grammar csharp; start: compilation_unit; // Namespaces compilation_unit : extern_alias_directive* using_directive* global_attributes? namespace_member_declaration* ; namespace_declaration : 'namespace' qualified_identifier namespace_body ';'? ; qualified_identifier : identifier ('.' identifier)* ; namespace_body : '{' extern_alias_directive* using_directive* namespace_member_declaration* '}' ; extern_alias_directive : 'extern' 'alias' identifier ';' ; using_directive : using_alias_directive | using_namespace_directive | using_static_directive ; using_alias_directive : 'using' identifier '=' namespace_or_type_name ';' ; using_namespace_directive : 'using' namespace_name ';' ; using_static_directive : 'using' 'static' type_name ';' ; namespace_member_declaration : namespace_declaration | type_declaration ; type_declaration : class_declaration | struct_declaration | interface_declaration | enum_declaration | delegate_declaration ; qualified_alias_member : identifier '::' identifier type_argument_list? ; // Basic concepts namespace_name : namespace_or_type_name ; type_name : namespace_or_type_name ; namespace_or_type_name : identifier type_argument_list? | namespace_or_type_name '.' identifier type_argument_list? | qualified_alias_member ; // Types type : value_type | reference_type | type_parameter | type_unsafe ; value_type : struct_type | enum_type ; struct_type : type_name | simple_type | nullable_type ; simple_type : numeric_type | 'bool' ; numeric_type : integral_type | floating_point_type | 'decimal' ; integral_type : 'sbyte' | 'byte' | 'short' | 'ushort' | 'int' | 'uint' | 'long' | 'ulong' | 'char' ; floating_point_type : 'float' | 'double' ; nullable_type : non_nullable_value_type '?' ; non_nullable_value_type : type ; enum_type : type_name ; reference_type : class_type | interface_type | array_type | delegate_type ; class_type : type_name | 'object' | 'dynamic' | 'string' ; interface_type : type_name ; array_type : non_array_type rank_specifier+ ; non_array_type : type ; rank_specifier : '[' dim_separator* ']' ; dim_separator : ',' ; delegate_type : type_name ; type_argument_list : '<' type_arguments '>' ; type_arguments : type_argument (',' type_argument)* ; type_argument : type ; type_parameter : identifier ; // Variables variable_reference : expression ; // Expressions argument_list : argument (',' argument)* ; argument : argument_name? argument_value ; argument_name : identifier ':' ; argument_value : expression | 'ref' variable_reference | 'out' variable_reference ; primary_expression : primary_no_array_creation_expression | array_creation_expression ; primary_no_array_creation_expression : literal | interpolated_string | simple_name | parenthesized_expression | member_access | invocation_expression | element_access | this_access | base_access | post_increment_expression | post_decrement_expression | object_creation_expression | delegate_creation_expression | anonymous_object_creation_expression | typeof_expression | checked_expression | unchecked_expression | default_value_expression | nameof_expression | anonymous_method_expression | primary_no_array_creation_expression_unsafe ; interpolated_string_expression : '$' interpolated_regular_string | '$' interpolated_verbatim_string ; interpolated_regular_string : interpolated_regular_string_whole | interpolated_regular_string_start interpolated_regular_string_body interpolated_regular_string_end ; interpolated_regular_string_body : interpolation (interpolated_regular_string_mid interpolation)* ; interpolation : expression | expression ',' constant_expression ; interpolated_verbatim_string : interpolated_verbatim_string_whole | interpolated_verbatim_string_start interpolated_verbatim_string_body interpolated_verbatim_string_end ; interpolated_verbatim_string_body : interpolation (interpolated_verbatim_string_mid interpolation)+ ; simple_name : identifier type_argument_list? ; parenthesized_expression : '(' expression ')' ; member_access : primary_expression '.' identifier type_argument_list? | predefined_type '.' identifier type_argument_list? | qualified_alias_member '.' identifier ; predefined_type : 'bool' | 'byte' | 'char' | 'decimal' | 'double' | 'float' | 'int' | 'long' | 'object' | 'sbyte' | 'short' | 'string' | 'uint' | 'ulong' | 'ushort' ; invocation_expression : primary_expression '(' argument_list? ')' ; element_access : primary_no_array_creation_expression '[' expression_list ']' ; this_access : 'this' ; base_access : 'base' '.' identifier | 'base' '[' expression_list ']' ; post_increment_expression : primary_expression '++' ; post_decrement_expression : primary_expression '--' ; object_creation_expression : 'new' type '(' argument_list? ')' object_or_collection_initializer? | 'new' type object_or_collection_initializer ; object_or_collection_initializer : object_initializer | collection_initializer ; object_initializer : '{' member_initializer_list? '}' | '{' member_initializer_list ',' '}' ; member_initializer_list : member_initializer (',' member_initializer)* ; member_initializer : initializer_target '=' initializer_value ; initializer_target : identifier | '[' argument_list ']' ; initializer_value : expression | object_or_collection_initializer ; collection_initializer : '{' element_initializer_list '}' | '{' element_initializer_list ',' '}' ; element_initializer_list : element_initializer (',' element_initializer)* ; element_initializer : non_assignment_expression | '{' expression_list '}' ; expression_list : expression (',' expression)* ; array_creation_expression : 'new' non_array_type '[' expression_list ']' rank_specifier* array_initializer? | 'new' array_type array_initializer | 'new' rank_specifier array_initializer ; delegate_creation_expression : 'new' delegate_type '(' expression ')' ; anonymous_object_creation_expression : 'new' anonymous_object_initializer ; anonymous_object_initializer : '{' member_declarator_list? '}' | '{' member_declarator_list ',' '}' ; member_declarator_list : member_declarator (',' member_declarator)* ; member_declarator : simple_name | member_access | base_access | null_conditional_member_access | identifier '=' expression ; typeof_expression : 'typeof' '(' type ')' | 'typeof' '(' unbound_type_name ')' | 'typeof' '(' 'void' ')' ; unbound_type_name : identifier generic_dimension_specifier? | identifier '::' identifier generic_dimension_specifier? | unbound_type_name '.' identifier generic_dimension_specifier? ; generic_dimension_specifier : '<' comma* '>' ; comma : ',' ; checked_expression : 'checked' '(' expression ')' ; unchecked_expression : 'unchecked' '(' expression ')' ; default_value_expression : 'default' '(' type ')' ; nameof_expression : 'nameof' '(' named_entity ')' ; named_entity : simple_name | named_entity_target '.' identifier type_argument_list? ; named_entity_target : 'this' | 'base' | named_entity | predefined_type | qualified_alias_member ; unary_expression : primary_expression | null_conditional_expression | '+' unary_expression | '-' unary_expression | '!' unary_expression | '~' unary_expression | pre_increment_expression | pre_decrement_expression | cast_expression | await_expression | unary_expression_unsafe ; null_conditional_expression : primary_expression null_conditional_operations ; null_conditional_operations : null_conditional_operations? '?' '.' identifier type_argument_list? | null_conditional_operations? '?' '[' argument_list ']' | null_conditional_operations '.' identifier type_argument_list? | null_conditional_operations '[' argument_list ']' | null_conditional_operations '(' argument_list? ')' ; null_conditional_member_access : primary_expression null_conditional_operations? '?' '.' identifier type_argument_list? | primary_expression null_conditional_operations '.' identifier type_argument_list? ; null_conditional_invocation_expression : primary_expression null_conditional_operations '(' argument_list? ')' ; pre_increment_expression : '++' unary_expression ; pre_decrement_expression : '--' unary_expression ; cast_expression : '(' type ')' unary_expression ; await_expression : 'await' unary_expression ; multiplicative_expression : unary_expression | multiplicative_expression '*' unary_expression | multiplicative_expression '/' unary_expression | multiplicative_expression '%' unary_expression ; additive_expression : multiplicative_expression | additive_expression '+' multiplicative_expression | additive_expression '-' multiplicative_expression ; shift_expression : additive_expression | shift_expression '<<' additive_expression | shift_expression right_shift additive_expression ; relational_expression : shift_expression | relational_expression '<' shift_expression | relational_expression '>' shift_expression | relational_expression '<=' shift_expression | relational_expression '>=' shift_expression | relational_expression 'is' type | relational_expression 'as' type ; equality_expression : relational_expression | equality_expression '==' relational_expression | equality_expression '!=' relational_expression ; and_expression : equality_expression | and_expression '&' equality_expression ; exclusive_or_expression : and_expression | exclusive_or_expression '^' and_expression ; inclusive_or_expression : exclusive_or_expression | inclusive_or_expression '|' exclusive_or_expression ; conditional_and_expression : inclusive_or_expression | conditional_and_expression '&&' inclusive_or_expression ; conditional_or_expression : conditional_and_expression | conditional_or_expression '||' conditional_and_expression ; null_coalescing_expression : conditional_or_expression | conditional_or_expression '??' null_coalescing_expression ; conditional_expression : null_coalescing_expression | null_coalescing_expression '?' expression ':' expression ; lambda_expression : anonymous_function_signature '=>' anonymous_function_body ; anonymous_method_expression : 'delegate' explicit_anonymous_function_signature? block ; anonymous_function_signature : explicit_anonymous_function_signature | implicit_anonymous_function_signature ; explicit_anonymous_function_signature : '(' explicit_anonymous_function_parameter_list? ')' ; explicit_anonymous_function_parameter_list : explicit_anonymous_function_parameter (',' explicit_anonymous_function_parameter)* ; explicit_anonymous_function_parameter : anonymous_function_parameter_modifier? type identifier ; anonymous_function_parameter_modifier : 'ref' | 'out' ; implicit_anonymous_function_signature : '(' implicit_anonymous_function_parameter_list? ')' | implicit_anonymous_function_parameter ; implicit_anonymous_function_parameter_list : implicit_anonymous_function_parameter (',' implicit_anonymous_function_parameter)* ; implicit_anonymous_function_parameter : identifier ; anonymous_function_body : expression | block ; query_expression : from_clause query_body ; from_clause : 'from' type? identifier 'in' expression ; query_body : query_body_clauses? select_or_group_clause query_continuation? ; query_body_clauses : query_body_clause | query_body_clauses query_body_clause ; query_body_clause : from_clause | let_clause | where_clause | join_clause | join_into_clause | orderby_clause ; let_clause : 'let' identifier '=' expression ; where_clause : 'where' boolean_expression ; join_clause : 'join' type? identifier 'in' expression 'on' expression 'equals' expression ; join_into_clause : 'join' type? identifier 'in' expression 'on' expression 'equals' expression 'into' identifier ; orderby_clause : 'orderby' orderings ; orderings : ordering (',' ordering)* ; ordering : expression ordering_direction? ; ordering_direction : 'ascending' | 'descending' ; select_or_group_clause : select_clause | group_clause ; select_clause : 'select' expression ; group_clause : 'group' expression 'by' expression ; query_continuation : 'into' identifier query_body ; assignment : unary_expression assignment_operator expression ; assignment_operator : '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<=' | right_shift_assignment ; expression : non_assignment_expression | assignment ; non_assignment_expression : conditional_expression | lambda_expression | query_expression ; constant_expression : expression ; boolean_expression : expression ; // Statements statement : labeled_statement | declaration_statement | embedded_statement ; embedded_statement : block | empty_statement | expression_statement | selection_statement | iteration_statement | jump_statement | try_statement | checked_statement | unchecked_statement | lock_statement | using_statement | yield_statement | embedded_statement_unsafe ; block : '{' statement_list? '}' ; statement_list : statement+ ; empty_statement : ';' ; labeled_statement : identifier ':' statement ; declaration_statement : local_variable_declaration ';' | local_constant_declaration ';' ; local_variable_declaration : local_variable_type local_variable_declarators ; local_variable_type : type | 'var' ; local_variable_declarators : local_variable_declarator | local_variable_declarators ',' local_variable_declarator ; local_variable_declarator : identifier | identifier '=' local_variable_initializer ; local_variable_initializer : expression | array_initializer | local_variable_initializer_unsafe ; local_constant_declaration : 'const' type constant_declarators ; constant_declarators : constant_declarator (',' constant_declarator)* ; constant_declarator : identifier '=' constant_expression ; expression_statement : statement_expression ';' ; statement_expression : invocation_expression | null_conditional_invocation_expression | object_creation_expression | assignment | post_increment_expression | post_decrement_expression | pre_increment_expression | pre_decrement_expression | await_expression ; selection_statement : if_statement | switch_statement ; if_statement : 'if' '(' boolean_expression ')' embedded_statement | 'if' '(' boolean_expression ')' embedded_statement 'else' embedded_statement ; switch_statement : 'switch' '(' expression ')' switch_block ; switch_block : '{' switch_section* '}' ; switch_section : switch_label+ statement_list ; switch_label : 'case' constant_expression ':' | 'default' ':' ; iteration_statement : while_statement | do_statement | for_statement | foreach_statement ; while_statement : 'while' '(' boolean_expression ')' embedded_statement ; do_statement : 'do' embedded_statement 'while' '(' boolean_expression ')' ';' ; for_statement : 'for' '(' for_initializer? ';' for_condition? ';' for_iterator? ')' embedded_statement ; for_initializer : local_variable_declaration | statement_expression_list ; for_condition : boolean_expression ; for_iterator : statement_expression_list ; statement_expression_list : statement_expression (',' statement_expression)* ; foreach_statement : 'foreach' '(' local_variable_type identifier 'in' expression ')' embedded_statement ; jump_statement : break_statement | continue_statement | goto_statement | return_statement | throw_statement ; break_statement : 'break' ';' ; continue_statement : 'continue' ';' ; goto_statement : 'goto' identifier ';' | 'goto' 'case' constant_expression ';' | 'goto' 'default' ';' ; return_statement : 'return' expression? ';' ; throw_statement : 'throw' expression? ';' ; try_statement : 'try' block catch_clause+ | 'try' block finally_clause | 'try' block catch_clause+ finally_clause ; catch_clause : 'catch' exception_specifier? exception_filter? block ; exception_specifier : '(' type identifier? ')' ; exception_filter : 'when' '(' expression ')' ; finally_clause : 'finally' block ; checked_statement : 'checked' block ; unchecked_statement : 'unchecked' block ; lock_statement : 'lock' '(' expression ')' embedded_statement ; using_statement : 'using' '(' resource_acquisition ')' embedded_statement ; resource_acquisition : local_variable_declaration | expression ; yield_statement : 'yield' 'return' expression ';' | 'yield' 'break' ';' ; // Classes class_declaration : attributes? class_modifier* 'partial'? 'class' identifier type_parameter_list? class_base? type_parameter_constraints_clause* class_body ';'? ; class_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | 'abstract' | 'sealed' | 'static' | class_modifier_unsafe ; type_parameter_list : '<' type_parameters '>' ; type_parameters : attributes? type_parameter | type_parameters ',' attributes? type_parameter ; class_base : ':' class_type | ':' interface_type_list | ':' class_type ',' interface_type_list ; interface_type_list : interface_type (',' interface_type)* ; type_parameter_constraints_clause : 'where' type_parameter ':' type_parameter_constraints ; type_parameter_constraints : primary_constraint | secondary_constraints | constructor_constraint | primary_constraint ',' secondary_constraints | primary_constraint ',' constructor_constraint | secondary_constraints ',' constructor_constraint | primary_constraint ',' secondary_constraints ',' constructor_constraint ; primary_constraint : class_type | 'class' | 'struct' ; secondary_constraints : interface_type | type_parameter | secondary_constraints ',' interface_type | secondary_constraints ',' type_parameter ; constructor_constraint : 'new' '(' ')' ; class_body : '{' class_member_declaration* '}' ; class_member_declaration : constant_declaration | field_declaration | method_declaration | property_declaration | event_declaration | indexer_declaration | operator_declaration | constructor_declaration | destructor_declaration | static_constructor_declaration | type_declaration ; constant_declaration : attributes? constant_modifier* 'const' type constant_declarators ';' ; constant_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' ; field_declaration : attributes? field_modifier* type variable_declarators ';' ; field_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | 'static' | 'readonly' | 'volatile' | field_modifier_unsafe ; variable_declarators : variable_declarator (',' variable_declarator)* ; variable_declarator : identifier ('=' variable_initializer)? ; variable_initializer : expression | array_initializer ; method_declaration : method_header method_body ; method_header : attributes? method_modifier* 'partial'? return_type member_name type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ; method_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | 'static' | 'virtual' | 'sealed' | 'override' | 'abstract' | 'extern' | method_modifier_unsafe ; return_type : type | 'void' ; member_name : identifier | interface_type '.' identifier ; method_body : block | '=>' expression ';' | ';' ; formal_parameter_list : fixed_parameters | fixed_parameters ',' parameter_array | parameter_array ; fixed_parameters : fixed_parameter (',' fixed_parameter)* ; fixed_parameter : attributes? parameter_modifier? type identifier default_argument? ; default_argument : '=' expression ; parameter_modifier : 'ref' | 'out' | 'this' ; parameter_array : attributes? 'params' array_type identifier ; property_declaration : attributes? property_modifier* type member_name property_body ; property_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | 'static' | 'virtual' | 'sealed' | 'override' | 'abstract' | 'extern' | property_modifier_unsafe ; property_body : '{' accessor_declarations '}' property_initializer? | '=>' expression ';' ; property_initializer : '=' variable_initializer ; accessor_declarations : get_accessor_declaration set_accessor_declaration? | set_accessor_declaration get_accessor_declaration? ; get_accessor_declaration : attributes? accessor_modifier? 'get' accessor_body ; set_accessor_declaration : attributes? accessor_modifier? 'set' accessor_body ; accessor_modifier : 'protected' | 'internal' | 'private' | 'protected' 'internal' | 'internal' 'protected' ; accessor_body : block | ';' ; event_declaration : attributes? event_modifier* 'event' type variable_declarators ';' | attributes? event_modifier* 'event' type member_name '{' event_accessor_declarations '}' ; event_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | 'static' | 'virtual' | 'sealed' | 'override' | 'abstract' | 'extern' | event_modifier_unsafe ; event_accessor_declarations : add_accessor_declaration remove_accessor_declaration | remove_accessor_declaration add_accessor_declaration ; add_accessor_declaration : attributes? 'add' block ; remove_accessor_declaration : attributes? 'remove' block ; indexer_declaration : attributes? indexer_modifier* indexer_declarator indexer_body ; indexer_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | 'virtual' | 'sealed' | 'override' | 'abstract' | 'extern' | indexer_modifier_unsafe ; indexer_declarator : type 'this' '[' formal_parameter_list ']' | type interface_type '.' 'this' '[' formal_parameter_list ']' ; indexer_body : '{' accessor_declarations '}' | '=>' expression ';' ; operator_declaration : attributes? operator_modifier+ operator_declarator operator_body ; operator_modifier : 'public' | 'static' | 'extern' | operator_modifier_unsafe ; operator_declarator : unary_operator_declarator | binary_operator_declarator | conversion_operator_declarator ; unary_operator_declarator : type 'operator' overloadable_unary_operator '(' type identifier ')' ; overloadable_unary_operator : '+' | '-' | '!' | '~' | '++' | '--' | 'true' | 'false' ; binary_operator_declarator : type 'operator' overloadable_binary_operator '(' type identifier ',' type identifier ')' ; overloadable_binary_operator : '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '<<' | 'right_shift' | '==' | '!=' | '>' | '<' | '>=' | '<=' ; conversion_operator_declarator : 'implicit' 'operator' type '(' type identifier ')' | 'explicit' 'operator' type '(' type identifier ')' ; operator_body : block | '=>' expression ';' | ';' ; constructor_declaration : attributes? constructor_modifier* constructor_declarator constructor_body ; constructor_modifier : 'public' | 'protected' | 'internal' | 'private' | 'extern' | constructor_modifier_unsafe ; constructor_declarator : identifier '(' formal_parameter_list? ')' constructor_initializer? ; constructor_initializer : ':' 'base' '(' argument_list? ')' | ':' 'this' '(' argument_list? ')' ; constructor_body : block | ';' ; static_constructor_declaration : attributes? static_constructor_modifiers identifier '(' ')' static_constructor_body ; static_constructor_modifiers : 'extern'? 'static' | 'static' 'extern'? | static_constructor_modifiers_unsafe ; static_constructor_body : block | ';' ; destructor_declaration : attributes? 'extern'? '~' identifier '(' ')' destructor_body | destructor_declaration_unsafe ; destructor_body : block | ';' ; // Structs struct_declaration : attributes? struct_modifier* 'partial'? 'struct' identifier type_parameter_list? struct_interfaces? type_parameter_constraints_clause* struct_body ';'? ; struct_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | struct_modifier_unsafe ; struct_interfaces : ':' interface_type_list ; struct_body : '{' struct_member_declaration* '}' ; struct_member_declaration : constant_declaration | field_declaration | method_declaration | property_declaration | event_declaration | indexer_declaration | operator_declaration | constructor_declaration | static_constructor_declaration | type_declaration | struct_member_declaration_unsafe ; // Arrays array_initializer : '{' variable_initializer_list? '}' | '{' variable_initializer_list ',' '}' ; variable_initializer_list : variable_initializer (',' variable_initializer)* ; // Interfaces interface_declaration : attributes? interface_modifier* 'partial'? 'interface' identifier variant_type_parameter_list? interface_base? type_parameter_constraints_clause* interface_body ';'? ; interface_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | interface_modifier_unsafe ; variant_type_parameter_list : '<' variant_type_parameters '>' ; variant_type_parameters : attributes? variance_annotation? type_parameter | variant_type_parameters ',' attributes? variance_annotation? type_parameter ; variance_annotation : 'in' | 'out' ; interface_base : ':' interface_type_list ; interface_body : '{' interface_member_declaration* '}' ; interface_member_declaration : interface_method_declaration | interface_property_declaration | interface_event_declaration | interface_indexer_declaration ; interface_method_declaration : attributes? 'new'? return_type identifier type_parameter_list '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; interface_property_declaration : attributes? 'new'? type identifier '{' interface_accessors '}' ; interface_accessors : attributes? 'get' ';' | attributes? 'set' ';' | attributes? 'get' ';' attributes? 'set' ';' | attributes? 'set' ';' attributes? 'get' ';' ; interface_event_declaration : attributes? 'new'? 'event' type identifier ';' ; interface_indexer_declaration : attributes? 'new'? type 'this' '[' formal_parameter_list ']' '{' interface_accessors '}' ; // Enums enum_declaration : attributes? enum_modifier* 'enum' identifier enum_base? enum_body ';'? ; enum_base : ':' integral_type ; enum_body : '{' enum_member_declarations? '}' | '{' enum_member_declarations ',' '}' ; enum_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' ; enum_member_declarations : enum_member_declaration (',' enum_member_declaration)* ; enum_member_declaration : attributes? identifier ('=' constant_expression)? ; // Delegates delegate_declaration : attributes? delegate_modifier* 'delegate' return_type identifier variant_type_parameter_list? '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';' ; delegate_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | delegate_modifier_unsafe ; // Attributes global_attributes : global_attribute_section+ ; global_attribute_section : '[' global_attribute_target_specifier attribute_list ']' | '[' global_attribute_target_specifier attribute_list ',' ']' ; global_attribute_target_specifier : global_attribute_target ':' ; global_attribute_target : 'assembly' | 'module' ; attributes : attribute_section+ ; attribute_section : '[' attribute_target_specifier? attribute_list ']' | '[' attribute_target_specifier? attribute_list ',' ']' ; attribute_target_specifier : attribute_target ':' ; attribute_target : 'field' | 'event' | 'method' | 'param' | 'property' | 'return' | 'type' ; attribute_list : attribute (',' attribute)* ; attribute : attribute_name attribute_arguments? ; attribute_name : type_name ; attribute_arguments : '(' positional_argument_list? ')' | '(' positional_argument_list ',' named_argument_list ')' | '(' named_argument_list ')' ; positional_argument_list : positional_argument (',' positional_argument)* ; positional_argument : attribute_argument_expression ; named_argument_list : named_argument (',' named_argument)* ; named_argument : identifier '=' attribute_argument_expression ; attribute_argument_expression : expression ; // Grammar extensions for unsafe code class_modifier_unsafe : 'unsafe' ; struct_modifier_unsafe : 'unsafe' ; interface_modifier_unsafe : 'unsafe' ; delegate_modifier_unsafe : 'unsafe' ; field_modifier_unsafe : 'unsafe' ; method_modifier_unsafe : 'unsafe' ; property_modifier_unsafe : 'unsafe' ; event_modifier_unsafe : 'unsafe' ; indexer_modifier_unsafe : 'unsafe' ; operator_modifier_unsafe : 'unsafe' ; constructor_modifier_unsafe : 'unsafe' ; destructor_declaration_unsafe : attributes? 'extern'? 'unsafe'? '~' identifier '(' ')' destructor_body | attributes? 'unsafe'? 'extern'? '~' identifier '(' ')' destructor_body ; static_constructor_modifiers_unsafe : 'extern'? 'unsafe'? 'static' | 'unsafe'? 'extern'? 'static' | 'extern'? 'static' 'unsafe'? | 'unsafe'? 'static' 'extern'? | 'static' 'extern'? 'unsafe'? | 'static' 'unsafe'? 'extern'? ; embedded_statement_unsafe : unsafe_statement | fixed_statement ; unsafe_statement : 'unsafe' block ; type_unsafe : pointer_type ; pointer_type : unmanaged_type '*' | 'void' '*' ; unmanaged_type : type ; primary_no_array_creation_expression_unsafe : pointer_member_access | pointer_element_access | sizeof_expression ; unary_expression_unsafe : pointer_indirection_expression | addressof_expression ; pointer_indirection_expression : '*' unary_expression ; pointer_member_access : primary_expression '->' identifier ; pointer_element_access : primary_no_array_creation_expression '[' expression ']' ; addressof_expression : '&' unary_expression ; sizeof_expression : 'sizeof' '(' unmanaged_type ')' ; fixed_statement : 'fixed' '(' pointer_type fixed_pointer_declarators ')' embedded_statement ; fixed_pointer_declarators : fixed_pointer_declarator (',' fixed_pointer_declarator)* ; fixed_pointer_declarator : identifier '=' fixed_pointer_initializer ; fixed_pointer_initializer : '&' variable_reference | expression ; struct_member_declaration_unsafe : fixed_size_buffer_declaration ; fixed_size_buffer_declaration : attributes? fixed_size_buffer_modifier* 'fixed' buffer_element_type fixed_size_buffer_declarator+ ';' ; fixed_size_buffer_modifier : 'new' | 'public' | 'protected' | 'internal' | 'private' | 'unsafe' ; buffer_element_type : type ; fixed_size_buffer_declarator : identifier '[' constant_expression ']' ; local_variable_initializer_unsafe : stackalloc_initializer ; stackalloc_initializer : 'stackalloc' unmanaged_type '[' expression ']' ; // Documentation comments single_line_doc_comment : '///' input_character* ; delimited_doc_comment : '/**' delimited_comment_section* asterisk* '/' ; // Lexical grammar input : input_section? ; input_section : input_section_part+ ; input_section_part : input_element* new_line | pp_directive ; input_element : whitespace | comment | token ; new_line : '' | '' | '' | '' | '' | '' ; comment : single_line_comment | delimited_comment ; single_line_comment : '//' input_character* ; input_character : '' ; new_line_character : '' | '' | '' | '' | '' ; delimited_comment : '/*' delimited_comment_section* asterisk* '/' ; delimited_comment_section : '/' | asterisk* not_slash_or_asterisk ; asterisk : '*' ; not_slash_or_asterisk : '' ; whitespace : '' | '' | '' | '
' ; token : identifier | keyword | integer_literal | real_literal | character_literal | string_literal | interpolated_string_literal | operator_or_punctuator ; 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 ; identifier : available_identifier | '@' identifier_or_keyword ; available_identifier : '' ; identifier_or_keyword : identifier_start_character identifier_part_character* ; identifier_start_character : letter_character | '_' ; identifier_part_character : letter_character | decimal_digit_character | connecting_character | combining_character | formatting_character ; letter_character : '' | '' ; combining_character : '' | '' ; decimal_digit_character : '' | '' ; connecting_character : '' | '' ; formatting_character : '' | '' ; keyword : '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' ; 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_digit+ integer_type_suffix? ; decimal_digit : '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ; integer_type_suffix : 'U' | 'u' | 'L' | 'l' | 'UL' | 'Ul' | 'uL' | 'ul' | 'LU' | 'Lu' | 'lU' | 'lu' ; hexadecimal_integer_literal : '0x' hex_digit+ integer_type_suffix? | '0X' hex_digit+ integer_type_suffix? ; hex_digit : '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_digit+ '.' decimal_digit+ exponent_part? real_type_suffix? | '.' decimal_digit+ exponent_part? real_type_suffix? | decimal_digit+ exponent_part real_type_suffix? | decimal_digit+ real_type_suffix ; exponent_part : 'e' sign? decimal_digit+ | 'E' sign? decimal_digit+ ; sign : '+' | '-' ; real_type_suffix : 'F' | 'f' | 'D' | 'd' | 'M' | 'm' ; character_literal : '\'' character '\'' ; character : single_character | simple_escape_sequence | hexadecimal_escape_sequence | unicode_escape_sequence ; single_character : '' ; simple_escape_sequence : '\\\'' | '\\"' | '\\\\' | '\\0' | '\\a' | '\\b' | '\\f' | '\\n' | '\\r' | '\\t' | '\\v' ; hexadecimal_escape_sequence : '\\x' hex_digit hex_digit? hex_digit? hex_digit?; string_literal : regular_string_literal | verbatim_string_literal ; regular_string_literal : '"' 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 : '' ; verbatim_string_literal : '@"' verbatim_string_literal_character* '"' ; verbatim_string_literal_character : single_verbatim_string_literal_character | quote_escape_sequence ; single_verbatim_string_literal_character : '' ; quote_escape_sequence : '""' ; interpolated_string_literal : '$' interpolated_regular_string_literal | '$' interpolated_verbatim_string_literal ; interpolated_regular_string_literal : interpolated_regular_string_whole | interpolated_regular_string_start interpolated_regular_string_literal_body interpolated_regular_string_end ; interpolated_regular_string_literal_body : regular_balanced_text | interpolated_regular_string_literal_body interpolated_regular_string_mid regular_balanced_text ; interpolated_regular_string_whole : '"' interpolated_regular_string_character* '"' ; interpolated_regular_string_start : '"' interpolated_regular_string_character* '{' ; interpolated_regular_string_mid : interpolation_format? '}' interpolated_regular_string_characters_after_brace? '{' ; interpolated_regular_string_end : interpolation_format? '}' interpolated_regular_string_characters_after_brace? '"' ; interpolated_regular_string_characters_after_brace : interpolated_regular_string_character_no_brace | interpolated_regular_string_characters_after_brace interpolated_regular_string_character ; interpolated_regular_string_character : single_interpolated_regular_string_character | simple_escape_sequence | hexadecimal_escape_sequence | unicode_escape_sequence | open_brace_escape_sequence | close_brace_escape_sequence ; interpolated_regular_string_character_no_brace : '' ; single_interpolated_regular_string_character : '' ; open_brace_escape_sequence : '{{' ; close_brace_escape_sequence : '}}' ; regular_balanced_text : regular_balanced_text_part+ ; regular_balanced_text_part : single_regular_balanced_text_character | delimited_comment | '@' identifier_or_keyword | string_literal | interpolated_string_literal | '(' regular_balanced_text ')' | '[' regular_balanced_text ']' | '{' regular_balanced_text '}' ; single_regular_balanced_text_character : '' | '' ; interpolation_format : interpolation_format_character+ ; interpolation_format_character : '' ; interpolated_verbatim_string_literal : interpolated_verbatim_string_whole | interpolated_verbatim_string_start interpolated_verbatim_string_literal_body interpolated_verbatim_string_end ; interpolated_verbatim_string_literal_body : verbatim_balanced_text | interpolated_verbatim_string_literal_body interpolated_verbatim_string_mid verbatim_balanced_text ; interpolated_verbatim_string_whole : '@"' interpolated_verbatim_string_character* '"' ; interpolated_verbatim_string_start : '@"' interpolated_verbatim_string_character* '{' ; interpolated_verbatim_string_mid : interpolation_format? '}' interpolated_verbatim_string_characters_after_brace? '{' ; interpolated_verbatim_string_end : interpolation_format? '}' interpolated_verbatim_string_characters_after_brace? '"' ; interpolated_verbatim_string_characters_after_brace : interpolated_verbatim_string_character_no_brace | interpolated_verbatim_string_characters_after_brace interpolated_verbatim_string_character ; interpolated_verbatim_string_character : single_interpolated_verbatim_string_character | quote_escape_sequence | open_brace_escape_sequence | close_brace_escape_sequence ; interpolated_verbatim_string_character_no_brace : '' ; single_interpolated_verbatim_string_character : '' ; verbatim_balanced_text : verbatim_balanced_text_part+ ; verbatim_balanced_text_part : single_verbatim_balanced_text_character | comment | '@' identifier_or_keyword | string_literal | interpolated_string_literal | '(' verbatim_balanced_text ')' | '[' verbatim_balanced_text ']' | '{' verbatim_balanced_text '}' ; single_verbatim_balanced_text_character : '' | '' ; null_literal : 'null' ; operator_or_punctuator : '{' | '}' | '[' | ']' | '(' | ')' | '.' | ',' | ':' | ';' | '+' | '-' | '*' | '/' | '%' | '&' | '|' | '^' | '!' | '~' | '=' | '<' | '>' | '?' | '??' | '::' | '++' | '--' | '&&' | '||' | '->' | '==' | '!=' | '<=' | '>=' | '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | '<<' | '<<=' | '=>' ; right_shift : '>>' ; right_shift_assignment : '>>=' ; pp_directive : pp_declaration | pp_conditional | pp_line | pp_diagnostic | pp_region | pp_pragma ; conditional_symbol : '' ; pp_expression : whitespace? pp_or_expression whitespace? ; pp_or_expression : pp_and_expression | pp_or_expression whitespace? '||' whitespace? pp_and_expression ; pp_and_expression : pp_equality_expression | pp_and_expression whitespace? '&&' whitespace? pp_equality_expression ; pp_equality_expression : pp_unary_expression | pp_equality_expression whitespace? '==' whitespace? pp_unary_expression | pp_equality_expression whitespace? '!=' whitespace? pp_unary_expression ; pp_unary_expression : pp_primary_expression | '!' whitespace? pp_unary_expression ; pp_primary_expression : 'true' | 'false' | conditional_symbol | '(' whitespace? pp_expression whitespace? ')' ; pp_declaration : whitespace? '#' whitespace? 'define' whitespace conditional_symbol pp_new_line | whitespace? '#' whitespace? 'undef' whitespace conditional_symbol pp_new_line ; pp_new_line : whitespace? single_line_comment? new_line ; pp_conditional : pp_if_section pp_elif_section* pp_else_section? pp_endif ; pp_if_section : whitespace? '#' whitespace? 'if' whitespace pp_expression pp_new_line conditional_section? ; pp_elif_section : whitespace? '#' whitespace? 'elif' whitespace pp_expression pp_new_line conditional_section? ; pp_else_section: | whitespace? '#' whitespace? 'else' pp_new_line conditional_section? ; pp_endif : whitespace? '#' whitespace? 'endif' pp_new_line ; conditional_section : input_section | skipped_section ; skipped_section : skipped_section_part+ ; skipped_section_part : skipped_characters? new_line | pp_directive ; skipped_characters : whitespace? not_number_sign input_character* ; not_number_sign : '' ; pp_diagnostic : whitespace? '#' whitespace? 'error' pp_message | whitespace? '#' whitespace? 'warning' pp_message ; pp_message : new_line | whitespace input_character* new_line ; pp_region : pp_start_region conditional_section? pp_end_region ; pp_start_region : whitespace? '#' whitespace? 'region' pp_message ; pp_end_region : whitespace? '#' whitespace? 'endregion' pp_message ; pp_line : whitespace? '#' whitespace? 'line' whitespace line_indicator pp_new_line ; line_indicator : decimal_digit+ whitespace file_name | decimal_digit+ | 'default' | 'hidden' ; file_name : '"' file_name_character+ '"' ; file_name_character : '' ; pp_pragma : whitespace? '#' whitespace? 'pragma' whitespace pragma_body pp_new_line ; pragma_body : pragma_warning_body ; pragma_warning_body : 'warning' whitespace warning_action | 'warning' whitespace warning_action whitespace warning_list ; warning_action : 'disable' | 'restore' ; warning_list : decimal_digit+ (whitespace? ',' whitespace? decimal_digit+)* ;