| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954 |
- /* yacc grammar for JAVA language */
- /* print with psf -p 10 -L50 -l 50 -w -E j.y > xx */
- %{
- #define REDUCE /* will display the reduce rules */
- #undef REDUCE
- #define PRNT_SYM
- #undef PRNT_SYM
- #define YYDEBUG 1
- #include <stdio.h>
- extern FILE *yyin;
- extern int yylineno;
- extern int yydebug;
- extern char yytext[];
- #ifdef REDUCE
- # define reduce(a) printf("%s\n",a)
- #else
- # define reduce(a)
- #endif
- #define YYSTYPE PyObject *
- %}
- /* Things defined here have to match the order of what's in the
- binop_lookup table. */
- %token PLUS_TOKEN MINUS_TOKEN MUL_TOKEN DIV_TOKEN MOD_TOKEN
- %token SHL_TOKEN SHR_TOKEN SAR_TOKEN
- %token AND_TOKEN XOR_TOKEN OR_TOKEN
- %token LOGICAL_AND_TOKEN LOGICAL_OR_TOKEN
- %token EQ_TOKEN NE_OP_TOKEN GREATER_TOKEN GE_TOKEN LESS_TOKEN LE_TOKEN
- /* This maps to the same binop_lookup entry than the token above */
- %token ADD_ASSIGN_TOKEN SUB_ASSIGN_TOKEN MUL_ASSIGN_TOKEN DIV_ASSIGN_TOKEN
- %token MOD_ASSIGN_TOKEN
- %token SHL_ASSIGN_TOKEN SHR_ASSIGN_TOKEN SAR_ASSIGN_TOKEN
- %token AND_ASSIGN_TOKEN XOR_ASSIGN_TOKEN OR_ASSIGN_TOKEN
- /* Modifier TOKEN have to be kept in this order. Don't scramble it */
- %token PUBLIC_TOKEN PRIVATE_TOKEN PROTECTED_TOKEN
- %token STATIC_TOKEN FINAL_TOKEN SYNCHRONIZED_TOKEN
- %token VOLATILE_TOKEN TRANSIENT_TOKEN NATIVE_TOKEN
- %token PAD_TOKEN ABSTRACT_TOKEN MODIFIER_TOKEN
- %token STRICT_TOKEN STRICTFP_TOKEN
- /* Keep those two in order, too */
- %token DEC_TOKEN INC_TOKEN
- /* From now one, things can be in any order */
- %token DEFAULT_TOKEN IF_TOKEN THROW_TOKEN
- %token BOOLEAN_TOKEN DO_TOKEN IMPLEMENTS_TOKEN
- %token THROWS_TOKEN BREAK_TOKEN IMPORT_TOKEN
- %token ELSE_TOKEN INSTANCEOF_TOKEN RETURN_TOKEN
- %token VOID_TOKEN CATCH_TOKEN INTERFACE_TOKEN
- %token CASE_TOKEN EXTENDS_TOKEN FINALLY_TOKEN
- %token SUPER_TOKEN WHILE_TOKEN CLASS_TOKEN
- %token SWITCH_TOKEN CONST_TOKEN TRY_TOKEN
- %token FOR_TOKEN NEW_TOKEN CONTINUE_TOKEN
- %token GOTO_TOKEN PACKAGE_TOKEN THIS_TOKEN
- %token ASSERT_TOKEN
- %token BYTE_TOKEN SHORT_TOKEN INT_TOKEN LONG_TOKEN
- %token CHAR_TOKEN
- %token FLOAT_TOKEN DOUBLE_TOKEN
- %token ID_TOKEN
- %token CONDITIONAL_TOKEN COLON_TOKEN TILDE_TOKEN NOT_TOKEN
- %token ASSIGN_ANY_TOKEN ASSIGNS_TOKEN
- %token OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN SEMICOLON_TOKEN COMMA_TOKEN PERIOD_TOKEN
- %token INTEGER_LITERAL_TOKEN FLOATING_POINT_LITERAL_TOKEN BOOLEAN_LITERAL_TOKEN STRING_LITERAL_TOKEN
- %token CHARACTER_LITERAL_TOKEN NULL_TOKEN
- %right SHL_ASSIGN_TOKEN SAR_ASSIGN_TOKEN AND_ASSIGN_TOKEN OR_ASSIGN_TOKEN XOR_ASSIGN_TOKEN
- ASSIGNS_TOKEN ADD_ASSIGN_TOKEN SUB_ASSIGN_TOKEN MUL_ASSIGN_TOKEN DIV_ASSIGN_TOKEN MOD_ASSIGN_TOKEN
- %left LOGICAL_OR_TOKEN
- %left LOGICAL_AND_TOKEN
- %left OR_TOKEN
- %left XOR_TOKEN
- %left AND_TOKEN
- %left RELATIVEQEUAL_TOKEN NE_OP_TOKEN
- %left GREATER_TOKEN LESS_TOKEN GE_TOKEN LE_TOKEN
- %left SHL_TOKEN SAR_TOKEN SHR_TOKEN
- %left PLUS_TOKEN MINUS_TOKEN
- %left MUL_TOKEN DIV_TOKEN MOD_TOKEN
- %nonassoc NOT_TOKEN TILDE_TOKEN
- %start goal
- %%
- goal
- : compilation_unit
- ;
- literal
- : INTEGER_LITERAL_TOKEN
- | FLOATING_POINT_LITERAL_TOKEN
- | BOOLEAN_LITERAL_TOKEN
- | CHARACTER_LITERAL_TOKEN
- | STRING_LITERAL_TOKEN
- | NULL_TOKEN
- ;
- type
- : primitive_type
- | reference_type
- ;
- primitive_type
- : INT_TOKEN
- | LONG_TOKEN
- | FLOAT_TOKEN
- | DOUBLE_TOKEN
- | BOOLEAN_TOKEN
- | BYTE_TOKEN
- | CHAR_TOKEN
- | SHORT_TOKEN
- ;
- reference_type
- : class_or_interface_type
- | array_type
- ;
- class_or_interface_type
- : name
- ;
- class_type
- : class_or_interface_type
- ;
- interface_type
- : class_or_interface_type
- ;
- array_type
- : primitive_type dims
- | name dims
- ;
- name
- : simple_name
- | qualified_name
- ;
- simple_name
- : identifier
- ;
- qualified_name
- : name PERIOD_TOKEN identifier
- ;
- identifier
- : ID_TOKEN
- ;
- compilation_unit
- :
- | package_declaration
- | import_declarations
- | type_declarations
- | package_declaration import_declarations
- | package_declaration type_declarations
- | import_declarations type_declarations
- | package_declaration import_declarations type_declarations
- ;
- import_declarations
- : import_declaration
- | import_declarations import_declaration
- ;
- type_declarations
- : type_declaration
- | type_declarations type_declaration
- ;
- package_declaration
- : PACKAGE_TOKEN name SEMICOLON_TOKEN
- ;
- import_declaration
- : single_type_import_declaration
- | type_import_on_demand_declaration
- ;
- single_type_import_declaration
- : IMPORT_TOKEN name SEMICOLON_TOKEN
- ;
- type_import_on_demand_declaration
- : IMPORT_TOKEN name PERIOD_TOKEN MUL_TOKEN SEMICOLON_TOKEN
- ;
- type_declaration
- : class_declaration
- | interface_declaration
- | empty_statement
- ;
- modifiers
- : modifier
- | modifiers modifier
- ;
- modifier
- : STATIC_TOKEN
- | PUBLIC_TOKEN
- | PROTECTED_TOKEN
- | PRIVATE_TOKEN
- | ABSTRACT_TOKEN
- | FINAL_TOKEN
- | NATIVE_TOKEN
- | SYNCHRONIZED_TOKEN
- | TRANSIENT_TOKEN
- | VOLATILE_TOKEN
- ;
- class_declaration
- : modifiers CLASS_TOKEN identifier super interfaces class_body
- | CLASS_TOKEN identifier super interfaces class_body
- ;
- super
- :
- | EXTENDS_TOKEN class_type
- ;
- interfaces
- :
- | IMPLEMENTS_TOKEN interface_type_list
- ;
- interface_type_list
- : interface_type
- | interface_type_list COMMA_TOKEN interface_type
- ;
- class_body
- : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN class_body_declarations CLOSE_BRACE_TOKEN
- ;
- 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
- | class_declaration
- | interface_declaration
- | empty_statement
- ;
- field_declaration
- : type variable_declarators SEMICOLON_TOKEN
- | modifiers type variable_declarators SEMICOLON_TOKEN
- ;
- variable_declarators
- : variable_declarator
- | variable_declarators COMMA_TOKEN variable_declarator
- ;
- variable_declarator
- : variable_declarator_id
- | variable_declarator_id ASSIGNS_TOKEN variable_initializer
- ;
- variable_declarator_id
- : identifier
- | variable_declarator_id OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN
- ;
- variable_initializer
- : expression
- | array_initializer
- ;
- method_declaration
- : method_header method_body
- ;
- method_header
- : type method_declarator throws
- | VOID_TOKEN method_declarator throws
- | modifiers type method_declarator throws
- | modifiers VOID_TOKEN method_declarator throws
- ;
- method_declarator
- : identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
- | identifier OPEN_PAREN_TOKEN formal_parameter_list CLOSE_PAREN_TOKEN
- | method_declarator OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN
- ;
- formal_parameter_list
- : formal_parameter
- | formal_parameter_list COMMA_TOKEN formal_parameter
- ;
- formal_parameter
- : type variable_declarator_id
- | modifiers type variable_declarator_id
- ;
- throws
- :
- | THROWS_TOKEN class_type_list
- ;
- class_type_list
- : class_type
- | class_type_list COMMA_TOKEN class_type
- ;
- method_body
- : block
- | SEMICOLON_TOKEN
- ;
- static_initializer
- : static block
- ;
- static
- : modifiers
- ;
- constructor_declaration
- : constructor_header constructor_body
- ;
- constructor_header
- : constructor_declarator throws
- | modifiers constructor_declarator throws
- ;
- constructor_declarator
- : simple_name OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
- | simple_name OPEN_PAREN_TOKEN formal_parameter_list CLOSE_PAREN_TOKEN
- ;
- constructor_body
- : block_begin constructor_block_end
- | block_begin explicit_constructor_invocation constructor_block_end
- | block_begin block_statements constructor_block_end
- | block_begin explicit_constructor_invocation block_statements constructor_block_end
- ;
- constructor_block_end
- : block_end
- ;
- block_begin
- : OPEN_BRACE_TOKEN
- ;
- block_end
- : CLOSE_BRACE_TOKEN
- ;
- explicit_constructor_invocation
- : this_or_super OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
- | this_or_super OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
- | name PERIOD_TOKEN SUPER_TOKEN OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
- | name PERIOD_TOKEN SUPER_TOKEN OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
- ;
- this_or_super
- : THIS_TOKEN
- | SUPER_TOKEN
- ;
- interface_declaration
- : INTERFACE_TOKEN identifier interface_body
- | modifiers INTERFACE_TOKEN identifier interface_body
- | INTERFACE_TOKEN identifier extends_interfaces interface_body
- | modifiers INTERFACE_TOKEN identifier extends_interfaces interface_body
- ;
- extends_interfaces
- : EXTENDS_TOKEN interface_type
- | extends_interfaces COMMA_TOKEN interface_type
- ;
- interface_body
- : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN interface_member_declarations CLOSE_BRACE_TOKEN
- ;
- 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
- ;
- abstract_method_declaration
- : method_header SEMICOLON_TOKEN
- ;
- array_initializer
- : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN COMMA_TOKEN CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN variable_initializers CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN variable_initializers COMMA_TOKEN CLOSE_BRACE_TOKEN
- ;
- variable_initializers
- : variable_initializer
- | variable_initializers COMMA_TOKEN variable_initializer
- ;
- block
- : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN block_statements CLOSE_BRACE_TOKEN
- ;
- block_statements
- : block_statement
- | block_statements block_statement
- ;
- block_statement
- : local_variable_declaration_statement
- | statement
- | class_declaration
- ;
- local_variable_declaration_statement
- : local_variable_declaration SEMICOLON_TOKEN
- ;
- local_variable_declaration
- : type variable_declarators
- | modifiers type variable_declarators
- ;
- statement
- : statement_without_trailing_substatement
- | labeled_statement
- | if_then_statement
- | if_then_else_statement
- | while_statement
- | for_statement
- ;
- statement_nsi
- : statement_without_trailing_substatement
- | labeled_statement_nsi
- | if_then_else_statement_nsi
- | while_statement_nsi
- | for_statement_nsi
- ;
- 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_TOKEN
- ;
- label_decl
- : identifier COLON_TOKEN
- ;
- labeled_statement
- : label_decl statement
- ;
- labeled_statement_nsi
- : label_decl statement_nsi
- ;
- expression_statement
- : statement_expression SEMICOLON_TOKEN
- | SYNCHRONIZED_TOKEN OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN block
- ;
- statement_expression
- : assignment
- | primary
- | pre_increment_expression
- | pre_decrement_expression
- | post_increment_expression
- | post_decrement_expression
- | method_invocation
- | class_instance_creation_expression
- ;
- if_then_statement
- : IF_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN statement
- ;
- if_then_else_statement
- : IF_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN statement_nsi ELSE_TOKEN statement
- ;
- if_then_else_statement_nsi
- : IF_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN statement_nsi ELSE_TOKEN statement_nsi
- ;
- switch_statement
- : switch_expression switch_block
- ;
- switch_expression
- : SWITCH_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN
- ;
- switch_block
- : OPEN_BRACE_TOKEN CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN switch_labels CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN switch_block_statement_groups CLOSE_BRACE_TOKEN
- | OPEN_BRACE_TOKEN switch_block_statement_groups switch_labels CLOSE_BRACE_TOKEN
- ;
- 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_TOKEN constant_expression COLON_TOKEN
- | DEFAULT_TOKEN COLON_TOKEN
- ;
- while_expression
- : WHILE_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN
- ;
- while_statement
- : while_expression statement
- ;
- while_statement_nsi
- : while_expression statement_nsi
- ;
- do_statement_begin
- : DO_TOKEN
- ;
- do_statement
- : do_statement_begin statement WHILE_TOKEN OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN SEMICOLON_TOKEN
- ;
- for_statement
- : for_begin SEMICOLON_TOKEN expression SEMICOLON_TOKEN for_update CLOSE_PAREN_TOKEN statement
- | for_begin SEMICOLON_TOKEN SEMICOLON_TOKEN for_update CLOSE_PAREN_TOKEN statement
- ;
- for_statement_nsi
- : for_begin SEMICOLON_TOKEN expression SEMICOLON_TOKEN for_update CLOSE_PAREN_TOKEN statement_nsi
- | for_begin SEMICOLON_TOKEN SEMICOLON_TOKEN for_update CLOSE_PAREN_TOKEN statement_nsi
- ;
- for_header
- : FOR_TOKEN OPEN_PAREN_TOKEN
- ;
- for_begin
- : for_header for_init
- ;
- for_init
- :
- | statement_expression_list
- | local_variable_declaration
- ;
- for_update
- :
- | statement_expression_list
- ;
- statement_expression_list
- : statement_expression
- | statement_expression_list COMMA_TOKEN statement_expression
- ;
- break_statement
- : BREAK_TOKEN SEMICOLON_TOKEN
- | BREAK_TOKEN identifier SEMICOLON_TOKEN
- ;
- continue_statement
- : CONTINUE_TOKEN SEMICOLON_TOKEN
- | CONTINUE_TOKEN identifier SEMICOLON_TOKEN
- ;
- return_statement
- : RETURN_TOKEN SEMICOLON_TOKEN
- | RETURN_TOKEN expression SEMICOLON_TOKEN
- ;
- throw_statement
- : THROW_TOKEN expression SEMICOLON_TOKEN
- ;
- assert_statement
- : ASSERT_TOKEN expression COLON_TOKEN expression SEMICOLON_TOKEN
- | ASSERT_TOKEN expression SEMICOLON_TOKEN
- | ASSERT_TOKEN error
- | ASSERT_TOKEN expression error
- ;
- synchronized_statement
- : synchronized OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN block
- | synchronized OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN error
- ;
- synchronized
- : MODIFIER_TOKEN
- ;
- try_statement
- : TRY_TOKEN block catches
- | TRY_TOKEN block finally
- | TRY_TOKEN block catches finally
- ;
- catches
- : catch_clause
- | catches catch_clause
- ;
- catch_clause
- : CATCH_TOKEN OPEN_PAREN_TOKEN formal_parameter CLOSE_PAREN_TOKEN block
- ;
- finally
- : FINALLY_TOKEN block
- ;
- primary
- : primary_no_new_array
- | array_creation_expression
- ;
- primary_no_new_array
- : literal
- | THIS_TOKEN
- | OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN
- | class_instance_creation_expression
- | field_access
- | method_invocation
- | array_access
- | type_literals
- | name PERIOD_TOKEN THIS_TOKEN
- ;
- type_literals
- : name PERIOD_TOKEN CLASS_TOKEN
- | array_type PERIOD_TOKEN CLASS_TOKEN
- | primitive_type PERIOD_TOKEN CLASS_TOKEN
- | VOID_TOKEN PERIOD_TOKEN CLASS_TOKEN
- ;
- class_instance_creation_expression
- : NEW_TOKEN class_type OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
- | NEW_TOKEN class_type OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
- | anonymous_class_creation
- | something_dot_new identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
- | something_dot_new identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN class_body
- | something_dot_new identifier OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
- | something_dot_new identifier OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN class_body
- ;
- anonymous_class_creation
- : NEW_TOKEN class_type OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN class_body
- | NEW_TOKEN class_type OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN class_body
- ;
- something_dot_new
- : name PERIOD_TOKEN NEW_TOKEN
- | primary PERIOD_TOKEN NEW_TOKEN
- ;
- argument_list
- : expression
- | argument_list COMMA_TOKEN expression
- | argument_list COMMA_TOKEN error
- ;
- array_creation_expression
- : NEW_TOKEN primitive_type dim_exprs
- | NEW_TOKEN class_or_interface_type dim_exprs
- | NEW_TOKEN primitive_type dim_exprs dims
- | NEW_TOKEN class_or_interface_type dim_exprs dims
- | NEW_TOKEN class_or_interface_type dims array_initializer
- | NEW_TOKEN primitive_type dims array_initializer
- ;
- dim_exprs
- : dim_expr
- | dim_exprs dim_expr
- ;
- dim_expr
- : OPEN_BRACKET_TOKEN expression CLOSE_BRACKET_TOKEN
- ;
- dims
- : OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN
- | dims OPEN_BRACKET_TOKEN CLOSE_BRACKET_TOKEN
- ;
- field_access
- : primary PERIOD_TOKEN identifier
- | SUPER_TOKEN PERIOD_TOKEN identifier
- ;
- method_invocation
- : name OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
- | name OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
- | primary PERIOD_TOKEN identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
- | primary PERIOD_TOKEN identifier OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
- | SUPER_TOKEN PERIOD_TOKEN identifier OPEN_PAREN_TOKEN CLOSE_PAREN_TOKEN
- | SUPER_TOKEN PERIOD_TOKEN identifier OPEN_PAREN_TOKEN argument_list CLOSE_PAREN_TOKEN
- ;
- array_access
- : name OPEN_BRACKET_TOKEN expression CLOSE_BRACKET_TOKEN
- | primary_no_new_array OPEN_BRACKET_TOKEN expression CLOSE_BRACKET_TOKEN
- ;
- postfix_expression
- : primary
- | name
- | post_increment_expression
- | post_decrement_expression
- ;
- post_increment_expression
- : postfix_expression INC_TOKEN
- ;
- post_decrement_expression
- : postfix_expression DEC_TOKEN
- ;
- trap_overflow_corner_case
- : pre_increment_expression
- | pre_decrement_expression
- | PLUS_TOKEN unary_expression
- | unary_expression_not_plus_minus
- ;
- unary_expression
- : trap_overflow_corner_case
- | MINUS_TOKEN trap_overflow_corner_case
- | MINUS_TOKEN error
- ;
- pre_increment_expression
- : INC_TOKEN unary_expression
- ;
- pre_decrement_expression
- : DEC_TOKEN unary_expression
- ;
- unary_expression_not_plus_minus
- : postfix_expression
- | TILDE_TOKEN unary_expression
- | NOT_TOKEN unary_expression
- | cast_expression
- ;
- cast_expression
- : OPEN_PAREN_TOKEN primitive_type dims CLOSE_PAREN_TOKEN unary_expression
- | OPEN_PAREN_TOKEN primitive_type CLOSE_PAREN_TOKEN unary_expression
- | OPEN_PAREN_TOKEN expression CLOSE_PAREN_TOKEN unary_expression_not_plus_minus
- | OPEN_PAREN_TOKEN name dims CLOSE_PAREN_TOKEN unary_expression_not_plus_minus
- ;
- multiplicative_expression
- : unary_expression
- | multiplicative_expression MUL_TOKEN unary_expression
- | multiplicative_expression DIV_TOKEN unary_expression
- | multiplicative_expression MOD_TOKEN unary_expression
- ;
- additive_expression
- : multiplicative_expression
- | additive_expression PLUS_TOKEN multiplicative_expression
- | additive_expression MINUS_TOKEN multiplicative_expression
- ;
- shift_expression
- : additive_expression
- | shift_expression SHL_TOKEN additive_expression
- | shift_expression SHR_TOKEN additive_expression
- | shift_expression SAR_TOKEN additive_expression
- ;
- relational_expression
- : shift_expression
- | relational_expression LESS_TOKEN shift_expression
- | relational_expression GREATER_TOKEN shift_expression
- | relational_expression LE_TOKEN shift_expression
- | relational_expression GE_TOKEN shift_expression
- | relational_expression INSTANCEOF_TOKEN reference_type
- ;
- equality_expression
- : relational_expression
- | equality_expression EQ_TOKEN relational_expression
- | equality_expression NE_OP_TOKEN relational_expression
- ;
- and_expression
- : equality_expression
- | and_expression AND_TOKEN equality_expression
- ;
- exclusive_or_expression
- : and_expression
- | exclusive_or_expression XOR_TOKEN and_expression
- ;
- inclusive_or_expression
- : exclusive_or_expression
- | inclusive_or_expression OR_TOKEN exclusive_or_expression
- ;
- conditional_and_expression
- : inclusive_or_expression
- | conditional_and_expression LOGICAL_AND_TOKEN inclusive_or_expression
- ;
- conditional_or_expression
- : conditional_and_expression
- | conditional_or_expression LOGICAL_OR_TOKEN conditional_and_expression
- ;
- conditional_expression
- : conditional_or_expression
- | conditional_or_expression CONDITIONAL_TOKEN expression COLON_TOKEN conditional_expression
- ;
- assignment_expression
- : conditional_expression
- | assignment
- ;
- assignment
- : left_hand_side assignment_operator assignment_expression
- ;
- left_hand_side
- : name
- | field_access
- | array_access
- ;
- assignment_operator
- : ASSIGNS_TOKEN
- | ADD_ASSIGN_TOKEN
- | SUB_ASSIGN_TOKEN
- | MUL_ASSIGN_TOKEN
- | DIV_ASSIGN_TOKEN
- | MOD_ASSIGN_TOKEN
- | SHL_ASSIGN_TOKEN
- | SHR_ASSIGN_TOKEN
- | SAR_ASSIGN_TOKEN
- | AND_ASSIGN_TOKEN
- | XOR_ASSIGN_TOKEN
- | OR_ASSIGN_TOKEN
- ;
- expression
- : assignment_expression
- ;
- constant_expression
- : expression
- ;
- %%
- void print_prototype(void)
- {
- }
- void generate_default_constructor(char *name)
- {
- }
-
- int yyerror(char *mesg)
- {
- printf("line %d: %s before %s\n", yylineno, mesg, yytext);
- exit(0);
- }
|