comments // /* */ end comments keys 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 end keys tokens hexadecimal_integer_literal "0x[\dABCDEFabcdef]+[(UL)(Ul)(uL)(ul)(LU)(Lu)(lU)(lu)UuLl]?" real_literal "\d+.\d+([eE][+-]?\d+)?[fFDdMm]?" | ".\d+([eE][+-]?\d+)?[fFDdMm]?" | "\d+([eE][+-]?\d+)[fFDdMm]?" | "\d+[fFDdMm]" decimal_integer_literal "\d+[(UL)(Ul)(uL)(ul)(LU)(Lu)(lU)(lu)UuLl]?" charlit "'[(\\\c)#']*'" stringlit "\"[(\\\c)#\"]*\"" | "@\"[(\"\")#\"]*\"" id "@?[\a_][\a\d_]*" end tokens define literal [boolean_literal] | [integer_literal] | [real_literal] | [character_literal] | [string_literal] | [null_literal] end define define boolean_literal 'true | 'false end define define integer_literal [decimal_integer_literal] | [hexadecimal_integer_literal] end define define character_literal [charlit] end define define string_literal [stringlit] end define define null_literal 'null end define compounds ?? :: ++ -- && || -> == != <= >= += -= *= /= '%= &= |= ^= << <<= end compounds comments '# end comments define program [compilation_unit] end define define compilation_unit [opt extern_alias_directives] [opt using_directives] [opt global_attributes] [opt namespace_member_declarations] end define define namespace_name [namespace_or_type_name] end define define type_name [namespace_or_type_name] end define define namespace_or_type_name [opt 'this] [id] [opt colon_colon_id] [repeat dot_id] [opt type_argument_list] end define define colon_colon_id ':: [id] end define define dot_id '. [id] end define define type [value_type] | [reference_type] | [type_parameter] end define define value_type [struct_type] | [enum_type] end define define struct_type [type_name] | [simple_type] | [nullable_type] end define define simple_type [numeric_type] | 'bool end define define numeric_type [integral_type] | [floating_point_type] | 'decimal end define define integral_type 'sbyte | 'byte | 'short | 'ushort | 'int | 'uint | 'long | 'ulong | 'char end define define floating_point_type 'float | 'double end define define enum_type [type_name] end define define nullable_type [non_nullable_value_type] '? end define define non_nullable_value_type [enum_type] | [type_name] | [simple_type] end define define reference_type [class_type] | [interface_type] | [array_type] | [delegate_type] end define define class_type [type_name] | 'object | 'string end define define interface_type [type_name] end define define array_type [non_array_type] [rank_specifiers] end define define non_array_type [value_type] | [class_type] | [interface_type] | [delegate_type] | [type_parameter] end define define rank_specifiers [repeat rank_specifier] end define define rank_specifier '[ [repeat ',] '] end define define delegate_type [type_name] end define define variable_reference [expression] end define define argument_list [list argument] end define define argument [expression] | 'ref [variable_reference] | 'out [variable_reference] end define define primary_expression [array_creation_expression] | [primary_no_array_creation_expression] | [object_initializer_expression] end define define primary_no_array_creation_expression [simple_primary_expression] [repeat primary_expression_modifier] end define define simple_primary_expression [literal] | [simple_name] | [parenthesized_expression] | [this_access] | [base_access] | [object_or_delegate_creation_expression] | [typeof_expression] | [checked_expression] | [unchecked_expression] | [default_value_expression] | [anonymous_method_expression] | [predefined_type] [member_access_operator] | [qualified_alias_member] [member_access_operator] end define define primary_expression_modifier [member_access_operator] | [invocation_operator] | [element_access_operator] | [post_increment_operator] | [post_decrement_operator] end define define simple_name [id] [opt type_argument_list] end define define parenthesized_expression '( [expression] ') end define define member_access_operator '. [id] [opt type_argument_list] end define define predefined_type 'bool | 'byte | 'char | 'decimal | 'double | 'float | 'int | 'long | 'object | 'sbyte | 'short | 'string | 'uint | 'ulong | 'ushort end define define invocation_operator '( [list argument] ') end define define element_access_operator '[ [list expression +] '] end define define this_access 'this end define define base_access 'base '. [id] [opt type_argument_list] | 'base '[ [list expression +] '] end define define post_increment_operator '++ end define define post_decrement_operator '-- end define define object_or_delegate_creation_expression 'new [type] '( [opt argument_list] ') end define define array_creation_expression 'new [non_array_type] '[ [expression_list] '] [opt rank_specifiers] [opt array_initializer] | 'new [array_type] [array_initializer] end define define object_initializer_expression 'new [opt array_type] [opt object_formals] [opt rank_specifiers] [object_initializer] end define define object_formals '( [opt formal_parameter_list] ') end define define object_initializer '{ [opt member_initializer_list] [opt ',] '} end define define member_initializer_list [list member_initializer +] end define define member_initializer [opt member_name_equals] [expression] | [opt member_name_equals] [array_initializer] end define define member_name_equals [simple_name] '= end define define expression_list [list expression +] end define define typeof_expression 'typeof '( [type] ') | 'typeof '( [unbound_type_name] ') | 'typeof '( 'void ') | 'typeof '( ') end define define unbound_type_name [id] [opt colon_colon_id] [opt generic_dimension_specifier] [repeat dot_id_generic_dimension_specifier] end define define dot_id_generic_dimension_specifier '. [id] [opt generic_dimension_specifier] end define define generic_dimension_specifier '< [repeat ',] '> end define define checked_expression 'checked '( [expression] ') end define define unchecked_expression 'unchecked '( [expression] ') end define define default_value_expression 'default '( [type] ') end define define anonymous_method_expression 'delegate [opt anonymous_method_signature] [block] end define define anonymous_method_signature '( [opt anonymous_method_parameter_list] ') end define define anonymous_method_parameter_list [list anonymous_method_parameter +] end define define anonymous_method_parameter [opt parameter_modifier] [type] [id] end define define unary_expression [primary_expression] | '+ [unary_expression] | '- [unary_expression] | '! [unary_expression] | '~ [unary_expression] | [pre_increment_expression] | [pre_decrement_expression] | [cast_expression] end define define pre_increment_expression '++ [unary_expression] end define define pre_decrement_expression '-- [unary_expression] end define define cast_expression '( [type] ') [unary_expression] end define define multiplicative_expression [unary_expression] | [multiplicative_expression] '* [unary_expression] | [multiplicative_expression] '/ [unary_expression] | [multiplicative_expression] '% [unary_expression] end define define additive_expression [multiplicative_expression] | [additive_expression] '+ [multiplicative_expression] | [additive_expression] '- [multiplicative_expression] end define define shift_expression [additive_expression] | [shift_expression] '<< [additive_expression] | [shift_expression] '>> [additive_expression] end define define 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] end define define equality_expression [relational_expression] | [equality_expression] '== [relational_expression] | [equality_expression] '!= [relational_expression] end define define and_expression [equality_expression] | [and_expression] '& [equality_expression] end define define exclusive_or_expression [and_expression] | [exclusive_or_expression] '^ [and_expression] end define define inclusive_or_expression [exclusive_or_expression] | [inclusive_or_expression] '| [exclusive_or_expression] end define define conditional_and_expression [inclusive_or_expression] | [conditional_and_expression] '&& [inclusive_or_expression] end define define conditional_or_expression [conditional_and_expression] | [conditional_or_expression] '|| [conditional_and_expression] end define define null_coalescing_expression [conditional_or_expression] | [conditional_or_expression] '?? [null_coalescing_expression] end define define conditional_expression [null_coalescing_expression] | [null_coalescing_expression] '? [expression] ': [expression] end define define assignment [unary_expression] [assignment_operator] [expression] end define define assignment_operator '= | '+= | '-= | '*= | '/= | '%= | '&= | '|= | '^= | '<<= | '>>= end define define expression [conditional_expression] | [assignment] | [query_expression] | [lambda_expression] end define define constant_expression [expression] end define define boolean_expression [expression] end define define query_expression [from_clause] [IN] [query_body] [EX] end define define query_body [repeat query_body_clause] [final_query_clause] [opt query_continuation] end define define query_body_clause [NL] [from_clause] | [NL] [join_clause] | [NL] [let_clause] | [NL] [where_clause] | [NL] [orderby_clause] end define define from_clause 'from [item_name] 'in [src_expr] end define define join_clause 'join [item_name] 'in [src_expr] 'on [key_expr] 'equals [key_expr] [opt into_item_name] end define define into_item_name 'into [item_name] end define define let_clause 'let [item_name] '= [sel_expr] end define define where_clause 'where [pred_expr] end define define orderby_clause 'orderby [list key_expr_ascending_descending] end define define key_expr_ascending_descending [key_expr] [opt ascending_descending] end define define ascending_descending 'ascending | 'descending end define define final_query_clause [NL] [select_clause] | [NL] [groupby_clause] end define define select_clause 'select [sel_expr] end define define groupby_clause 'group [sel_expr] 'by [key_expr] end define define query_continuation 'into [item_name] [query_body] end define define item_name [opt type] [simple_name] end define define sel_expr [expression] end define define key_expr [expression] end define define src_expr [expression] end define define pred_expr [expression] end define define lambda_expression [input_parameters] '=> [expression] | [input_parameters] '=> [block] end define define input_parameters [input_parameter] | '( [list input_parameter] ') end define define input_parameter [opt type] [id] end define define constant_expression [expression] end define define boolean_expression [expression] end define define statement [labeled_statement] | [declaration_statement] | [embedded_statement] end define define 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] end define define block '{ [NL] [IN] [opt statement_list] [EX] '} [opt ';] end define define statement_list [repeat statement +] end define define empty_statement '; end define define labeled_statement [id] ': [statement] end define define declaration_statement [local_variable_declaration] '; [NL] | [local_constant_declaration] '; [NL] end define define local_variable_declaration [type] [local_variable_declarators] end define define local_variable_declarators [list local_variable_declarator +] end define define local_variable_declarator [id] [opt equals_local_variable_initializer] end define define equals_local_variable_initializer '= [local_variable_initializer] end define define local_variable_initializer [expression] | [array_initializer] end define define local_constant_declaration 'const [type] [constant_declarators] end define define expression_statement [statement_expression] '; [NL] end define define statement_expression [primary_no_array_creation_expression] | [object_creation_expression] | [assignment] | [pre_increment_expression] | [pre_decrement_expression] end define define object_creation_expression 'new [type] '( [opt argument_list] ') end define define selection_statement [if_statement] | [switch_statement] end define define if_statement 'if '( [boolean_expression] ') [nested_statement] [repeat else_if_clause] [opt else_clause] [NL] end define define else_if_clause 'else 'if '( [boolean_expression] ') [nested_statement] end define define else_clause 'else [nested_statement] end define define nested_statement [block] | [IN] [NL] [embedded_statement] [EX] end define define switch_statement 'switch '( [expression] ') [switch_block] end define define switch_block '{ [NL] [IN] [switch_sections] [EX] '} [NL] end define define switch_sections [repeat switch_section +] end define define switch_section [switch_labels] [NL] [IN] [statement_list] [EX] end define define switch_labels [repeat switch_label +] end define define switch_label 'case [constant_expression] ': | 'default ': end define define iteration_statement [while_statement] | [do_statement] | [for_statement] | [foreach_statement] end define define while_statement 'while '( [boolean_expression] ') [nested_statement] [NL] end define define do_statement 'do [NL] [IN] [embedded_statement] [EX] 'while '( [boolean_expression] ') '; [NL] end define define for_statement 'for '( [opt for_initializer] '; [opt for_condition] '; [opt for_iterator] ') [nested_statement] [NL] end define define for_initializer [local_variable_declaration] | [statement_expression_list] end define define for_condition [boolean_expression] end define define for_iterator [statement_expression_list] end define define statement_expression_list [list statement_expression +] end define define foreach_statement 'foreach '( [type] [id] 'in [expression] ') [nested_statement] [NL] end define define jump_statement [break_statement] | [continue_statement] | [goto_statement] | [return_statement] | [throw_statement] end define define break_statement 'break '; [NL] end define define continue_statement 'continue '; [NL] end define define goto_statement 'goto [id] '; [NL] | 'goto 'case [constant_expression] '; [NL] | 'goto 'default '; [NL] end define define return_statement 'return [opt expression] '; [NL] end define define throw_statement 'throw [opt expression] '; [NL] end define define try_statement 'try [block] [NL] [opt catch_clauses] [opt finally_clause] end define define catch_clauses [opt specific_catch_clauses] [opt general_catch_clause] end define define specific_catch_clauses [repeat specific_catch_clause +] end define define specific_catch_clause 'catch '( [class_type] [opt id] ') [block] [NL] end define define general_catch_clause 'catch [block] [NL] end define define finally_clause 'finally [block] [NL] end define define checked_statement 'checked [block] [NL] end define define unchecked_statement 'unchecked [block] [NL] end define define lock_statement 'lock '( [expression] ') [NL] [embedded_statement] end define define using_statement 'using '( [resource_acquisition] ') [NL] [embedded_statement] end define define resource_acquisition [local_variable_declaration] | [expression] end define define yield_statement 'yield 'return [expression] '; [NL] | 'yield 'break '; [NL] end define define namespace_declaration 'namespace [qualified_identifier] [NL] [namespace_body] end define define qualified_identifier [id] [repeat dot_id] end define define namespace_body '{ [NL] [IN] [opt extern_alias_directives] [opt using_directives] [opt namespace_member_declarations] [EX] '} [opt ';] [NL] end define define extern_alias_directives [repeat extern_alias_directive +] [NL] end define define extern_alias_directive 'extern [id] [id] '; [NL] end define define using_directives [repeat using_directive +] [NL] end define define using_directive [using_alias_directive] | [using_namespace_directive] end define define using_alias_directive 'using [id] '= [namespace_or_type_name] '; [NL] end define define using_namespace_directive 'using [namespace_name] '; [NL] end define define namespace_member_declarations [repeat namespace_member_declaration +] end define define namespace_member_declaration [namespace_declaration] [NL] | [type_declaration] [NL] end define define type_declaration [class_declaration] | [struct_declaration] | [interface_declaration] | [enum_declaration] | [delegate_declaration] end define define qualified_alias_member [id] ':: [id] [opt type_argument_list] end define define class_declaration [opt attributes] [opt class_modifiers] [opt 'partial] 'class [id] [opt type_parameter_list] [opt class_base] [opt type_parameter_constraints_clauses] [NL] [class_body] end define define class_modifiers [repeat class_modifier +] end define define class_modifier 'new | 'public | 'protected | 'internal | 'private | 'abstract | 'sealed | 'static end define define class_base ': [class_and_interface_type_ist] end define define class_and_interface_type_ist [list class_or_interface_type +] end define define class_or_interface_type [class_type] | [interface_type] end define define class_body '{ [NL] [IN] [opt class_member_declarations] [EX] '} [opt ';] [NL] end define define class_member_declarations [repeat class_member_declaration *] end define define class_member_declaration [constant_declaration] | [field_declaration] | [method_declaration] | [property_declaration] | [event_declaration] | [indexer_declaration] | [operator_declaration] | [constructor_declaration] | [finalizer_declaration] | [static_constructor_declaration] | [type_declaration] end define define constant_declaration [opt attributes] [opt constant_modifiers] 'const [type] [constant_declarators] '; [NL] end define define constant_modifiers [repeat constant_modifier +] end define define constant_modifier 'new | 'public | 'protected | 'internal | 'private end define define constant_declarators [list constant_declarator +] end define define constant_declarator [id] '= [constant_expression] end define define field_declaration [opt attributes] [opt field_modifiers] [type] [variable_declarators] '; [NL] end define define field_modifiers [repeat field_modifier +] end define define field_modifier 'new | 'public | 'protected | 'internal | 'private | 'static | 'readonly | 'volatile end define define variable_declarators [list variable_declarator +] end define define variable_declarator [id] [opt equals_variable_initializer] end define define equals_variable_initializer '= [variable_initializer] end define define variable_initializer [expression] | [array_initializer] end define define method_declaration [method_header] [NL] [method_body] [NL] end define define method_header [opt attributes] [opt method_modifiers] [return_type] [member_name] [opt type_parameter_list] '( [opt formal_parameter_list] ') [opt type_parameter_constraints_clauses] end define define method_modifiers [repeat method_modifier +] end define define method_modifier 'new | 'public | 'protected | 'internal | 'private | 'static | 'virtual | 'sealed | 'override | 'abstract | 'extern | 'partial end define define return_type [type] | 'void end define define member_name [opt interface_type_dot] [id] end define define interface_type_dot [interface_type] '. end define define method_body [block] [NL] | '; [NL] end define define formal_parameter_list [fixed_parameters] [opt comma_parameter_array] end define define comma_parameter_array ', [parameter_array] end define define fixed_parameters [list fixed_parameter +] end define define fixed_parameter [opt attributes] [opt parameter_modifier] [type] [id] | [parameter_array] end define define parameter_modifier 'ref | 'out end define define parameter_array [opt attributes] 'params [array_type] [id] end define define property_declaration [NL] [opt attributes] [opt property_modifiers] [type] [member_name] '{ [NL] [IN] [accessor_declarations] [EX] '} [NL] end define define property_modifiers [repeat property_modifier +] end define define property_modifier 'new | 'public | 'protected | 'internal | 'private | 'static | 'virtual | 'sealed | 'override | 'abstract | 'extern end define define accessor_declarations [get_accessor_declaration] [opt set_accessor_declaration] | [set_accessor_declaration] [opt get_accessor_declaration] end define define get_accessor_declaration [opt attributes] [opt accessor_modifier] 'get [accessor_body] end define define set_accessor_declaration [opt attributes] [opt accessor_modifier] 'set [accessor_body] end define define accessor_modifier 'protected | 'internal | 'private | 'protected 'internal | 'internal 'protected end define define accessor_body [block] [NL] | '; [NL] end define define event_declaration [opt attributes] [opt event_modifiers] 'event [type] [variable_declarators] '; [NL] | [opt attributes] [opt event_modifiers] 'event [type] [member_name] '{ [NL] [IN] [event_accessor_declarations] [EX] '} [NL] [EX] end define define event_modifiers [repeat event_modifier +] end define define event_modifier 'new | 'public | 'protected | 'internal | 'private | 'static | 'virtual | 'sealed | 'override | 'abstract | 'extern end define define event_accessor_declarations [add_accessor_declaration] [remove_accessor_declaration] | [remove_accessor_declaration] [add_accessor_declaration] end define define add_accessor_declaration [opt attributes] 'add [block] [NL] end define define remove_accessor_declaration [opt attributes] 'remove [block] [NL] end define define indexer_declaration [opt attributes] [opt indexer_modifiers] [indexer_declarator] '{ [NL] [IN] [accessor_declarations] [EX] '} [NL] end define define indexer_modifiers [repeat indexer_modifier +] end define define indexer_modifier 'new | 'public | 'protected | 'internal | 'private | 'virtual | 'sealed | 'override | 'abstract | 'extern end define define indexer_declarator [type] [opt interface_type_dot] 'this '[ [formal_parameter_list] '] end define define operator_declaration [opt attributes] [opt operator_modifiers] [operator_declarator] [operator_body] end define define operator_modifiers [repeat operator_modifier +] end define define operator_modifier 'public | 'static | 'extern end define define operator_declarator [unary_operator_declarator] | [binary_operator_declarator] | [conversion_operator_declarator] end define define unary_operator_declarator [type] 'operator [overloadable_unary_operator] '( [type] [id] ') end define define overloadable_unary_operator '+ | '- | '! | '~ | '++ | '-- | 'true | 'false end define define binary_operator_declarator [type] 'operator [overloadable_binary_operator] '( [type] [id] ') end define define overloadable_binary_operator '+ | '- | '* | '/ | '% | '& | '| | '^ | '<< | '>> | '== | '!= | '> | '< | '>= | '<= end define define conversion_operator_declarator 'implicit 'operator [type] '( [type] [id] ') | 'explicit 'operator [type] '( [type] [id] ') end define define operator_body [block] [NL] | '; [NL] end define define constructor_declaration [opt attributes] [opt constructor_modifiers] [constructor_declarator] [NL] [constructor_body] [NL] end define define constructor_modifiers [repeat constructor_modifier +] end define define constructor_modifier 'public | 'protected | 'internal | 'private | 'extern end define define constructor_declarator [id] '( [opt formal_parameter_list] ') [opt constructor_initializer] end define define constructor_initializer ': 'base '( [opt argument_list] ') | ': 'this '( [opt argument_list] ') end define define constructor_body [block] [NL] | '; [NL] end define define static_constructor_declaration [opt attributes] [static_constructor_modifiers] [id] '( ') [NL] [static_constructor_body] [NL] end define define static_constructor_modifiers [opt 'extern] 'static | 'static [opt 'extern] end define define static_constructor_body [block] [NL] | '; [NL] end define define finalizer_declaration [opt attributes] [opt 'extern] '~ [id] '( ') [finalizer_body] end define define finalizer_body [block] [NL] | '; [NL] end define define struct_declaration [opt attributes] [opt struct_modifiers] [opt 'partial] 'struct [id] [opt type_parameter_list] [opt struct_interfaces ] [opt type_parameter_constraints_clauses] [NL] [struct_body] [NL] end define define struct_modifiers [repeat struct_modifier +] end define define struct_modifier 'new | 'public | 'proctected | 'internal | 'private end define define struct_interfaces ': [interface_type_list] end define define interface_type_list [list interface_type +] end define define struct_body '{ [NL] [IN] [opt struct_member_declarations] [EX] '} [opt ';] [NL] end define define struct_member_declarations [repeat struct_member_declaration +] end define define struct_member_declaration [constant_declaration] | [field_declaration] | [method_declaration] | [property_declaration] | [event_declaration] | [indexer_declaration] | [operator_declaration] | [constructor_declaration] | [static_constructor_declaration] | [type_declaration] end define define array_initializer '{ [opt variable_initializer_list] [opt ',] '} end define define variable_initializer_list [list variable_initializer +] end define define interface_declaration [opt attributes] [opt interface_modifiers] [opt 'partial] 'interface [id] [opt type_parameter_list] [opt interface_base] [opt type_parameter_constraints_clauses] [NL] [interface_body] [NL] end define define interface_modifiers [repeat interface_modifier] end define define interface_modifier 'new | 'public | 'protected | 'internal | 'private end define define interface_base ': [interface_type_list] end define define interface_body '{ [NL] [IN] [opt interface_member_declarations] [EX] '} [opt ';] [NL] end define define interface_member_declarations [repeat interface_member_declaration +] end define define interface_member_declaration [interface_method_declaration] | [interface_property_declaration] | [interface_event_declaration] | [interface_indexer_declaration] end define define interface_method_declaration [opt attributes] [opt 'new] [return_type] [id] [opt type_parameter_list] '( [opt formal_parameter_list] ') [opt type_parameter_constraints_clauses] '; [NL] end define define interface_property_declaration [opt attributes] [opt 'new] [type] [id] [NL] '{ [NL] [IN] [interface_accessors] [EX] '} [NL] end define define interface_accessors [opt attributes] 'get '; | [opt attributes] 'set '; | [opt attributes] 'get '; [opt attributes] 'set '; | [opt attributes] 'set '; [opt attributes] 'get '; end define define interface_event_declaration [opt attributes] [opt 'new] 'event [type] [id] '; [NL] end define define interface_indexer_declaration [opt attributes] [opt 'new] [type] 'this '[ [formal_parameter_list] '] '{ [NL] [IN] [interface_accessors] [EX] '} [NL] end define define enum_declaration [opt attributes] [opt enum_modifiers] 'enum [id] [opt enum_base] [enum_body] [NL] end define define enum_base ': [integral_type] end define define enum_body '{ [NL] [IN] [opt enum_member_declarations] [opt ',] [EX] '} [opt ';] [NL] end define define enum_modifiers [repeat enum_modifier +] end define define enum_modifier 'new | 'public | 'protected | 'internal | 'private end define define enum_member_declarations [list enum_member_declaration +] end define define enum_member_declaration [opt attributes] [id] [opt equals_constant_expression] end define define equals_constant_expression '= [constant_expression] end define define delegate_declaration [opt attributes] [opt delegate_modifiers] 'delegate [return_type] [id] [opt type_parameter_list] '( [opt formal_parameter_list] ') [opt type_parameter_constraints_clauses] '; [NL] end define define delegate_modifiers [repeat delegate_modifier +] end define define delegate_modifier 'new | 'public | 'protected | 'internal | 'private end define define global_attributes [global_attribute_sections] end define define global_attribute_sections [repeat global_attribute_section +] end define define global_attribute_section '[ [global_attribute_target_specifier] [attribute_list] [opt ',] '] end define define global_attribute_target_specifier [global_attribute_target] ': end define define global_attribute_target [id] | [key] end define define attributes [attribute_sections] end define define attribute_sections [repeat attribute_section +] end define define attribute_section '[ [opt attribute_target_specifier] [attribute_list] [opt ',] '] end define define attribute_target_specifier [attribute_target] ': end define define attribute_target [id] | [key] end define define attribute_list [list attribute +] end define define attribute [attribute_name] [opt attribute_arguments] end define define attribute_name [type_name] end define define attribute_arguments '( [attribute_argument_list] ') end define define attribute_argument_list [list attribute_argument] end define define attribute_argument [positional_argument] | [named_argument] end define define positional_argument [attribute_argument_expression] end define define named_argument [id] '= [attribute_argument_expression] end define define attribute_argument_expression [expression] end define define type_parameter_list '< [type_parameters] '> end define define type_parameters [list attributes_type_parameter +] end define define attributes_type_parameter [opt attributes] [type_parameter] end define define type_parameter [id] end define define type_argument_list '< [list type_argument +] '> end define define type_argument [type] end define define type_parameter_constraints_clauses [repeat type_parameter_constraints_clause +] end define define type_parameter_constraints_clause 'where [type_parameter] ': [type_parameter_constraints] end define define type_parameter_constraints [list type_parameter_constraint] end define define type_parameter_constraint [primary_constraint] | [secondary_constraint] | [constructor_constraint] end define define primary_constraint [class_type] | 'class | 'struct end define define secondary_constraint [interface_type] | [type_parameter] end define define constructor_constraint 'new '( ') end define redefine class_modifier ... | 'unsafe end redefine redefine struct_modifier ... | 'unsafe end redefine redefine interface_modifier ... | 'unsafe end redefine redefine delegate_modifier ... | 'unsafe end redefine redefine field_modifier ... | 'unsafe end redefine redefine method_modifier ... | 'unsafe end redefine redefine property_modifier ... | 'unsafe end redefine redefine event_modifier ... | 'unsafe end redefine redefine indexer_modifier ... | 'unsafe end redefine redefine operator_modifier ... | 'unsafe end redefine redefine constructor_modifier ... | 'unsafe end redefine redefine finalizer_declaration [opt attributes] [opt 'extern] [opt 'unsafe] '~ [id] '( ') [NL] [finalizer_body] [NL] | [opt attributes] [opt 'unsafe] [opt 'extern] '~ [id] '( ') [NL] [finalizer_body] [NL] end redefine redefine static_constructor_modifiers [opt 'extern] [opt 'unsafe] 'static | [opt 'unsafe] [opt 'extern] 'static | [opt 'extern] 'static [opt 'unsafe] | [opt 'unsafe] 'static [opt 'extern] | 'static [opt 'extern] [opt 'unsafe] | 'static [opt 'unsafe] [opt 'extern] end redefine redefine embedded_statement ... | [unsafe_statement] end redefine define unsafe_statement 'unsafe [block] end define redefine type [pointer_type] end redefine define pointer_type [unmanaged_type] [repeat '*] | 'void '* [repeat '*] end define define unmanaged_type [value_type] | [reference_type] | [type_parameter] end define redefine primary_no_array_creation_expression ... | [sizeof_expression] end redefine redefine primary_expression_modifier ... | [pointer_member_access_operator] | [pointer_element_access_operator] end redefine redefine unary_expression ... | [pointer_indirection_expression] | [addressof_expression] end redefine define pointer_indirection_expression '* [unary_expression] end define define pointer_member_access_operator '-> [id] [opt type_argument_list] end define define pointer_element_access_operator '[ [expression] '] end define define addressof_expression '& [unary_expression] end define define sizeof_expression 'sizeof '( [unmanaged_type] ') end define redefine embedded_statement ... | [fixed_statement] end redefine define fixed_statement 'fixed '( [pointer_type] [fixed_pointer_declarators] ') [embedded_statement] end define define fixed_pointer_declarators [list fixed_pointer_declarator +] end define define fixed_pointer_declarator [id] '= [fixed_pointer_initializer] end define define fixed_pointer_initializer '& [variable_reference] | [expression] end define redefine local_variable_initializer [expression] | [array_initializer] | [stackalloc_initializer] end redefine define stackalloc_initializer 'stackalloc [unmanaged_type] '[ [expression] '] end define define comments_ [repeat comment_NL] end define define comment_NL [comment] [NL] end define redefine embedded_statement ... | [comment_NL] end redefine redefine namespace_member_declaration ... | [comment_NL] end redefine redefine class_member_declaration ... | [comment_NL] end redefine redefine struct_member_declaration ... | [comment_NL] end redefine redefine interface_member_declaration ... | [comment_NL] end redefine redefine enum_member_declaration ... | [comment_NL] end redefine redefine extern_alias_directive ... | [comment_NL] end redefine redefine using_directive ... | [comment_NL] end redefine redefine global_attribute_section ... | [comment_NL] end redefine redefine attribute_section ... | [comment_NL] end redefine redefine namespace_body [opt comments_] ... end redefine redefine class_body [opt comments_] ... end redefine redefine method_body [opt comments_] ... end redefine redefine accessor_body [opt comments_] ... end redefine redefine operator_body [opt comments_] ... end redefine redefine constructor_body [opt comments_] ... end redefine redefine static_constructor_body [opt comments_] ... end redefine redefine finalizer_body [opt comments_] ... end redefine redefine struct_body [opt comments_] ... end redefine redefine interface_body [opt comments_] ... end redefine redefine enum_body [opt comments_] ... end redefine redefine block [opt comments_] ... end redefine redefine block ... [opt comments_] end redefine redefine else_if_clause [opt comments_] ... end redefine redefine else_clause [opt comments_] ... end redefine redefine switch_block [opt comments_] ... end redefine redefine switch_label [opt comments_] ... end redefine redefine primary_expression [opt comments_] ... end redefine redefine member_name ... [opt comments_] end redefine redefine nested_statement [block] | [IN] [NL] [opt comments_] [embedded_statement] [EX] end redefine function contains Object [any] match * [any] Object end function function PrivateDelegateModifier A [interface_member_declaration] match [interface_member_declarations] B [interface_member_declarations] construct M [method_modifier *] _ [^ A] construct PublicModifiers [method_modifier *] 'public 'protected where not M [contains each PublicModifiers] end function function PrivateStructMethodModifier A [struct_member_declaration] match [struct_member_declarations] B [struct_member_declarations] construct Methods [method_modifier *] _ [^ A] construct Fields [field_modifier *] _ [^ A] construct MethodModifiers [method_modifier *] 'public 'protected construct FieldModifiers [field_modifier *] 'public 'protected where not Methods [contains each MethodModifiers] where not Fields [contains each FieldModifiers] end function function PrivateClassMethodModifier A [class_member_declaration] match [class_member_declarations] B [class_member_declarations] construct Methods [method_modifier *] _ [^ A] construct Fields [field_modifier *] _ [^ A] construct MethodModifiers [method_modifier *] 'public 'protected construct FieldModifiers [field_modifier *] 'public 'protected where not Methods [contains each MethodModifiers] where not Fields [contains each FieldModifiers] end function keys <<<<<< >>>>>> end keys compounds <<<<<< >>>>>> end compounds define Change [NL] <<<<<< [opt number] [opt stringlit] [NL] | [NL] >>>>>> [opt number] [opt stringlit] [NL] end define redefine primary_expression_modifier ... | [attr Change] end define function find_replace_primary_expression_modifier replace [program] P [ program ] import Program_Diff [program] construct S [primary_expression_modifier *] _ [ find_clones_primary_expression_modifier P Program_Diff ] construct P3 [program] P [mark_clones_primary_expression_modifier each S] by P3 end function function find_clones_primary_expression_modifier P [program] P2 [program] replace [primary_expression_modifier *] _ [ primary_expression_modifier * ] construct S [primary_expression_modifier *] _ [ ^ P ] by _ [add_if_clones_primary_expression_modifier1 P2 each S] end function function add_if_clones_primary_expression_modifier1 P2 [program] Stmt [primary_expression_modifier] construct S2 [primary_expression_modifier *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ primary_expression_modifier * ] replace [primary_expression_modifier *] StructuredClones [ primary_expression_modifier * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_primary_expression_modifier S [primary_expression_modifier] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [primary_expression_modifier] >>>>>> CloneNumber C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [primary_expression_modifier] <<<<<< CloneNumber C by P [ $ S S1 ] end function redefine class_member_declaration ... | [attr Change] end define function find_replace_class_member_declaration replace [program] P [ program ] import Program_Diff [program] construct S [class_member_declaration *] _ [ find_clones_class_member_declaration P Program_Diff ] construct P3 [program] P [mark_clones_class_member_declaration each S] by P3 end function function find_clones_class_member_declaration P [program] P2 [program] replace [class_member_declaration *] _ [ class_member_declaration * ] construct S [class_member_declaration *] _ [ ^ P ] by _ [add_if_clones_class_member_declaration1 P2 each S] end function function add_if_clones_class_member_declaration1 P2 [program] Stmt [class_member_declaration] construct S2 [class_member_declaration *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ class_member_declaration * ] replace [class_member_declaration *] StructuredClones [ class_member_declaration * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_class_member_declaration S [class_member_declaration] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [class_member_declaration] >>>>>> CloneNumber C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [class_member_declaration] <<<<<< CloneNumber C by P [ $ S S1 ] end function redefine struct_member_declaration ... | [attr Change] end define function find_replace_struct_member_declaration replace [program] P [ program ] import Program_Diff [program] construct S [struct_member_declaration *] _ [ find_clones_struct_member_declaration P Program_Diff ] construct P3 [program] P [mark_clones_struct_member_declaration each S] by P3 end function function find_clones_struct_member_declaration P [program] P2 [program] replace [struct_member_declaration *] _ [ struct_member_declaration * ] construct S [struct_member_declaration *] _ [ ^ P ] by _ [add_if_clones_struct_member_declaration1 P2 each S] end function function add_if_clones_struct_member_declaration1 P2 [program] Stmt [struct_member_declaration] construct S2 [struct_member_declaration *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ struct_member_declaration * ] replace [struct_member_declaration *] StructuredClones [ struct_member_declaration * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_struct_member_declaration S [struct_member_declaration] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [struct_member_declaration] >>>>>> CloneNumber C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [struct_member_declaration] <<<<<< CloneNumber C by P [ $ S S1 ] end function redefine interface_member_declaration ... | [attr Change] end define function find_replace_interface_member_declaration replace [program] P [ program ] import Program_Diff [program] construct S [interface_member_declaration *] _ [ find_clones_interface_member_declaration P Program_Diff ] construct P3 [program] P [mark_clones_interface_member_declaration each S] by P3 end function function find_clones_interface_member_declaration P [program] P2 [program] replace [interface_member_declaration *] _ [ interface_member_declaration * ] construct S [interface_member_declaration *] _ [ ^ P ] by _ [add_if_clones_interface_member_declaration1 P2 each S] end function function add_if_clones_interface_member_declaration1 P2 [program] Stmt [interface_member_declaration] construct S2 [interface_member_declaration *] _ [ ^ P2 ] deconstruct * S2 Stmt Rest [ interface_member_declaration * ] replace [interface_member_declaration *] StructuredClones [ interface_member_declaration * ] deconstruct not * StructuredClones C [attr Change] by StructuredClones [ . Stmt ] end function function mark_clones_interface_member_declaration S [interface_member_declaration] import CloneNumber [number] import Program_Diff [program] export CloneNumber CloneNumber [ + 1 ] construct C [stringlit] _ [ quote S ] where not C [= ""] construct S2 [interface_member_declaration] >>>>>> CloneNumber C export Program_Diff Program_Diff [ $ S S2 ] replace [program] P [ program ] construct S1 [interface_member_declaration] <<<<<< CloneNumber C by P [ $ S S1 ] end function rule normalise_list_primary_no_array_creation_expression_primary_expression_modifier replace [repeat primary_expression_modifier] N1 [primary_expression_modifier] N2 [primary_expression_modifier] Rest [repeat primary_expression_modifier] construct T1 [stringlit] _ [ quote N1 ] construct T2 [stringlit] _ [ quote N2 ] where T1 [> T2] by N2 N1 Rest end rule function normalise_ignore_by1_PrivateClassMethodModifier_class_member_declarations_class_member_declaration1 E1 [ class_member_declarations] N1 [class_member_declaration] replace [class_member_declaration *] Seq [class_member_declaration *] where not E1 [PrivateClassMethodModifier N1] by Seq [ . N1 ] end function function normalise_ignore_by2_PrivateClassMethodModifier_class_member_declarations_class_member_declaration1 E1 [ class_member_declarations] N1 [class_member_declaration] replace [class_member_declaration *] Seq [class_member_declaration *] where E1 [PrivateClassMethodModifier N1] by Seq end function function normalise_ignore_by3_PrivateClassMethodModifier_class_member_declarations_class_member_declaration1 E1 [ class_member_declarations] replace [class_member_declarations *] Seq [class_member_declarations *] deconstruct E1 N1 [repeat class_member_declaration *] construct N2 [class_member_declaration *] _ [normalise_ignore_by1_PrivateClassMethodModifier_class_member_declarations_class_member_declaration1 E1 each N1] [normalise_ignore_by2_PrivateClassMethodModifier_class_member_declarations_class_member_declaration1 E1 each N1] construct E2 [class_member_declarations] N2 by Seq [ . E2 ] end function function normalise_ignore_by4_PrivateClassMethodModifier_class_member_declarations_class_member_declaration1 replace [program] P1 [ program ] construct List1 [class_member_declarations *] _ [ ^ P1 ] construct List2 [class_member_declarations *] _ [normalise_ignore_by3_PrivateClassMethodModifier_class_member_declarations_class_member_declaration1 each List1] construct P2 [program] P1 [$ each List1 List2] by P2 end function function normalise_preferred_tokens_method_body_block1 B [method_body] replace [method_body *] A [method_body *] deconstruct not B '; construct B1 [method_body] '; by _ [ . A ] [ . B1 ] end function function normalise_preferred_replace_method_body_block1 replace [program] Prg [ program ] construct A [method_body *] _ [ ^ Prg ] construct A1 [method_body *] _ [normalise_preferred_tokens_method_body_block1 each A] by Prg [$ each A A1] end function function normalise_ignore_by1_PrivateStructMethodModifier_struct_member_declarations_struct_member_declaration1 E1 [ struct_member_declarations] N1 [struct_member_declaration] replace [struct_member_declaration *] Seq [struct_member_declaration *] where not E1 [PrivateStructMethodModifier N1] by Seq [ . N1 ] end function function normalise_ignore_by2_PrivateStructMethodModifier_struct_member_declarations_struct_member_declaration1 E1 [ struct_member_declarations] N1 [struct_member_declaration] replace [struct_member_declaration *] Seq [struct_member_declaration *] where E1 [PrivateStructMethodModifier N1] by Seq end function function normalise_ignore_by3_PrivateStructMethodModifier_struct_member_declarations_struct_member_declaration1 E1 [ struct_member_declarations] replace [struct_member_declarations *] Seq [struct_member_declarations *] deconstruct E1 N1 [repeat struct_member_declaration +] construct N2 [struct_member_declaration *] _ [normalise_ignore_by1_PrivateStructMethodModifier_struct_member_declarations_struct_member_declaration1 E1 each N1 ] [normalise_ignore_by2_PrivateStructMethodModifier_struct_member_declarations_struct_member_declaration1 E1 each N1] construct E2 [struct_member_declarations] N2 by Seq [ . E2 ] end function function normalise_ignore_by4_PrivateStructMethodModifier_struct_member_declarations_struct_member_declaration1 replace [program] P1 [ program ] construct List1 [struct_member_declarations *] _ [ ^ P1 ] construct List2 [struct_member_declarations *] _ [normalise_ignore_by3_PrivateStructMethodModifier_struct_member_declarations_struct_member_declaration1 each List1 ] construct P2 [program] P1 [$ each List1 List2] by P2 end function function normalise_ignore_by1_PrivateDelegateModifier_interface_member_declarations_interface_member_declaration1 E1 [ interface_member_declarations] N1 [interface_member_declaration] replace [interface_member_declaration *] Seq [interface_member_declaration *] where not E1 [PrivateDelegateModifier N1] by Seq [ . N1 ] end function function normalise_ignore_by2_PrivateDelegateModifier_interface_member_declarations_interface_member_declaration1 E1 [ interface_member_declarations] N1 [interface_member_declaration] replace [interface_member_declaration *] Seq [interface_member_declaration *] where E1 [PrivateDelegateModifier N1] by Seq end function function normalise_ignore_by3_PrivateDelegateModifier_interface_member_declarations_interface_member_declaration1 E1 [ interface_member_declarations] replace [interface_member_declarations *] Seq [interface_member_declarations *] deconstruct E1 N1 [repeat interface_member_declaration +] construct N2 [interface_member_declaration *] _ [normalise_ignore_by1_PrivateDelegateModifier_interface_member_declarations_interface_member_declaration1 E1 each N1] [ normalise_ignore_by2_PrivateDelegateModifier_interface_member_declarations_interface_member_declaration1 E1 each N1] construct E2 [interface_member_declarations] N2 by Seq [ . E2 ] end function function normalise_ignore_by4_PrivateDelegateModifier_interface_member_declarations_interface_member_declaration1 replace [program] P1 [ program ] construct List1 [interface_member_declarations *] _ [ ^ P1 ] construct List2 [interface_member_declarations *] _ [normalise_ignore_by3_PrivateDelegateModifier_interface_member_declarations_interface_member_declaration1 each List1] construct P2 [program] P1 [$ each List1 List2] by P2 end function function program_normalise replace [program] Prg [ program ] by Prg [ normalise_ignore_by4_PrivateClassMethodModifier_class_member_declarations_class_member_declaration1 ] [ normalise_ignore_by4_PrivateStructMethodModifier_struct_member_declarations_struct_member_declaration1 ] [ normalise_ignore_by4_PrivateDelegateModifier_interface_member_declarations_interface_member_declaration1 ] [ normalise_preferred_replace_method_body_block1 ] [ normalise_list_primary_no_array_creation_expression_primary_expression_modifier ] end function function program_remove_clone replace [program] Prg [ program ] export CloneNumber [number] 0 import TXLargs [repeat stringlit] deconstruct * TXLargs "-diff" Filename [ stringlit ] export CloneNumber 99 construct P2 [program] _ [ read Filename ] [ program_normalise ] export Program_Diff [program] P2 by Prg [ find_replace_primary_expression_modifier ] [ find_replace_class_member_declaration ] [ find_replace_struct_member_declaration ] [ find_replace_interface_member_declaration ] end function redefine program ... | [empty] | [attr number] end define function print_diff_1 replace [program] Prg [ program ] import TXLinput [stringlit] construct Str_TmpFile [stringlit] TXLinput [ + ".tmp" ] construct Str_RmTmpFile [stringlit] _ [ + "/bin/rm -f " ] [ + Str_TmpFile ] construct P2 [program] Prg [ write Str_TmpFile ] [ read Str_TmpFile ] [ system Str_RmTmpFile ] construct S_Diff [stringlit] _ [ quote P2 ] where not S_Diff [= ""] by Prg end function function print_diff_2 replace [program] Prg [ program ] import TXLinput [stringlit] construct Str_TmpFile [stringlit] TXLinput [ + ".tmp" ] construct Str_RmTmpFile [stringlit] _ [ + "/bin/rm -f " ] [ + Str_TmpFile ] construct P2 [program] Prg [ program_normalise ] [ write Str_TmpFile ] [ read Str_TmpFile ] [ system Str_RmTmpFile ] construct S_Diff [stringlit] _ [ quote P2 ] where S_Diff [= ""] by _ end function function print_diff replace [program] P_diff [ program ] import CloneNumber [number] import Program_Diff [program] where CloneNumber [> 0] construct P_Clone [program] CloneNumber [ - 99 ] construct P_Left [program] P_diff [ print_diff_1 ] [ print_diff_2 ] [ printattr ] construct P_Right [program] Program_Diff [ print_diff_1 ] [ print_diff_2 ] [ printattr ] by P_Clone end function function main replace [program] Prg [ program ] export Program_Diff [program] _ export Program [program] Prg by Prg [ program_normalise ] [ program_remove_clone ] [ print_diff ] end function