A.1 Lexical grammar

Jump to: navigation, search

Contents

A.1 C# Lexical grammar

input:

input-sectionopt

input-section:

input-section-part
input-section   input-section-part

input-section-part:

input-elementsopt   new-line
pp-directive

input-elements:

input-element
input-elements   input-element

input-element:

whitespace
comment
token

A.1.1 C# Line terminators

new-line:

Carriage return character (U+000D)
Line feed character (U+000A)
Carriage return character (U+000D) followed by line feed character (U+000A)
Line separator character (U+2028)
Paragraph separator character (U+2029)

A.1.2 C# White space

whitespace:

Any character with Unicode class Zs
Horizontal tab character (U+0009)
Vertical tab character (U+000B)
Form feed character (U+000C)

A.1.3 C# Comments

comment:

single-line-comment
delimited-comment

single-line-comment:

//   input-charactersopt

input-characters:

input-character
input-characters   input-character

input-character:

Any Unicode character except a new-line-character

new-line-character:

Carriage return character (U+000D)
Line feed character (U+000A)
Line separator character (U+2028)
Paragraph separator character (U+2029)

delimited-comment:

/*   delimited-comment-charactersopt   */

delimited-comment-characters:

delimited-comment-character
delimited-comment-characters   delimited-comment-character

delimited-comment-character:

not-asterisk
*   not-slash

not-asterisk:

Any Unicode character except *

not-slash:

Any Unicode character except /

A.1.4 C# Tokens

token:

identifier
keyword
integer-literal
real-literal
character-literal
string-literal
operator-or-punctuator

A.1.5 C# Unicode character escape sequences

unicode-escape-sequence:

\u   hex-digit   hex-digit   hex-digit   hex-digit
\U   hex-digit   hex-digit   hex-digit hex-digit   hex-digit   hex-digit   hex-digit   hex-digit

A.1.6 C# Identifiers

identifier:

available-identifier
@   identifier-or-keyword

available-identifier:

An identifier-or-keyword that is not a keyword

identifier-or-keyword:

identifier-start-character   identifier-part-charactersopt

identifier-start-character:

letter-character
_ (the underscore character U+005F)

identifier-part-characters:

identifier-part-character
identifier-part-characters   identifier-part-character

identifier-part-character:

letter-character
decimal-digit-character
connecting-character
combining-character
formatting-character

letter-character:

A Unicode character of classes Lu, Ll, Lt, Lm, Lo, or Nl
A unicode-escape-sequence representing a character of classes Lu, Ll, Lt, Lm, Lo, or Nl

combining-character:

A Unicode character of classes Mn or Mc
A unicode-escape-sequence representing a character of classes Mn or Mc

decimal-digit-character:

A Unicode character of the class Nd
A unicode-escape-sequence representing a character of the class Nd

connecting-character:

A Unicode character of the class Pc
A unicode-escape-sequence representing a character of the class Pc

formatting-character:

A Unicode character of the class Cf
A unicode-escape-sequence representing a character of the class Cf

A.1.7 C# Keywords

keyword: one of

abstract as base bool break byte case
catch char checked class const continue decimal
default delegate do double else enum event
explicit extern false finally fixed float for
foreach goto if implicit in int interface
internal is lock long namespace new null
object operator out override params private protected
public readonly ref return sbyte sealed short
sizeof stackalloc static string struct switch this
throw true try typeof uint ulong unchecked
unsafe ushort using virtual void volatile while

A.1.8 C# Literals

literal:

boolean-literal
integer-literal
real-literal
character-literal
string-literal
null-literal

boolean-literal:

true
false

integer-literal:

decimal-integer-literal
hexadecimal-integer-literal

decimal-integer-literal:

decimal-digits   integer-type-suffixopt

decimal-digits:

decimal-digit
decimal-digits   decimal-digit

decimal-digit: one of

0 1 2 3 4 5 6 7 8 9

integer-type-suffix: one of

U u L l UL Ul uL ul LU Lu lU lu

hexadecimal-integer-literal:

0x   hex-digits   integer-type-suffixopt
0X   hex-digits   integer-type-suffixopt

hex-digits:

hex-digit
hex-digits   hex-digit

hex-digit: one of

0 1 2 3 4 5 6 7 8 9 A B C D E F a b c d e f

real-literal:

decimal-digits   .   decimal-digits   exponent-partopt   real-type-suffixopt
.   decimal-digits   exponent-partopt   real-type-suffixopt
decimal-digits   exponent-part   real-type-suffixopt
decimal-digits   real-type-suffix

exponent-part:

e   signopt   decimal-digits
E   signopt   decimal-digits

sign: one of

+ -

real-type-suffix: one of

F f D d M m

character-literal:

'   character   '

character:

single-character
simple-escape-sequence
hexadecimal-escape-sequence
unicode-escape-sequence

single-character:

Any character except ' (U+0027), \ (U+005C), and new-line-character

simple-escape-sequence: one of

\' \" \\ \0 \a \b \f \n \r \t \v

hexadecimal-escape-sequence:

\x   hex-digit   hex-digitopt   hex-digitopt   hex-digitopt

string-literal:

regular-string-literal
verbatim-string-literal

regular-string-literal:

"   regular-string-literal-charactersopt   "

regular-string-literal-characters:

regular-string-literal-character
regular-string-literal-characters   regular-string-literal-character

regular-string-literal-character:

single-regular-string-literal-character
simple-escape-sequence
hexadecimal-escape-sequence
unicode-escape-sequence

single-regular-string-literal-character:

Any character except " (U+0022), \ (U+005C), and new-line-character

verbatim-string-literal:

@"   verbatim -string-literal-charactersopt   "

verbatim-string-literal-characters:

verbatim-string-literal-character
verbatim-string-literal-characters   verbatim-string-literal-character

verbatim-string-literal-character:

single-verbatim-string-literal-character
quote-escape-sequence

single-verbatim-string-literal-character:

any character except "

quote-escape-sequence:

""

null-literal:

null

A.1.9 C# Operators and punctuators

operator-or-punctuator: one of

{ } [ ] ( ) . , : ;<BR>
+ - * / % & | ^ ! ~<BR>
= < > ? ++ -- && || << >><BR>
== != <= >= += -= *= /= %= &=<BR>
|= ^= <<= >>= ->

A.1.10 C# Pre-processing directives

pp-directive:

pp-declaration
pp-conditional
pp-line
pp-diagnostic
pp-region

pp-new-line:

whitespaceopt   single-line-commentopt   new-line

conditional-symbol:

Any identifier-or-keyword except true or false

pp-expression:

whitespaceopt   pp-or-expression   whitespaceopt

pp-or-expression:

pp-and-expression
pp-or-expression   whitespaceopt   ||   whitespaceopt   pp-and-expression

pp-and-expression:

pp-equality-expression
pp-and-expression   whitespaceopt   &&   whitespaceopt   pp-equality-expression

pp-equality-expression:

pp-unary-expression
pp-equality-expression   whitespaceopt   ==   whitespaceopt   pp-unary-expression
pp-equality-expression   whitespaceopt   !=   whitespaceopt   pp-unary-expression

pp-unary-expression:

pp-primary-expression
!   whitespaceopt   pp-unary-expression

pp-primary-expression:

true
false
conditional-symbol
(   whitespaceopt   pp-expression   whitespaceopt   )

pp-declaration:

whitespaceopt   #   whitespaceopt   define   whitespace   conditional-symbol   pp-new-line
whitespaceopt   #   whitespaceopt   undef   whitespace   conditional-symbol   pp-new-line

pp-conditional:

pp-if-section   pp-elif-sectionsopt   pp-else-sectionopt   pp-endif

pp-if-section:

whitespaceopt   #   whitespaceopt   if   whitespace   pp-expression   pp-new-line   conditional-sectionopt

pp-elif-sections:

pp-elif-section
pp-elif-sections   pp-elif-section

pp-elif-section:

whitespaceopt   #   whitespaceopt   elif   whitespace   pp-expression   pp-new-line   conditional-sectionopt

pp-else-section:

whitespaceopt   #   whitespaceopt   else   pp-new-line   conditional-sectionopt

pp-endif:

whitespaceopt   #   whitespaceopt   endif   pp-new-line

conditional-section:

input-section
skipped-section

skipped-section:

skipped-section-part
skipped-section   skipped-section-part

skipped-section-part:

skipped-charactersopt   new-line
pp-directive

skipped-characters:

whitespaceopt   not-number-sign   input-charactersopt

not-number-sign:

Any input-character except #

pp-line:

whitespaceopt   #   whitespaceopt   line   whitespace   line-indicator   pp-new-line

line-indicator:

decimal-digits   whitespace   file-name
decimal-digits
default

file-name:

"   file-name-characters   "

file-name-characters:

file-name-character
file-name-characters   file-name-character

file-name-character:

Any input-character except "

pp-diagnostic:

whitespaceopt   #   whitespaceopt   error   pp-message
whitespaceopt   #   whitespaceopt   warning   pp-message

pp-message:

new-line
whitespace   input-charactersopt   new-line

pp-region:

pp-start-region   conditional-sectionopt   pp-end-region

pp-start-region:

whitespaceopt   #   whitespaceopt   region   pp-message

pp-end-region:

whitespaceopt   #   whitespaceopt   endregion   pp-message

C# Online.NET