Lexical and syntactic grammars for C# are interspersed throughout this specification. The lexical grammar defines how characters can be combined to form tokens; the syntactic grammar defines how tokens can be combined to form C# programs.
Grammar productions include non-terminal symbols 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 non-terminal, followed by a colon. Each successive indented line contains the right-hand side for a production that has the non-terminal symbol as the left-hand side. The example:
defines the nonsense non-terminal as having two productions, one with terminal1
on the right-hand side and one with terminal2
on the right-hand side.
Alternatives are normally listed on separate lines, 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. The example:
is shorthand for:
A subscripted suffix "opt", as in identifieropt, is used as shorthand to indicate an optional symbol. The example:
is shorthand for: