Lexical and syntactic grammars for C# are interspersed throughout this
specification. The lexical grammar
defines how characters can be combined to form tokens (§9.4), the minimal
lexical elements of the language.
The syntactic grammar defines how tokens can be combined to make valid C#
programs.
Grammar productions include both non-terminal and terminal symbols. In
grammar productions, nonterminal
symbols are shown in italic type, and terminal symbols are shown in a
fixed-width font. Each
non-terminal is defined by a set of productions. The first line of a set of
productions is the name of the nonterminal,
followed by one or two colons. One colon is used for a production in the
syntactic grammar, two
colons for a production in the lexical grammar. Each successive indented
line contains the right-hand side
for a production that has the non-terminal symbol as the left-hand side.
For example:
class-modifier:
new
public
protected
internal
private
abstract
sealed
defines the class-modifier non-terminal as having seven productions.
Alternatives are normally listed on separate lines, as shown above, though
in cases where there are many
alternatives, the phrase .one of. precedes a list of the options. This is
simply shorthand for listing each of
the alternatives on a separate line. For example:
decimal-digit: one of
0 1 2 3 4 5 6 7 8 9
is equivalent to:
decimal-digit:
0
1
2
3
4
5
6
7
8
9
A subscripted suffix .opt., as in identifieropt, is used as shorthand to
indicate an optional symbol. The
example:
for-statement:
for ( for-initializeropt ; for-conditionopt ; for-iteratoropt )
embedded-statement
is equivalent to:
specification. The lexical grammar
defines how characters can be combined to form tokens (§9.4), the minimal
lexical elements of the language.
The syntactic grammar defines how tokens can be combined to make valid C#
programs.
Grammar productions include both non-terminal and terminal symbols. In
grammar productions, nonterminal
symbols are shown in italic type, and terminal symbols are shown in a
fixed-width font. Each
non-terminal is defined by a set of productions. The first line of a set of
productions is the name of the nonterminal,
followed by one or two colons. One colon is used for a production in the
syntactic grammar, two
colons for a production in the lexical grammar. Each successive indented
line contains the right-hand side
for a production that has the non-terminal symbol as the left-hand side.
For example:
class-modifier:
new
public
protected
internal
private
abstract
sealed
defines the class-modifier non-terminal as having seven productions.
Alternatives are normally listed on separate lines, as shown above, though
in cases where there are many
alternatives, the phrase .one of. precedes a list of the options. This is
simply shorthand for listing each of
the alternatives on a separate line. For example:
decimal-digit: one of
0 1 2 3 4 5 6 7 8 9
is equivalent to:
decimal-digit:
0
1
2
3
4
5
6
7
8
9
A subscripted suffix .opt., as in identifieropt, is used as shorthand to
indicate an optional symbol. The
example:
for-statement:
for ( for-initializeropt ; for-conditionopt ; for-iteratoropt )
embedded-statement
is equivalent to:
本文介绍了C#的词法和句法语法。词法语法定义字符如何组合成标记,句法语法定义标记如何组合成有效程序。语法产生式包含非终结符和终结符,文中说明了它们的表示方式、定义规则,还给出了相关示例。
587

被折叠的 条评论
为什么被折叠?



