5. Notational conventions

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

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:

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航