★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:https://www.cnblogs.com/strengthen/p/9740754.html 
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

词法结构

 1 GRAMMAR OF WHITESPACE
 2
 3 whitespace → whitespace-item whitespace opt
 4
 5 whitespace-item → line-break
 6
 7 whitespace-item → comment
 8
 9 whitespace-item → multiline-comment
10
11 whitespace-item → U+0000, U+0009, U+000B, U+000C, or U+0020
12
13 line-break → U+000A
14
15 line-break → U+000D
16
17 line-break → U+000D followed by U+000A
18
19 comment → // comment-text line-break
20
21 multiline-comment → /* multiline-comment-text */
22
23 comment-text → comment-text-item comment-text opt
24
25 comment-text-item → Any Unicode scalar value except U+000A or U+000D
26
27 multiline-comment-text → multiline-comment-text-item multiline-comment-text opt
28
29 multiline-comment-text-item → multiline-comment
30
31 multiline-comment-text-item → comment-text-item
32
33 multiline-comment-text-item → Any Unicode scalar value except /* or */

 1 GRAMMAR OF AN IDENTIFIER
 2
 3 identifier → identifier-head identifier-characters opt
 4
 5 identifier → ` identifier-head identifier-characters opt `
 6
 7 identifier → implicit-parameter-name
 8
 9 identifier-list → identifier | identifier , identifier-list
10
11 identifier-head → Upper- or lowercase letter A through Z
12
13 identifier-head → _
14
15 identifier-head → U+00A8, U+00AA, U+00AD, U+00AF, U+00B2–U+00B5, or U+00B7–U+00BA
16
17 identifier-head → U+00BC–U+00BE, U+00C0–U+00D6, U+00D8–U+00F6, or U+00F8–U+00FF
18
19 identifier-head → U+0100–U+02FF, U+0370–U+167F, U+1681–U+180D, or U+180F–U+1DBF
20
21 identifier-head → U+1E00–U+1FFF
22
23 identifier-head → U+200B–U+200D, U+202A–U+202E, U+203F–U+2040, U+2054, or U+2060–U+206F
24
25 identifier-head → U+2070–U+20CF, U+2100–U+218F, U+2460–U+24FF, or U+2776–U+2793
26
27 identifier-head → U+2C00–U+2DFF or U+2E80–U+2FFF
28
29 identifier-head → U+3004–U+3007, U+3021–U+302F, U+3031–U+303F, or U+3040–U+D7FF
30
31 identifier-head → U+F900–U+FD3D, U+FD40–U+FDCF, U+FDF0–U+FE1F, or U+FE30–U+FE44
32
33 identifier-head → U+FE47–U+FFFD
34
35 identifier-head → U+10000–U+1FFFD, U+20000–U+2FFFD, U+30000–U+3FFFD, or U+40000–U+4FFFD
36
37 identifier-head → U+50000–U+5FFFD, U+60000–U+6FFFD, U+70000–U+7FFFD, or U+80000–U+8FFFD
38
39 identifier-head → U+90000–U+9FFFD, U+A0000–U+AFFFD, U+B0000–U+BFFFD, or U+C0000–U+CFFFD
40
41 identifier-head → U+D0000–U+DFFFD or U+E0000–U+EFFFD
42
43 identifier-character → Digit 0 through 9
44
45 identifier-character → U+0300–U+036F, U+1DC0–U+1DFF, U+20D0–U+20FF, or U+FE20–U+FE2F
46
47 identifier-character → identifier-head
48
49 identifier-characters → identifier-character identifier-characters opt
50
51 implicit-parameter-name → $ decimal-digits

1 GRAMMAR OF A LITERAL
2
3 literal → numeric-literal | string-literal | boolean-literal | nil-literal
4
5 numeric-literal → -opt integer-literal | -opt floating-point-literal
6
7 boolean-literal → true | false
8
9 nil-literal → nil

 1 GRAMMAR OF AN INTEGER LITERAL
 2
 3 integer-literal → binary-literal
 4
 5 integer-literal → octal-literal
 6
 7 integer-literal → decimal-literal
 8
 9 integer-literal → hexadecimal-literal
10
11 binary-literal → 0b binary-digit binary-literal-characters opt
12
13 binary-digit → Digit 0 or 1
14
15 binary-literal-character → binary-digit | _
16
17 binary-literal-characters → binary-literal-character binary-literal-characters opt
18
19 octal-literal → 0o octal-digit octal-literal-characters opt
20
21 octal-digit → Digit 0 through 7
22
23 octal-literal-character → octal-digit | _
24
25 octal-literal-characters → octal-literal-character octal-literal-characters opt
26
27 decimal-literal → decimal-digit decimal-literal-characters opt
28
29 decimal-digit → Digit 0 through 9
30
31 decimal-digits → decimal-digit decimal-digits opt
32
33 decimal-literal-character → decimal-digit | _
34
35 decimal-literal-characters → decimal-literal-character decimal-literal-characters opt
36
37 hexadecimal-literal → 0x hexadecimal-digit hexadecimal-literal-characters opt
38
39 hexadecimal-digit → Digit 0 through 9, a through f, or A through F
40
41 hexadecimal-literal-character → hexadecimal-digit | _
42
43 hexadecimal-literal-characters → hexadecimal-literal-character hexadecimal-literal-characters opt

 1 GRAMMAR OF A FLOATING-POINT LITERAL
 2
 3 floating-point-literal → decimal-literal decimal-fraction opt decimal-exponent opt
 4
 5 floating-point-literal → hexadecimal-literal hexadecimal-fraction opt hexadecimal-exponent
 6
 7 decimal-fraction → . decimal-literal
 8
 9 decimal-exponent → floating-point-e sign opt decimal-literal
10
11 hexadecimal-fraction → . hexadecimal-digit hexadecimal-literal-characters opt
12
13 hexadecimal-exponent → floating-point-p sign opt decimal-literal
14
15 floating-point-e → e | E
16
17 floating-point-p → p | P
18
19 sign → + | -

 1 GRAMMAR OF A STRING LITERAL
 2
 3 string-literal → static-string-literal | interpolated-string-literal
 4
 5 static-string-literal → " quoted-text opt "
 6
 7 static-string-literal → """ multiline-quoted-text opt """
 8
 9 quoted-text → quoted-text-item quoted-text opt
10
11 quoted-text-item → escaped-character
12
13 quoted-text-item → Any Unicode scalar value except ", \, U+000A, or U+000D
14
15 multiline-quoted-text → multiline-quoted-text-item multiline-quoted-text opt
16
17 multiline-quoted-text-item → escaped-character
18
19 multiline-quoted-text-item → Any Unicode scalar value except \
20
21 multiline-quoted-text-item → escaped-newline
22
23 interpolated-string-literal → " interpolated-text opt "
24
25 interpolated-string-literal → """ multiline-interpolated-text opt """
26
27 interpolated-text → interpolated-text-item interpolated-text opt
28
29 interpolated-text-item → \( expression ) | quoted-text-item
30
31 multiline-interpolated-text → multiline-interpolated-text-item multiline-interpolated-text opt
32
33 multiline-interpolated-text-item → \( expression ) | multiline-quoted-text-item
34
35 escaped-character → \0 | \\ | \t | \n | \r | \" | \'
36
37 escaped-character → \u { unicode-scalar-digits }
38
39 unicode-scalar-digits → Between one and eight hexadecimal digits
40
41 escaped-newline → \ whitespace opt line-break

 1 GRAMMAR OF OPERATORS
 2
 3 operator → operator-head operator-characters opt
 4
 5 operator → dot-operator-head dot-operator-characters
 6
 7 operator-head → / | = | - | + | ! | * | % | < | > | & | | | ^ | ~ | ?
 8
 9 operator-head → U+00A1–U+00A7
10
11 operator-head → U+00A9 or U+00AB
12
13 operator-head → U+00AC or U+00AE
14
15 operator-head → U+00B0–U+00B1, U+00B6, U+00BB, U+00BF, U+00D7, or U+00F7
16
17 operator-head → U+2016–U+2017 or U+2020–U+2027
18
19 operator-head → U+2030–U+203E
20
21 operator-head → U+2041–U+2053
22
23 operator-head → U+2055–U+205E
24
25 operator-head → U+2190–U+23FF
26
27 operator-head → U+2500–U+2775
28
29 operator-head → U+2794–U+2BFF
30
31 operator-head → U+2E00–U+2E7F
32
33 operator-head → U+3001–U+3003
34
35 operator-head → U+3008–U+3020 or U+3030
36
37 operator-character → operator-head
38
39 operator-character → U+0300–U+036F
40
41 operator-character → U+1DC0–U+1DFF
42
43 operator-character → U+20D0–U+20FF
44
45 operator-character → U+FE00–U+FE0F
46
47 operator-character → U+FE20–U+FE2F
48
49 operator-character → U+E0100–U+E01EF
50
51 operator-characters → operator-character operator-characters opt
52
53 dot-operator-head → .
54
55 dot-operator-character → . | operator-character
56
57 dot-operator-characters → dot-operator-character dot-operator-characters opt
58
59 binary-operator → operator
60
61 prefix-operator → operator
62
63 postfix-operator → operator

类型

 1 GRAMMAR OF A TYPE
 2
 3 type → array-type
 4
 5 type → dictionary-type
 6
 7 type → function-type
 8
 9 type → type-identifier
10
11 type → tuple-type
12
13 type → optional-type
14
15 type → implicitly-unwrapped-optional-type
16
17 type → protocol-composition-type
18
19 type → metatype-type
20
21 type → Any
22
23 type → Self
24
25 type → ( type )

1 GRAMMAR OF A TYPE ANNOTATION
2
3 type-annotation → : attributes opt inoutopt type

1 GRAMMAR OF A TYPE IDENTIFIER
2
3 type-identifier → type-name generic-argument-clause opt | type-name generic-argument-clause opt . type-identifier
4
5 type-name → identifier

1 GRAMMAR OF A TUPLE TYPE
2
3 tuple-type → ( ) | ( tuple-type-element , tuple-type-element-list )
4
5 tuple-type-element-list → tuple-type-element | tuple-type-element , tuple-type-element-list
6
7 tuple-type-element → element-name type-annotation | type
8
9 element-name → identifier

 1 GRAMMAR OF A FUNCTION TYPE
 2
 3 function-type → attributes opt function-type-argument-clause throwsopt -> type
 4
 5 function-type → attributes opt function-type-argument-clause rethrows -> type
 6
 7 function-type-argument-clause → ( )
 8
 9 function-type-argument-clause → ( function-type-argument-list ...opt )
10
11 function-type-argument-list → function-type-argument | function-type-argument , function-type-argument-list
12
13 function-type-argument → attributes opt inoutopt type | argument-label type-annotation
14
15 argument-label → identifier

1 GRAMMAR OF AN ARRAY TYPE
2
3 array-type → [ type ]

1 GRAMMAR OF A DICTIONARY TYPE
2
3 dictionary-type → [ type : type ]

1 GRAMMAR OF AN OPTIONAL TYPE
2
3 optional-type → type ?

1 GRAMMAR OF AN IMPLICITLY UNWRAPPED OPTIONAL TYPE
2
3 implicitly-unwrapped-optional-type → type !

1 GRAMMAR OF A PROTOCOL COMPOSITION TYPE
2
3 protocol-composition-type → type-identifier & protocol-composition-continuation
4
5 protocol-composition-continuation → type-identifier | protocol-composition-type

1 GRAMMAR OF A METATYPE TYPE
2
3 metatype-type → type . Type | type . Protocol

1 GRAMMAR OF A TYPE INHERITANCE CLAUSE
2
3 type-inheritance-clause → : type-inheritance-list
4
5 type-inheritance-list → type-identifier | type-identifier , type-inheritance-list

表达式

1 GRAMMAR OF AN EXPRESSION
2
3 expression → try-operator opt prefix-expression binary-expressions opt
4
5 expression-list → expression | expression , expression-list

1 GRAMMAR OF A PREFIX EXPRESSION
2
3 prefix-expression → prefix-operator opt postfix-expression
4
5 prefix-expression → in-out-expression
6
7 in-out-expression → & identifier

1 GRAMMAR OF A TRY EXPRESSION
2
3 try-operator → try | try ? | try !

 1 GRAMMAR OF A BINARY EXPRESSION
 2
 3 binary-expression → binary-operator prefix-expression
 4
 5 binary-expression → assignment-operator try-operator opt prefix-expression
 6
 7 binary-expression → conditional-operator try-operator opt prefix-expression
 8
 9 binary-expression → type-casting-operator
10
11 binary-expressions → binary-expression binary-expressions opt

1 GRAMMAR OF AN ASSIGNMENT OPERATOR
2
3 assignment-operator → =

1 GRAMMAR OF A CONDITIONAL OPERATOR
2
3 conditional-operator → ? expression :

1 GRAMMAR OF A TYPE-CASTING OPERATOR
2
3 type-casting-operator → is type
4
5 type-casting-operator → as type
6
7 type-casting-operator → as ? type
8
9 type-casting-operator → as ! type

 1 GRAMMAR OF A PRIMARY EXPRESSION
 2
 3 primary-expression → identifier generic-argument-clause opt
 4
 5 primary-expression → literal-expression
 6
 7 primary-expression → self-expression
 8
 9 primary-expression → superclass-expression
10
11 primary-expression → closure-expression
12
13 primary-expression → parenthesized-expression
14
15 primary-expression → tuple-expression
16
17 primary-expression → implicit-member-expression
18
19 primary-expression → wildcard-expression
20
21 primary-expression → key-path-expression
22
23 primary-expression → selector-expression
24
25 primary-expression → key-path-string-expression

 1 GRAMMAR OF A LITERAL EXPRESSION
 2
 3 literal-expression → literal
 4
 5 literal-expression → array-literal | dictionary-literal | playground-literal
 6
 7 literal-expression → #file | #line | #column | #function | #dsohandle
 8
 9 array-literal → [ array-literal-items opt ]
10
11 array-literal-items → array-literal-item ,opt | array-literal-item , array-literal-items
12
13 array-literal-item → expression
14
15 dictionary-literal → [ dictionary-literal-items ] | [ : ]
16
17 dictionary-literal-items → dictionary-literal-item ,opt | dictionary-literal-item , dictionary-literal-items
18
19 dictionary-literal-item → expression : expression
20
21 playground-literal → #colorLiteral ( red : expression , green : expression , blue : expression , alpha : expression )
22
23 playground-literal → #fileLiteral ( resourceName : expression )
24
25 playground-literal → #imageLiteral ( resourceName : expression )

1 GRAMMAR OF A SELF EXPRESSION
2
3 self-expression → self | self-method-expression | self-subscript-expression | self-initializer-expression
4
5 self-method-expression → self . identifier
6
7 self-subscript-expression → self [ function-call-argument-list ]
8
9 self-initializer-expression → self . init

1 GRAMMAR OF A SUPERCLASS EXPRESSION
2
3 superclass-expression → superclass-method-expression | superclass-subscript-expression | superclass-initializer-expression
4
5 superclass-method-expression → super . identifier
6
7 superclass-subscript-expression → super [ function-call-argument-list ]
8
9 superclass-initializer-expression → super . init

 1 GRAMMAR OF A CLOSURE EXPRESSION
 2
 3 closure-expression → { closure-signature opt statements opt }
 4
 5 closure-signature → capture-list opt closure-parameter-clause throwsopt function-result opt in
 6
 7 closure-signature → capture-list in
 8
 9 closure-parameter-clause → ( ) | ( closure-parameter-list ) | identifier-list
10
11 closure-parameter-list → closure-parameter | closure-parameter , closure-parameter-list
12
13 closure-parameter → closure-parameter-name type-annotation opt
14
15 closure-parameter → closure-parameter-name type-annotation ...
16
17 closure-parameter-name → identifier
18
19 capture-list → [ capture-list-items ]
20
21 capture-list-items → capture-list-item | capture-list-item , capture-list-items
22
23 capture-list-item → capture-specifier opt expression
24
25 capture-specifier → weak | unowned | unowned(safe) | unowned(unsafe)

1 GRAMMAR OF A IMPLICIT MEMBER EXPRESSION
2
3 implicit-member-expression → . identifier

1 GRAMMAR OF A PARENTHESIZED EXPRESSION
2
3 parenthesized-expression → ( expression )

1 GRAMMAR OF A TUPLE EXPRESSION
2
3 tuple-expression → ( ) | ( tuple-element , tuple-element-list )
4
5 tuple-element-list → tuple-element | tuple-element , tuple-element-list
6
7 tuple-element → expression | identifier : expression

1 GRAMMAR OF A WILDCARD EXPRESSION
2
3 wildcard-expression → _

 1 GRAMMAR OF A KEY-PATH EXPRESSION
 2
 3 key-path-expression → \ type opt . key-path-components
 4
 5 key-path-components → key-path-component | key-path-component . key-path-components
 6
 7 key-path-component → identifier key-path-postfixes opt | key-path-postfixes
 8
 9 key-path-postfixes → key-path-postfix key-path-postfixes opt
10
11 key-path-postfix → ? | ! | [ function-call-argument-list ]

1 GRAMMAR OF A SELECTOR EXPRESSION
2
3 selector-expression → #selector ( expression )
4
5 selector-expression → #selector ( getter: expression )
6
7 selector-expression → #selector ( setter: expression )

1 GRAMMAR OF A KEY-PATH STRING EXPRESSION
2
3 key-path-string-expression → #keyPath ( expression )

 1 GRAMMAR OF A POSTFIX EXPRESSION
 2
 3 postfix-expression → primary-expression
 4
 5 postfix-expression → postfix-expression postfix-operator
 6
 7 postfix-expression → function-call-expression
 8
 9 postfix-expression → initializer-expression
10
11 postfix-expression → explicit-member-expression
12
13 postfix-expression → postfix-self-expression
14
15 postfix-expression → subscript-expression
16
17 postfix-expression → forced-value-expression
18
19 postfix-expression → optional-chaining-expression

 1 GRAMMAR OF A FUNCTION CALL EXPRESSION
 2
 3 function-call-expression → postfix-expression function-call-argument-clause
 4
 5 function-call-expression → postfix-expression function-call-argument-clause opt trailing-closure
 6
 7 function-call-argument-clause → ( ) | ( function-call-argument-list )
 8
 9 function-call-argument-list → function-call-argument | function-call-argument , function-call-argument-list
10
11 function-call-argument → expression | identifier : expression
12
13 function-call-argument → operator | identifier : operator
14
15 trailing-closure → closure-expression

1 GRAMMAR OF AN INITIALIZER EXPRESSION
2
3 initializer-expression → postfix-expression . init
4
5 initializer-expression → postfix-expression . init ( argument-names )

 1 GRAMMAR OF AN EXPLICIT MEMBER EXPRESSION
 2
 3 explicit-member-expression → postfix-expression . decimal-digits
 4
 5 explicit-member-expression → postfix-expression . identifier generic-argument-clause opt
 6
 7 explicit-member-expression → postfix-expression . identifier ( argument-names )
 8
 9 argument-names → argument-name argument-names opt
10
11 argument-name → identifier :

1 GRAMMAR OF A SELF EXPRESSION
2
3 postfix-self-expression → postfix-expression . self

1 GRAMMAR OF A SUBSCRIPT EXPRESSION
2
3 subscript-expression → postfix-expression [ function-call-argument-list ]

1 GRAMMAR OF A FORCED-VALUE EXPRESSION
2
3 forced-value-expression → postfix-expression !

1 GRAMMAR OF AN OPTIONAL-CHAINING EXPRESSION
2
3 optional-chaining-expression → postfix-expression ?

语句

 1 GRAMMAR OF A STATEMENT
 2
 3 statement → expression ;opt
 4
 5 statement → declaration ;opt
 6
 7 statement → loop-statement ;opt
 8
 9 statement → branch-statement ;opt
10
11 statement → labeled-statement ;opt
12
13 statement → control-transfer-statement ;opt
14
15 statement → defer-statement ;opt
16
17 statement → do-statement ;opt
18
19 statement → compiler-control-statement
20
21 statements → statement statements opt

1 GRAMMAR OF A LOOP STATEMENT
2
3 loop-statement → for-in-statement
4
5 loop-statement → while-statement
6
7 loop-statement → repeat-while-statement

1 GRAMMAR OF A FOR-IN STATEMENT
2
3 for-in-statement → for caseopt pattern in expression where-clause opt code-block

 1 GRAMMAR OF A WHILE STATEMENT
 2
 3 while-statement → while condition-list code-block
 4
 5 condition-list → condition | condition , condition-list
 6
 7 condition → expression | availability-condition | case-condition | optional-binding-condition
 8
 9 case-condition → case pattern initializer
10
11 optional-binding-condition → let pattern initializer | var pattern initializer

1 GRAMMAR OF A REPEAT-WHILE STATEMENT
2
3 repeat-while-statement → repeat code-block while expression

1 GRAMMAR OF A BRANCH STATEMENT
2
3 branch-statement → if-statement
4
5 branch-statement → guard-statement
6
7 branch-statement → switch-statement

1 GRAMMAR OF AN IF STATEMENT
2
3 if-statement → if condition-list code-block else-clause opt
4
5 else-clause → else code-block | else if-statement

1 GRAMMAR OF A GUARD STATEMENT
2
3 guard-statement → guard condition-list else code-block

 1 GRAMMAR OF A SWITCH STATEMENT
 2
 3 switch-statement → switch expression { switch-cases opt }
 4
 5 switch-cases → switch-case switch-cases opt
 6
 7 switch-case → case-label statements
 8
 9 switch-case → default-label statements
10
11 switch-case → conditional-switch-case
12
13 case-label → case case-item-list :
14
15 case-item-list → pattern where-clause opt | pattern where-clause opt , case-item-list
16
17 default-label → default :
18
19 where-clause → where where-expression
20
21 where-expression → expression
22
23 conditional-switch-case → switch-if-directive-clause switch-elseif-directive-clauses opt switch-else-directive-clause opt endif-directive
24
25 switch-if-directive-clause → if-directive compilation-condition switch-cases opt
26
27 switch-elseif-directive-clauses → elseif-directive-clause switch-elseif-directive-clauses opt
28
29 switch-elseif-directive-clause → elseif-directive compilation-condition switch-cases opt
30
31 switch-else-directive-clause → else-directive switch-cases opt

 1 GRAMMAR OF A LABELED STATEMENT
 2
 3 labeled-statement → statement-label loop-statement
 4
 5 labeled-statement → statement-label if-statement
 6
 7 labeled-statement → statement-label switch-statement
 8
 9 labeled-statement → statement-label do-statement
10
11 statement-label → label-name :
12
13 label-name → identifier

 1 GRAMMAR OF A CONTROL TRANSFER STATEMENT
 2
 3 control-transfer-statement → break-statement
 4
 5 control-transfer-statement → continue-statement
 6
 7 control-transfer-statement → fallthrough-statement
 8
 9 control-transfer-statement → return-statement
10
11 control-transfer-statement → throw-statement

1 GRAMMAR OF A BREAK STATEMENT
2
3 break-statement → break label-name opt

1 GRAMMAR OF A CONTINUE STATEMENT
2
3 continue-statement → continue label-name opt

1 GRAMMAR OF A FALLTHROUGH STATEMENT
2
3 fallthrough-statement → fallthrough

1 GRAMMAR OF A RETURN STATEMENT
2
3 return-statement → return expression opt

1 GRAMMAR OF A THROW STATEMENT
2
3 throw-statement → throw expression

1 GRAMMAR OF A DEFER STATEMENT
2
3 defer-statement → defer code-block

1 GRAMMAR OF A DO STATEMENT
2
3 do-statement → do code-block catch-clauses opt
4
5 catch-clauses → catch-clause catch-clauses opt
6
7 catch-clause → catch pattern opt where-clause opt code-block

1 GRAMMAR OF A COMPILER CONTROL STATEMENT
2
3 compiler-control-statement → conditional-compilation-block
4
5 compiler-control-statement → line-control-statement
6
7 compiler-control-statement → diagnostic-statement

 1 GRAMMAR OF A CONDITIONAL COMPILATION BLOCK
 2
 3 conditional-compilation-block → if-directive-clause elseif-directive-clauses opt else-directive-clause opt endif-directive
 4
 5 if-directive-clause → if-directive compilation-condition statements opt
 6
 7 elseif-directive-clauses → elseif-directive-clause elseif-directive-clauses opt
 8
 9 elseif-directive-clause → elseif-directive compilation-condition statements opt
10
11 else-directive-clause → else-directive statements opt
12
13 if-directive → #if
14
15 elseif-directive → #elseif
16
17 else-directive → #else
18
19 endif-directive → #endif
20
21 compilation-condition → platform-condition
22
23 compilation-condition → identifier
24
25 compilation-condition → boolean-literal
26
27 compilation-condition → ( compilation-condition )
28
29 compilation-condition → ! compilation-condition
30
31 compilation-condition → compilation-condition && compilation-condition
32
33 compilation-condition → compilation-condition || compilation-condition
34
35 platform-condition → os ( operating-system )
36
37 platform-condition → arch ( architecture )
38
39 platform-condition → swift ( >= swift-version )
40
41 platform-condition → compiler ( >= swift-version )
42
43 platform-condition → canImport ( module-name )
44
45 platform-condition → targetEnvironment ( environment )
46
47 operating-system → macOS | iOS | watchOS | tvOS
48
49 architecture → i386 | x86_64 | arm | arm64
50
51 swift-version → decimal-digits swift-version-continuation opt
52
53 swift-version-continuation → . decimal-digits swift-version-continuation opt
54
55 module-name → identifier
56
57 environment → simulator

1 GRAMMAR OF A LINE CONTROL STATEMENT
2
3 line-control-statement → #sourceLocation ( file: file-name , line: line-number )
4
5 line-control-statement → #sourceLocation ( )
6
7 line-number → A decimal integer greater than zero
8
9 file-name → static-string-literal

1 GRAMMAR OF A COMPILE-TIME DIAGNOSTIC STATEMENT
2
3 diagnostic-statement → #error ( diagnostic-message )
4
5 diagnostic-statement → #warning ( diagnostic-message )
6
7 diagnostic-message → static-string-literal

 1 GRAMMAR OF AN AVAILABILITY CONDITION
 2
 3 availability-condition → #available ( availability-arguments )
 4
 5 availability-arguments → availability-argument | availability-argument , availability-arguments
 6
 7 availability-argument → platform-name platform-version
 8
 9 availability-argument → *
10
11 platform-name → iOS | iOSApplicationExtension
12
13 platform-name → macOS | macOSApplicationExtension
14
15 platform-name → watchOS
16
17 platform-name → tvOS
18
19 platform-version → decimal-digits
20
21 platform-version → decimal-digits . decimal-digits
22
23 platform-version → decimal-digits . decimal-digits . decimal-digits

声明

 1 GRAMMAR OF A DECLARATION
 2
 3 declaration → import-declaration
 4
 5 declaration → constant-declaration
 6
 7 declaration → variable-declaration
 8
 9 declaration → typealias-declaration
10
11 declaration → function-declaration
12
13 declaration → enum-declaration
14
15 declaration → struct-declaration
16
17 declaration → class-declaration
18
19 declaration → protocol-declaration
20
21 declaration → initializer-declaration
22
23 declaration → deinitializer-declaration
24
25 declaration → extension-declaration
26
27 declaration → subscript-declaration
28
29 declaration → operator-declaration
30
31 declaration → precedence-group-declaration
32
33 declarations → declaration declarations opt

1 GRAMMAR OF A TOP-LEVEL DECLARATION
2
3 top-level-declaration → statements opt

1 GRAMMAR OF A CODE BLOCK
2
3 code-block → { statements opt }

1 GRAMMAR OF AN IMPORT DECLARATION
2
3 import-declaration → attributes opt import import-kind opt import-path
4
5 import-kind → typealias | struct | class | enum | protocol | let | var | func
6
7 import-path → import-path-identifier | import-path-identifier . import-path
8
9 import-path-identifier → identifier | operator

1 GRAMMAR OF A CONSTANT DECLARATION
2
3 constant-declaration → attributes opt declaration-modifiers opt let pattern-initializer-list
4
5 pattern-initializer-list → pattern-initializer | pattern-initializer , pattern-initializer-list
6
7 pattern-initializer → pattern initializer opt
8
9 initializer → = expression

 1 GRAMMAR OF A VARIABLE DECLARATION
 2
 3 variable-declaration → variable-declaration-head pattern-initializer-list
 4
 5 variable-declaration → variable-declaration-head variable-name type-annotation code-block
 6
 7 variable-declaration → variable-declaration-head variable-name type-annotation getter-setter-block
 8
 9 variable-declaration → variable-declaration-head variable-name type-annotation getter-setter-keyword-block
10
11 variable-declaration → variable-declaration-head variable-name initializer willSet-didSet-block
12
13 variable-declaration → variable-declaration-head variable-name type-annotation initializer opt willSet-didSet-block
14
15 variable-declaration-head → attributes opt declaration-modifiers opt var
16
17 variable-name → identifier
18
19 getter-setter-block → code-block
20
21 getter-setter-block → { getter-clause setter-clause opt }
22
23 getter-setter-block → { setter-clause getter-clause }
24
25 getter-clause → attributes opt mutation-modifier opt get code-block
26
27 setter-clause → attributes opt mutation-modifier opt set setter-name opt code-block
28
29 setter-name → ( identifier )
30
31 getter-setter-keyword-block → { getter-keyword-clause setter-keyword-clause opt }
32
33 getter-setter-keyword-block → { setter-keyword-clause getter-keyword-clause }
34
35 getter-keyword-clause → attributes opt mutation-modifier opt get
36
37 setter-keyword-clause → attributes opt mutation-modifier opt set
38
39 willSet-didSet-block → { willSet-clause didSet-clause opt }
40
41 willSet-didSet-block → { didSet-clause willSet-clause opt }
42
43 willSet-clause → attributes opt willSet setter-name opt code-block
44
45 didSet-clause → attributes opt didSet setter-name opt code-block

1 GRAMMAR OF A TYPE ALIAS DECLARATION
2
3 typealias-declaration → attributes opt access-level-modifier opt typealias typealias-name generic-parameter-clause opt typealias-assignment
4
5 typealias-name → identifier
6
7 typealias-assignment → = type

 1 GRAMMAR OF A FUNCTION DECLARATION
 2
 3 function-declaration → function-head function-name generic-parameter-clause opt function-signature generic-where-clause opt function-body opt
 4
 5 function-head → attributes opt declaration-modifiers opt func
 6
 7 function-name → identifier | operator
 8
 9 function-signature → parameter-clause throwsopt function-result opt
10
11 function-signature → parameter-clause rethrows function-result opt
12
13 function-result → -> attributes opt type
14
15 function-body → code-block
16
17 parameter-clause → ( ) | ( parameter-list )
18
19 parameter-list → parameter | parameter , parameter-list
20
21 parameter → external-parameter-name opt local-parameter-name type-annotation default-argument-clause opt
22
23 parameter → external-parameter-name opt local-parameter-name type-annotation
24
25 parameter → external-parameter-name opt local-parameter-name type-annotation ...
26
27 external-parameter-name → identifier
28
29 local-parameter-name → identifier
30
31 default-argument-clause → = expression

 1 GRAMMAR OF AN ENUMERATION DECLARATION
 2
 3 enum-declaration → attributes opt access-level-modifier opt union-style-enum
 4
 5 enum-declaration → attributes opt access-level-modifier opt raw-value-style-enum
 6
 7 union-style-enum → indirectopt enum enum-name generic-parameter-clause opt type-inheritance-clause opt generic-where-clause opt { union-style-enum-members opt }
 8
 9 union-style-enum-members → union-style-enum-member union-style-enum-members opt
10
11 union-style-enum-member → declaration | union-style-enum-case-clause | compiler-control-statement
12
13 union-style-enum-case-clause → attributes opt indirectopt case union-style-enum-case-list
14
15 union-style-enum-case-list → union-style-enum-case | union-style-enum-case , union-style-enum-case-list
16
17 union-style-enum-case → enum-case-name tuple-type opt
18
19 enum-name → identifier
20
21 enum-case-name → identifier
22
23 raw-value-style-enum → enum enum-name generic-parameter-clause opt type-inheritance-clause generic-where-clause opt { raw-value-style-enum-members }
24
25 raw-value-style-enum-members → raw-value-style-enum-member raw-value-style-enum-members opt
26
27 raw-value-style-enum-member → declaration | raw-value-style-enum-case-clause | compiler-control-statement
28
29 raw-value-style-enum-case-clause → attributes opt case raw-value-style-enum-case-list
30
31 raw-value-style-enum-case-list → raw-value-style-enum-case | raw-value-style-enum-case , raw-value-style-enum-case-list
32
33 raw-value-style-enum-case → enum-case-name raw-value-assignment opt
34
35 raw-value-assignment → = raw-value-literal
36
37 raw-value-literal → numeric-literal | static-string-literal | boolean-literal

 1 GRAMMAR OF A STRUCTURE DECLARATION
 2
 3 struct-declaration → attributes opt access-level-modifier opt struct struct-name generic-parameter-clause opt type-inheritance-clause opt generic-where-clause opt struct-body
 4
 5 struct-name → identifier
 6
 7 struct-body → { struct-members opt }
 8
 9 struct-members → struct-member struct-members opt
10
11 struct-member → declaration | compiler-control-statement

 1 GRAMMAR OF A CLASS DECLARATION
 2
 3 class-declaration → attributes opt access-level-modifier opt finalopt class class-name generic-parameter-clause opt type-inheritance-clause opt generic-where-clause opt class-body
 4
 5 class-declaration → attributes opt final access-level-modifier opt class class-name generic-parameter-clause opt type-inheritance-clause opt generic-where-clause opt class-body
 6
 7 class-name → identifier
 8
 9 class-body → { class-members opt }
10
11 class-members → class-member class-members opt
12
13 class-member → declaration | compiler-control-statement

 1 GRAMMAR OF A PROTOCOL DECLARATION
 2
 3 protocol-declaration → attributes opt access-level-modifier opt protocol protocol-name type-inheritance-clause opt generic-where-clause opt protocol-body
 4
 5 protocol-name → identifier
 6
 7 protocol-body → { protocol-members opt }
 8
 9 protocol-members → protocol-member protocol-members opt
10
11 protocol-member → protocol-member-declaration | compiler-control-statement
12
13 protocol-member-declaration → protocol-property-declaration
14
15 protocol-member-declaration → protocol-method-declaration
16
17 protocol-member-declaration → protocol-initializer-declaration
18
19 protocol-member-declaration → protocol-subscript-declaration
20
21 protocol-member-declaration → protocol-associated-type-declaration
22
23 protocol-member-declaration → typealias-declaration

1 GRAMMAR OF A PROTOCOL PROPERTY DECLARATION
2
3 protocol-property-declaration → variable-declaration-head variable-name type-annotation getter-setter-keyword-block

1 GRAMMAR OF A PROTOCOL METHOD DECLARATION
2
3 protocol-method-declaration → function-head function-name generic-parameter-clause opt function-signature generic-where-clause opt

1 GRAMMAR OF A PROTOCOL INITIALIZER DECLARATION
2
3 protocol-initializer-declaration → initializer-head generic-parameter-clause opt parameter-clause throwsopt generic-where-clause opt
4
5 protocol-initializer-declaration → initializer-head generic-parameter-clause opt parameter-clause rethrows generic-where-clause opt

1 GRAMMAR OF A PROTOCOL SUBSCRIPT DECLARATION
2
3 protocol-subscript-declaration → subscript-head subscript-result generic-where-clause opt getter-setter-keyword-block

1 GRAMMAR OF A PROTOCOL ASSOCIATED TYPE DECLARATION
2
3 protocol-associated-type-declaration → attributes opt access-level-modifier opt associatedtype typealias-name type-inheritance-clause opt typealias-assignment opt generic-where-clause opt

 1 GRAMMAR OF AN INITIALIZER DECLARATION
 2
 3 initializer-declaration → initializer-head generic-parameter-clause opt parameter-clause throwsopt generic-where-clause opt initializer-body
 4
 5 initializer-declaration → initializer-head generic-parameter-clause opt parameter-clause rethrows generic-where-clause opt initializer-body
 6
 7 initializer-head → attributes opt declaration-modifiers opt init
 8
 9 initializer-head → attributes opt declaration-modifiers opt init ?
10
11 initializer-head → attributes opt declaration-modifiers opt init !
12
13 initializer-body → code-block

1 GRAMMAR OF A DEINITIALIZER DECLARATION
2
3 deinitializer-declaration → attributes opt deinit code-block

1 GRAMMAR OF AN EXTENSION DECLARATION
2
3 extension-declaration → attributes opt access-level-modifier opt extension type-identifier type-inheritance-clause opt generic-where-clause opt extension-body
4
5 extension-body → { extension-members opt }
6
7 extension-members → extension-member extension-members opt
8
9 extension-member → declaration | compiler-control-statement

 1 GRAMMAR OF A SUBSCRIPT DECLARATION
 2
 3 subscript-declaration → subscript-head subscript-result generic-where-clause opt code-block
 4
 5 subscript-declaration → subscript-head subscript-result generic-where-clause opt getter-setter-block
 6
 7 subscript-declaration → subscript-head subscript-result generic-where-clause opt getter-setter-keyword-block
 8
 9 subscript-head → attributes opt declaration-modifiers opt subscript generic-parameter-clause opt parameter-clause
10
11 subscript-result → -> attributes opt type

 1 GRAMMAR OF AN OPERATOR DECLARATION
 2
 3 operator-declaration → prefix-operator-declaration | postfix-operator-declaration | infix-operator-declaration
 4
 5 prefix-operator-declaration → prefix operator operator
 6
 7 postfix-operator-declaration → postfix operator operator
 8
 9 infix-operator-declaration → infix operator operator infix-operator-group opt
10
11 infix-operator-group → : precedence-group-name

 1 GRAMMAR OF A PRECEDENCE GROUP DECLARATION
 2
 3 precedence-group-declaration → precedencegroup precedence-group-name { precedence-group-attributes opt }
 4
 5 precedence-group-attributes → precedence-group-attribute precedence-group-attributes opt
 6
 7 precedence-group-attribute → precedence-group-relation
 8
 9 precedence-group-attribute → precedence-group-assignment
10
11 precedence-group-attribute → precedence-group-associativity
12
13 precedence-group-relation → higherThan : precedence-group-names
14
15 precedence-group-relation → lowerThan : precedence-group-names
16
17 precedence-group-assignment → assignment : boolean-literal
18
19 precedence-group-associativity → associativity : left
20
21 precedence-group-associativity → associativity : right
22
23 precedence-group-associativity → associativity : none
24
25 precedence-group-names → precedence-group-name | precedence-group-name , precedence-group-names
26
27 precedence-group-name → identifier

 1 GRAMMAR OF A DECLARATION MODIFIER
 2
 3 declaration-modifier → class | convenience | dynamic | final | infix | lazy | optional | override | postfix | prefix | required | static | unowned | unowned ( safe ) | unowned ( unsafe ) | weak
 4
 5 declaration-modifier → access-level-modifier
 6
 7 declaration-modifier → mutation-modifier
 8
 9 declaration-modifiers → declaration-modifier declaration-modifiers opt
10
11 access-level-modifier → private | private ( set )
12
13 access-level-modifier → fileprivate | fileprivate ( set )
14
15 access-level-modifier → internal | internal ( set )
16
17 access-level-modifier → public | public ( set )
18
19 access-level-modifier → open | open ( set )
20
21 mutation-modifier → mutating | nonmutating

属性

 1 GRAMMAR OF AN ATTRIBUTE
 2
 3 attribute → @ attribute-name attribute-argument-clause opt
 4
 5 attribute-name → identifier
 6
 7 attribute-argument-clause → ( balanced-tokens opt )
 8
 9 attributes → attribute attributes opt
10
11 balanced-tokens → balanced-token balanced-tokens opt
12
13 balanced-token → ( balanced-tokens opt )
14
15 balanced-token → [ balanced-tokens opt ]
16
17 balanced-token → { balanced-tokens opt }
18
19 balanced-token → Any identifier, keyword, literal, or operator
20
21 balanced-token → Any punctuation except (, ), [, ], {, or }

模式

 1 GRAMMAR OF A PATTERN
 2
 3 pattern → wildcard-pattern type-annotation opt
 4
 5 pattern → identifier-pattern type-annotation opt
 6
 7 pattern → value-binding-pattern
 8
 9 pattern → tuple-pattern type-annotation opt
10
11 pattern → enum-case-pattern
12
13 pattern → optional-pattern
14
15 pattern → type-casting-pattern
16
17 pattern → expression-pattern

1 GRAMMAR OF A WILDCARD PATTERN
2
3 wildcard-pattern → _

1 GRAMMAR OF AN IDENTIFIER PATTERN
2
3 identifier-pattern → identifier

1 GRAMMAR OF A VALUE-BINDING PATTERN
2
3 value-binding-pattern → var pattern | let pattern

1 GRAMMAR OF A TUPLE PATTERN
2
3 tuple-pattern → ( tuple-pattern-element-list opt )
4
5 tuple-pattern-element-list → tuple-pattern-element | tuple-pattern-element , tuple-pattern-element-list
6
7 tuple-pattern-element → pattern | identifier : pattern

1 GRAMMAR OF AN ENUMERATION CASE PATTERN
2
3 enum-case-pattern → type-identifier opt . enum-case-name tuple-pattern opt

1 GRAMMAR OF AN OPTIONAL PATTERN
2
3 optional-pattern → identifier-pattern ?

1 GRAMMAR OF A TYPE CASTING PATTERN
2
3 type-casting-pattern → is-pattern | as-pattern
4
5 is-pattern → is type
6
7 as-pattern → pattern as type

1 GRAMMAR OF AN EXPRESSION PATTERN
2
3 expression-pattern → expression

泛型和参数

 1 GRAMMAR OF A GENERIC PARAMETER CLAUSE
 2
 3 generic-parameter-clause → < generic-parameter-list >
 4
 5 generic-parameter-list → generic-parameter | generic-parameter , generic-parameter-list
 6
 7 generic-parameter → type-name
 8
 9 generic-parameter → type-name : type-identifier
10
11 generic-parameter → type-name : protocol-composition-type
12
13 generic-where-clause → where requirement-list
14
15 requirement-list → requirement | requirement , requirement-list
16
17 requirement → conformance-requirement | same-type-requirement
18
19 conformance-requirement → type-identifier : type-identifier
20
21 conformance-requirement → type-identifier : protocol-composition-type
22
23 same-type-requirement → type-identifier == type

1 GRAMMAR OF A GENERIC ARGUMENT CLAUSE
2
3 generic-argument-clause → < generic-argument-list >
4
5 generic-argument-list → generic-argument | generic-argument , generic-argument-list
6
7 generic-argument → type

转载于:https://www.cnblogs.com/strengthen/p/9740754.html

Swift5.1 语言参考(十) 语法汇总相关推荐

  1. Swift5.1 语言参考(三) 类型

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  2. Swift5.1 语言参考(六) 声明

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  3. “易语言.飞扬”十分钟入门教程(修订版1,update for EF1.1.0)

    "易语言.飞扬"十分钟入门教程 (修订版1,update for EF1.1.0) 作者:liigo,2007.8.12 本文地址:http://blog.csdn.net/lii ...

  4. 转:C语言面试题大汇总 (图像处理方向)

    C语言面试题大汇总 (图像处理方向) C语言面试题大汇总 1.局部变量能否和全局变量重名? 答:能,局部会屏蔽全局.要用全局变量,需要使用"::" ;局部变量可以与全局变量同名,在 ...

  5. “易语言.飞扬”十分钟入门教程

    "易语言.飞扬"十分钟入门教程 作者:liigo 2007.1.1 原文链接:http://blog.csdn.net/liigo/archive/2007/01/01/14720 ...

  6. Markdown 语法汇总

    Markdown语法汇总 前言 我们在平时写作的时候,可能你会倾向于使用 Markdown 这种富文本标记语言,因为它是纯文本格式,而且可以很方便的生成具有很强可读性的 html 文件.比如现在很多写 ...

  7. HDL4SE:软件工程师学习Verilog语言(十四)

    14 RISC-V CPU初探 前面我们介绍了verilog语言的基本语法特征,并讨论了数字电路设计中常用的状态机和流水线结构,然后我们借鉴SystemC的做法,引入了HDL4SE建模语言,以及相应的 ...

  8. Swift语言指南(十)--字符串与字符

    原文:Swift语言指南(十)--字符串与字符 字符串是一段字符的有序集合,如"hellow,world"或"信天翁".Swift 中的字符串由 String ...

  9. Java 语言中十大“坑爹”功能!

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 来源:https://www.sohu.com/a/35 ...

最新文章

  1. 数据结构——四大查找算法(工作必备)
  2. TensorFlow之会话
  3. LDD3源码分析之访问控制
  4. Wordpress会员插件 wp_members 最新简体中文语言包
  5. yarn资源管理调度平台
  6. 三次样条插值 cubic spline interpolation
  7. 新上手jupyterlab安装及问题解决
  8. Machine Learning---感知器学习算法
  9. iOS音频掌柜-- AVAudioSession
  10. plc控制电机实验报告_基于西门子PLC电动机正反转互锁控制实验报告
  11. java jasperReports导出PDF字体加粗失效
  12. gnu/stubs-32.h
  13. java sqlite sqlite_busy_sqlite3出现SQLITE_BUSY错误码的原因以及解决方法
  14. 对马的幽灵是关于人的
  15. win 10 输入法自定义切换快捷键(rime)
  16. 查询数据库空间(mysql和oracle)
  17. 双向链表插入、删除操作
  18. HDU-2182-Frog
  19. 有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)。
  20. C++重学之路 5 控制语句和逻辑运算符

热门文章

  1. python列表遍历 空列表_Python list列表执行reversed()后执行pop()返回迭代对象遍历为空问题...
  2. 如何阅读一本书 pdf_如何快速阅读一本书?
  3. Map类集合K/V能不能存储null值的情况
  4. python练习,随机数字 函数,循环,if,格式化输出
  5. 电脑知识:如何保养自己的电脑,看完你就懂了!
  6. APP技巧:微信10个实用小技巧,太实用了,赶紧收藏!
  7. 开发工具:Intellij IDEA 非常实用的小技巧,你确定不来看看?
  8. 后端:循环遍历的用法介绍
  9. 消防信号二总线有没电压_春晓161#地块人防工程消防电源监控系统的设计与应用...
  10. java excel row遍历空_Java poi读取,写入Excel,处理row和cell可能为空的情况