|
1 |
| -# Language Reference |
| 1 | +# 语言参考 |
2 | 2 |
|
3 |
| -## About the Language Reference |
4 | 3 | ## 关于语言参考
|
5 | 4 |
|
6 |
| -This part of the book describes the formal grammar of the Swift programming language.The grammar described here is intended to help you understand the language in more detail, rather than to allow you to directly implement a parser or compiler. |
7 |
| - |
8 |
| - |
9 | 5 | 本书的该部分描述了Swift编程语言的正式语法。在此描述语法的目的是为了帮助你更详细的理解该语言,而不是让你直接实现一个解析器或编译器。
|
10 | 6 |
|
11 |
| -The Swift language is relatively small, because many common types, functions, and operators that appear virtually everywhere in Swift code are actually defined in the Swift standard library. Although these types, functions, and operators are not part of the Swift language itself, they are used extensively in the discussions and code examples in this |
12 |
| -part of the book. |
13 |
| - |
14 |
| -Swift语言相对较小,因为那些无处不在出现在Swift代码中的很多常见的类型,函数,和运算符实际上已经定义在了Swift的标准库中。虽然这些类型,函数,和运算符本身不是Swift语言的一部分,但它们被广泛应用于该书本部分的探讨和代码示例中。 |
| 7 | +Swift语言相对较小,因为那些无处不在出现在Swift代码中的很多常见的类型,函数,和运算符实际上已经定义在了Swift的标准库中。虽然这些类型,函数,和运算符不是Swift语言本身的一部分,但它们被广泛应用于该书本部分的探讨和代码示例中。 |
15 | 8 |
|
16 |
| -## How to Read the Grammar |
17 | 9 | ## 如何阅读语法
|
18 |
| -The notation used to describe the formal grammar of the Swift programming language follows a few conventions: |
19 | 10 |
|
20 | 11 | 用于描述Swift编程语言正规语法的标记有如下几个约定:
|
21 | 12 |
|
22 |
| - * An arrow (→) is used to mark grammar productions and can be read as “can consist of.“ |
23 |
| - |
24 |
| -* 箭头(→)用于标记语法生产和可以理解为“可包括” |
25 |
| - |
26 |
| -* Syntactic categories are indicated by italic text and appear on both sides of a grammar production rule. |
| 13 | +* 箭头(→)用于标记文法和可以理解为“可包括” |
27 | 14 |
|
28 | 15 | * 语法范围以斜体文字表示,显示在语法规范的两侧。
|
29 | 16 |
|
30 |
| -* Literal words and punctuation are indicated by boldface constant width text and appear only on the right-hand side of a grammar production rule. |
| 17 | +* 文字和标点由固定宽度的粗体文字显示,并只出现在一个标记文法的右侧. |
31 | 18 |
|
32 |
| -* 文字和标点由固定宽度的粗体文字显示,并只出现在一个语法生产规范的右侧. |
33 |
| -* Alternative grammar productions are separated by vertical bars (|). When alternative productions are too long to read easily, they are broken into multiple grammar production rules on new lines. |
| 19 | +* 替代标记文法式由竖线(|)分隔。当替代文法过长而不易阅读时,它们将在新行中变换为多个标记文法规范。 |
34 | 20 |
|
35 |
| -* 替代语法产生式由竖线(|)分隔。当替代产生式过长而不易阅读时,它们将在新行中变换为多个语法产生式规范。 |
| 21 | +* 在一些案例中,常规字体文本将用于描述右侧的标记文法规则。 |
36 | 22 |
|
37 |
| -* In a few cases, regular font text is used to describe the right-hand side of a grammar production rule. |
38 |
| - |
39 |
| -* 在一些案例中,常规字体文本将用于描述右侧的语法产生式规则。 |
40 |
| - |
41 |
| -* Optional syntactic categories and literals are marked by a trailing subscript, opt. |
42 |
| - |
43 |
| -* 可选的句法范围和文字为在尾部以opt标识描述。 |
44 |
| - |
45 |
| -As an example, the grammar of a getter-setter block is defined as follows: |
| 23 | +* 可选的句法范围和字面量则以尾部下标opt作为标识。 |
46 | 24 |
|
47 | 25 | 比如,getter-setter 区的语法定义如下:
|
48 | 26 |
|
49 |
| -> G R A M M A R O F A G E T T E R- S E T T E R B L O C K |
50 |
| -
|
51 |
| -> getter-setter-block → { getter-clause setter-clause opt } |{ setter-clause getter clause |
52 |
| -} |
| 27 | +> GETTER-SETTER区语法 |
53 | 28 |
|
54 |
| -This definition indicates that a getter-setter block can consist of a getter clause followed by an optional setter clause, enclosed in braces, or a setter clause followed by a getter clause, enclosed in braces. The grammar production above is equivalent to the following two productions, where the alternatives are spelled out explicitly: |
| 29 | +> getter-setter-block → { getter-clause setter-clause opt } |{ setter-clause getter clause} |
55 | 30 |
|
56 | 31 | 该定义表示,一个getter-setter方法块可由一个getter子句后跟一个可选的setter语句,括在大括号中。或者一个setter子句后跟一个getter子句,括在大括号中。上述语法产生式等价于下面的两个替代处已经明确拼写出的产生式。
|
57 | 32 |
|
58 |
| -> G R A M M A R O F A G E T T E R S E T T E R B L O C K |
| 33 | +> GETTER-SETTER区语法 |
59 | 34 |
|
60 | 35 | > getter-setter-block → { getter-clause setter-clause opt }
|
61 | 36 |
|
|
0 commit comments