java15.cup
来自「tiger编译器的Java实现」· CUP 代码 · 共 1,264 行 · 第 1/3 页
CUP
1,264 行
class_declaration ::= modifiers_opt CLASS IDENTIFIER type_parameters_opt super_opt interfaces_opt class_body ;super ::= EXTENDS class_type ;super_opt ::= | super ;interfaces ::= IMPLEMENTS interface_type_list ;interfaces_opt::= | interfaces ;interface_type_list ::= interface_type | interface_type_list COMMA interface_type ;class_body ::= LBRACE class_body_declarations_opt RBRACE ;class_body_declarations_opt ::= | class_body_declarations ;class_body_declarations ::= class_body_declaration | class_body_declarations class_body_declaration ;class_body_declaration ::= class_member_declaration | static_initializer | constructor_declaration | block ;class_member_declaration ::= field_declaration | method_declaration /* repeat the prod for 'class_declaration' here: */ | modifiers_opt CLASS IDENTIFIER type_parameters_opt super_opt interfaces_opt class_body | interface_declaration | SEMICOLON ;// 19.8.2) Field Declarationsfield_declaration ::= modifiers_opt type variable_declarators SEMICOLON ;variable_declarators ::= variable_declarator | variable_declarators COMMA variable_declarator ;variable_declarator ::= variable_declarator_id | variable_declarator_id EQ variable_initializer ;variable_declarator_id ::= IDENTIFIER | variable_declarator_id LBRACK RBRACK ;variable_initializer ::= expression_l | array_initializer ;// 19.8.3) Method Declarationsmethod_declaration ::= method_header method_body ;method_header ::= // have to expand type_parameters_opt here so that we don't // force an early decision of whether this is a field_declaration // or a method_declaration (the type_parameters_opt would have to // be reduced when we see the 'type' if this was a method declaration, // but it might still turn out to be a field declaration). // also, we can't rely on the special PLT token here, as the LT // doesn't follow a IDENTIFIER modifiers_opt type method_declarator throws_opt | modifiers_opt LT type_parameter_list_1 type method_declarator throws_opt | modifiers_opt VOID method_declarator throws_opt | modifiers_opt LT type_parameter_list_1 VOID method_declarator throws_opt ;method_declarator ::= IDENTIFIER LPAREN formal_parameter_list_opt RPAREN | method_declarator LBRACK RBRACK // deprecated // be careful; the above production also allows 'void foo() []' ;formal_parameter_list_opt ::= | formal_parameter_list ;formal_parameter_list ::= formal_parameter | formal_parameter_list COMMA formal_parameter ;formal_parameter ::= type variable_declarator_id | FINAL type variable_declarator_id ;throws_opt ::= | throws ;throws ::= THROWS class_type_list ;class_type_list ::= class_type | class_type_list COMMA class_type ;method_body ::= block | SEMICOLON ;// 19.8.4) Static Initializersstatic_initializer ::= STATIC block ;// 19.8.5) Constructor Declarationsconstructor_declaration ::= modifiers_opt constructor_declarator throws_opt constructor_body | modifiers_opt LT type_parameter_list_1 constructor_declarator throws_opt constructor_body ;constructor_declarator ::= simple_name LPAREN formal_parameter_list_opt RPAREN ;constructor_body ::= LBRACE explicit_constructor_invocation block_statements RBRACE | LBRACE explicit_constructor_invocation RBRACE | LBRACE block_statements RBRACE | LBRACE RBRACE ;explicit_constructor_invocation ::= THIS LPAREN argument_list_opt RPAREN SEMICOLON | SUPER LPAREN argument_list_opt RPAREN SEMICOLON | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON ;// 19.9) Interfaces// 19.9.1) Interface Declarationsinterface_declaration ::= modifiers_opt INTERFACE IDENTIFIER type_parameters_opt extends_interfaces_opt interface_body ;extends_interfaces_opt ::= | extends_interfaces ;extends_interfaces ::= EXTENDS interface_type | extends_interfaces COMMA interface_type ;interface_body ::= LBRACE interface_member_declarations_opt RBRACE ;interface_member_declarations_opt ::= | interface_member_declarations ;interface_member_declarations ::= interface_member_declaration | interface_member_declarations interface_member_declaration ;interface_member_declaration ::= constant_declaration | abstract_method_declaration | class_declaration | interface_declaration ;constant_declaration ::= field_declaration // need to semantically check that modifiers of field declaration // include only PUBIC, STATIC, or FINAL. Other modifiers are // disallowed. ;abstract_method_declaration ::= method_header SEMICOLON ;// 19.10) Arraysarray_initializer ::= LBRACE variable_initializers COMMA RBRACE | LBRACE variable_initializers RBRACE | LBRACE COMMA RBRACE | LBRACE RBRACE ;variable_initializers ::= variable_initializer | variable_initializers COMMA variable_initializer ;// 19.11) Blocks and Statementsblock ::= LBRACE block_statements_opt RBRACE ;block_statements_opt ::= | block_statements ;block_statements ::= block_statement | block_statements block_statement ;block_statement ::= local_variable_declaration_statement | statement | class_declaration | interface_declaration ;local_variable_declaration_statement ::= local_variable_declaration SEMICOLON ;local_variable_declaration ::= type variable_declarators | FINAL type variable_declarators ;statement ::= statement_without_trailing_substatement | labeled_statement | if_then_statement | if_then_else_statement | while_statement | for_statement ;statement_no_short_if ::= statement_without_trailing_substatement | labeled_statement_no_short_if | if_then_else_statement_no_short_if | while_statement_no_short_if | for_statement_no_short_if ;statement_without_trailing_substatement ::= block | empty_statement | expression_statement | switch_statement | do_statement | break_statement | continue_statement | return_statement | synchronized_statement | throw_statement | try_statement | assert_statement ;empty_statement ::= SEMICOLON ;labeled_statement ::= IDENTIFIER COLON statement ;labeled_statement_no_short_if ::= IDENTIFIER COLON statement_no_short_if ;expression_statement ::= statement_expression SEMICOLON ;statement_expression ::= assignment | preincrement_expression | predecrement_expression | postincrement_expression | postdecrement_expression | method_invocation | class_instance_creation_expression ;if_then_statement ::= IF LPAREN expression_nn RPAREN statement | IF LPAREN name RPAREN statement ;if_then_else_statement ::= IF LPAREN expression_nn RPAREN statement_no_short_if ELSE statement | IF LPAREN name RPAREN statement_no_short_if ELSE statement ;if_then_else_statement_no_short_if ::= IF LPAREN expression_nn RPAREN statement_no_short_if ELSE statement_no_short_if | IF LPAREN name RPAREN statement_no_short_if ELSE statement_no_short_if ;switch_statement ::= SWITCH LPAREN expression_nn RPAREN switch_block | SWITCH LPAREN name RPAREN switch_block ;switch_block ::= LBRACE switch_block_statement_groups switch_labels RBRACE | LBRACE switch_block_statement_groups RBRACE | LBRACE switch_labels RBRACE | LBRACE RBRACE ;switch_block_statement_groups ::= switch_block_statement_group | switch_block_statement_groups switch_block_statement_group ;switch_block_statement_group ::= switch_labels block_statements ;switch_labels ::= switch_label | switch_labels switch_label ;switch_label ::= CASE constant_expression_nn COLON | CASE name COLON | DEFAULT COLON ;while_statement ::= WHILE LPAREN expression_nn RPAREN statement | WHILE LPAREN name RPAREN statement ;while_statement_no_short_if ::= WHILE LPAREN expression_nn RPAREN statement_no_short_if | WHILE LPAREN name RPAREN statement_no_short_if ;do_statement ::= DO statement WHILE LPAREN expression_nn RPAREN SEMICOLON | DO statement WHILE LPAREN name RPAREN SEMICOLON ;for_statement ::= FOR LPAREN for_init_opt SEMICOLON expression_nn_opt SEMICOLON for_update_opt RPAREN statement | FOR LPAREN for_init_opt SEMICOLON name SEMICOLON for_update_opt RPAREN statement ;for_statement_no_short_if ::= FOR LPAREN for_init_opt SEMICOLON expression_nn_opt SEMICOLON for_update_opt RPAREN statement_no_short_if | FOR LPAREN for_init_opt SEMICOLON name SEMICOLON for_update_opt RPAREN statement_no_short_if ;for_init_opt ::= | for_init ;for_init ::= statement_expression_list | local_variable_declaration ;for_update_opt ::= | for_update ;for_update ::= statement_expression_list ;statement_expression_list ::= statement_expression_l | statement_expression_list COMMA statement_expression_l ;identifier_opt ::= | IDENTIFIER ;break_statement ::= BREAK identifier_opt SEMICOLON ;continue_statement ::= CONTINUE identifier_opt SEMICOLON ;return_statement ::= RETURN expression_nn_opt SEMICOLON | RETURN name SEMICOLON ;throw_statement ::= THROW expression_nn SEMICOLON | THROW name SEMICOLON ;synchronized_statement ::= SYNCHRONIZED LPAREN expression_nn RPAREN block | SYNCHRONIZED LPAREN name RPAREN block ;try_statement ::= TRY block catches | TRY block catches_opt finally ;catches_opt ::= | catches ;catches ::= catch_clause | catches catch_clause ;catch_clause ::= CATCH LPAREN formal_parameter RPAREN block ;finally ::= FINALLY block ;assert_statement ::= ASSERT expression_nn SEMICOLON | ASSERT expression_nn COLON expression_nn SEMICOLON | ASSERT name SEMICOLON | ASSERT name COLON expression_nn SEMICOLON | ASSERT expression_nn COLON name SEMICOLON | ASSERT name COLON name SEMICOLON ;// 19.12) Expressionsprimary ::= primary_no_new_array | array_creation_expression ;primary_no_new_array ::= literal | THIS | LPAREN name RPAREN | LPAREN expression_nn RPAREN | class_instance_creation_expression | field_access | method_invocation | array_access | name DOT THIS | VOID DOT CLASS // "Type DOT CLASS", but expanded | primitive_type DOT CLASS | name DOT CLASS// this production *might* be valid, but introduces conflicts.// | name type_arguments DOT CLASS | primitive_type dims DOT CLASS | name dims DOT CLASS// this production *might* be valid, but introduces conflicts.// | name type_arguments dims DOT CLASS ;class_instance_creation_expression ::= // actually only class_type is valid in the next production, but // that would lead to a grammar conflict. NEW class_or_interface_type LPAREN argument_list_opt RPAREN | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body | primary DOT NEW IDENTIFIER type_arguments_opt
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?