ECMA-334: 5. Notational conventions

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Language Specification
© 2006 ECMA International

5. Notational conventions

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, non-terminal 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
static

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:

for-statement:
for ( ; ; ) embedded-statement
for ( for-initializer ; ; ) embedded-statement
for ( ; for-condition ; ) embedded-statement
for ( ; ; for-iterator ) embedded-statement
for ( for-initializer ; for-condition ; ) embedded-statement
for ( ; for-condition ; for-iterator ) embedded-statement
for ( for-initializer ; ; for-iterator ) embedded-statement
for ( for-initializer ; for-condition ; for-iterator ) embedded-statement

All terminal characters are to be understood as the appropriate Unicode character from the range U+0020 to U+007F, as opposed to any similar-looking characters from other Unicode character ranges.


Today's Deals: Electronics

Personal tools