3 import java_cup.runtime.*;
5 /* Java 1.0 parser for CUP.
6 * Copyright (C) 1998 C. Scott Ananian <cananian@alumni.princeton.edu>
7 * This program is released under the terms of the GPL; see the file
8 * COPYING for more details. There is NO WARRANTY on this code.
14 public Grm10(Lexer l) {
19 public void syntax_error(java_cup.runtime.Symbol current) {
20 report_error("Syntax error (" + current.sym + ")", current);
22 public void report_error(String message, java_cup.runtime.Symbol info) {
23 lexer.errorMsg(message, info);
27 scan with {: return lexer.nextToken(); :};
29 terminal BOOLEAN; // primitive_type
30 terminal BYTE, SHORT, INT, LONG, CHAR; // integral_type
31 terminal FLOAT, DOUBLE; // floating_point_type
32 terminal LBRACK, RBRACK; // array_type
33 terminal java.lang.String IDENTIFIER; // name
34 terminal DOT; // qualified_name
35 terminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;
36 terminal PACKAGE; // package_declaration
37 terminal IMPORT; // import_declaration
38 terminal PUBLIC, PROTECTED, PRIVATE; // modifier
39 terminal STATIC; // modifier
40 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
41 terminal CLASS; // class_declaration
42 terminal EXTENDS; // super
43 terminal IMPLEMENTS; // interfaces
44 terminal VOID; // method_header
45 terminal THROWS; // throws
46 terminal THIS, SUPER; // explicit_constructor_invocation
47 terminal INTERFACE; // interface_declaration
48 terminal IF, ELSE; // if_then_statement, if_then_else_statement
49 terminal SWITCH; // switch_statement
50 terminal CASE, DEFAULT; // switch_label
51 terminal DO, WHILE; // while_statement, do_statement
52 terminal FOR; // for_statement
53 terminal BREAK; // break_statement
54 terminal CONTINUE; // continue_statement
55 terminal RETURN; // return_statement
56 terminal THROW; // throw_statement
57 terminal TRY; // try_statement
58 terminal CATCH; // catch_clause
59 terminal FINALLY; // finally
60 terminal NEW; // class_instance_creation_expression
61 terminal PLUSPLUS; // postincrement_expression
62 terminal MINUSMINUS; // postdecrement_expression
63 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
64 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
65 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
66 terminal EQEQ, NOTEQ; // equality_expression
67 terminal AND; // and_expression
68 terminal XOR; // exclusive_or_expression
69 terminal OR; // inclusive_or_expression
70 terminal ANDAND; // conditional_and_expression
71 terminal OROR; // conditional_or_expression
72 terminal QUESTION; // conditional_expression
73 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
74 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
75 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
77 terminal java.lang.Number INTEGER_LITERAL;
78 terminal java.lang.Number FLOATING_POINT_LITERAL;
79 terminal java.lang.Boolean BOOLEAN_LITERAL;
80 terminal java.lang.Character CHARACTER_LITERAL;
81 terminal java.lang.String STRING_LITERAL;
82 terminal NULL_LITERAL;
84 // Reserved but unused:
86 // lexer compatibility with Java 1.2:
88 // lexer compatibility with Java 1.4
90 // lexer compatibility with Java 1.5
94 // 19.2) The Syntactic Grammar
96 // 19.3) Lexical Structure
98 // 19.4) Types, Values, and Variables
99 non terminal type, primitive_type, numeric_type;
100 non terminal integral_type, floating_point_type;
101 non terminal reference_type;
102 non terminal class_or_interface_type;
103 non terminal class_type, interface_type;
104 non terminal array_type;
106 non terminal name, simple_name, qualified_name;
108 non terminal compilation_unit;
109 non terminal package_declaration_opt, package_declaration;
110 non terminal import_declarations_opt, import_declarations;
111 non terminal type_declarations_opt, type_declarations;
112 non terminal import_declaration;
113 non terminal single_type_import_declaration;
114 non terminal type_import_on_demand_declaration;
115 non terminal type_declaration;
116 // 19.7) Productions used only in the LALR(1) grammar
117 non terminal modifiers_opt, modifiers, modifier;
118 // 19.8.1) Class Declaration
119 non terminal class_declaration, super, super_opt;
120 non terminal interfaces, interfaces_opt, interface_type_list;
121 non terminal class_body;
122 non terminal class_body_declarations, class_body_declarations_opt;
123 non terminal class_body_declaration, class_member_declaration;
124 // 19.8.2) Field Declarations
125 non terminal field_declaration, variable_declarators, variable_declarator;
126 non terminal variable_declarator_id, variable_initializer;
127 // 19.8.3) Method Declarations
128 non terminal method_declaration, method_header, method_declarator;
129 non terminal formal_parameter_list_opt, formal_parameter_list;
130 non terminal formal_parameter;
131 non terminal throws_opt, throws;
132 non terminal class_type_list, method_body;
133 // 19.8.4) Static Initializers
134 non terminal static_initializer;
135 // 19.8.5) Constructor Declarations
136 non terminal constructor_declaration, constructor_declarator;
137 non terminal constructor_body;
138 non terminal explicit_constructor_invocation;
139 // 19.9.1) Interface Declarations
140 non terminal interface_declaration;
141 non terminal extends_interfaces_opt, extends_interfaces;
142 non terminal interface_body;
143 non terminal interface_member_declarations_opt, interface_member_declarations;
144 non terminal interface_member_declaration, constant_declaration;
145 non terminal abstract_method_declaration;
147 non terminal array_initializer;
148 non terminal variable_initializers;
149 // 19.11) Blocks and Statements
151 non terminal block_statements_opt, block_statements, block_statement;
152 non terminal local_variable_declaration_statement, local_variable_declaration;
153 non terminal statement, statement_no_short_if;
154 non terminal statement_without_trailing_substatement;
155 non terminal empty_statement;
156 non terminal labeled_statement, labeled_statement_no_short_if;
157 non terminal expression_statement, statement_expression;
158 non terminal if_then_statement;
159 non terminal if_then_else_statement, if_then_else_statement_no_short_if;
160 non terminal switch_statement, switch_block;
161 non terminal switch_block_statement_groups;
162 non terminal switch_block_statement_group;
163 non terminal switch_labels, switch_label;
164 non terminal while_statement, while_statement_no_short_if;
165 non terminal do_statement;
166 non terminal for_statement, for_statement_no_short_if;
167 non terminal for_init_opt, for_init;
168 non terminal for_update_opt, for_update;
169 non terminal statement_expression_list;
170 non terminal identifier_opt;
171 non terminal break_statement, continue_statement;
172 non terminal return_statement, throw_statement;
173 non terminal synchronized_statement, try_statement;
174 non terminal catches_opt, catches, catch_clause;
175 non terminal finally;
176 // 19.12) Expressions
177 non terminal primary, primary_no_new_array;
178 non terminal class_instance_creation_expression;
179 non terminal argument_list_opt, argument_list;
180 non terminal array_creation_expression;
181 non terminal dim_exprs, dim_expr, dims_opt, dims;
182 non terminal field_access, method_invocation, array_access;
183 non terminal postfix_expression;
184 non terminal postincrement_expression, postdecrement_expression;
185 non terminal unary_expression, unary_expression_not_plus_minus;
186 non terminal preincrement_expression, predecrement_expression;
187 non terminal cast_expression;
188 non terminal multiplicative_expression, additive_expression;
189 non terminal shift_expression, relational_expression, equality_expression;
190 non terminal and_expression, exclusive_or_expression, inclusive_or_expression;
191 non terminal conditional_and_expression, conditional_or_expression;
192 non terminal conditional_expression, assignment_expression;
193 non terminal assignment;
194 non terminal left_hand_side;
195 non terminal assignment_operator;
196 non terminal expression_opt, expression;
197 non terminal constant_expression;
201 // 19.2) The Syntactic Grammar
202 goal ::= compilation_unit
205 // 19.3) Lexical Structure.
206 literal ::= INTEGER_LITERAL
207 | FLOATING_POINT_LITERAL
214 // 19.4) Types, Values, and Variables
215 type ::= primitive_type
222 numeric_type::= integral_type
223 | floating_point_type
232 floating_point_type ::=
238 class_or_interface_type
241 class_or_interface_type ::= name;
243 class_type ::= class_or_interface_type;
244 interface_type ::= class_or_interface_type;
246 array_type ::= primitive_type LBRACK RBRACK
248 | array_type LBRACK RBRACK
255 simple_name ::= IDENTIFIER
263 package_declaration_opt
264 import_declarations_opt
265 type_declarations_opt
267 package_declaration_opt ::= package_declaration | ;
268 import_declarations_opt ::= import_declarations | ;
269 type_declarations_opt ::= type_declarations | ;
271 import_declarations ::=
273 | import_declarations import_declaration
275 type_declarations ::=
277 | type_declarations type_declaration
279 package_declaration ::=
280 PACKAGE name SEMICOLON
282 import_declaration ::=
283 single_type_import_declaration
284 | type_import_on_demand_declaration
286 single_type_import_declaration ::=
287 IMPORT name SEMICOLON
289 type_import_on_demand_declaration ::=
290 IMPORT name DOT MULT SEMICOLON
294 | interface_declaration
298 // 19.7) Productions used only in the LALR(1) grammar
302 modifiers ::= modifier
305 modifier ::= PUBLIC | PROTECTED | PRIVATE
307 | ABSTRACT | FINAL | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE
312 // 19.8.1) Class Declaration:
313 class_declaration ::=
314 modifiers_opt CLASS IDENTIFIER super_opt interfaces_opt class_body
316 super ::= EXTENDS class_type
321 interfaces ::= IMPLEMENTS interface_type_list
326 interface_type_list ::=
328 | interface_type_list COMMA interface_type
330 class_body ::= LBRACE class_body_declarations_opt RBRACE
332 class_body_declarations_opt ::=
333 | class_body_declarations ;
334 class_body_declarations ::=
335 class_body_declaration
336 | class_body_declarations class_body_declaration
338 class_body_declaration ::=
339 class_member_declaration
341 | constructor_declaration
343 class_member_declaration ::=
349 // 19.8.2) Field Declarations
350 field_declaration ::=
351 modifiers_opt type variable_declarators SEMICOLON
353 variable_declarators ::=
355 | variable_declarators COMMA variable_declarator
357 variable_declarator ::=
358 variable_declarator_id
359 | variable_declarator_id EQ variable_initializer
361 variable_declarator_id ::=
363 | variable_declarator_id LBRACK RBRACK
365 variable_initializer ::=
370 // 19.8.3) Method Declarations
371 method_declaration ::=
372 method_header method_body
375 modifiers_opt type method_declarator throws_opt
376 | modifiers_opt VOID method_declarator throws_opt
378 method_declarator ::=
379 IDENTIFIER LPAREN formal_parameter_list_opt RPAREN
380 | method_declarator LBRACK RBRACK
382 formal_parameter_list_opt ::=
383 | formal_parameter_list
385 formal_parameter_list ::=
387 | formal_parameter_list COMMA formal_parameter
390 type variable_declarator_id
395 throws ::= THROWS class_type_list
399 | class_type_list COMMA class_type
401 method_body ::= block
405 // 19.8.4) Static Initializers
406 static_initializer ::=
410 // 19.8.5) Constructor Declarations
411 constructor_declaration ::=
412 modifiers_opt constructor_declarator throws_opt
415 constructor_declarator ::=
416 simple_name LPAREN formal_parameter_list_opt RPAREN
419 LBRACE explicit_constructor_invocation
420 block_statements RBRACE
421 | LBRACE explicit_constructor_invocation RBRACE
422 | LBRACE block_statements RBRACE
425 explicit_constructor_invocation ::=
426 THIS LPAREN argument_list_opt RPAREN SEMICOLON
427 | SUPER LPAREN argument_list_opt RPAREN SEMICOLON
432 // 19.9.1) Interface Declarations
433 interface_declaration ::=
434 modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
437 extends_interfaces_opt ::=
440 extends_interfaces ::=
441 EXTENDS interface_type
442 | extends_interfaces COMMA interface_type
445 LBRACE interface_member_declarations_opt RBRACE
447 interface_member_declarations_opt ::=
448 | interface_member_declarations
450 interface_member_declarations ::=
451 interface_member_declaration
452 | interface_member_declarations interface_member_declaration
454 interface_member_declaration ::=
456 | abstract_method_declaration
459 constant_declaration ::=
462 abstract_method_declaration ::=
463 method_header SEMICOLON
467 array_initializer ::=
468 LBRACE variable_initializers COMMA RBRACE
469 | LBRACE variable_initializers RBRACE
470 | LBRACE COMMA RBRACE
473 variable_initializers ::=
475 | variable_initializers COMMA variable_initializer
478 // 19.11) Blocks and Statements
479 block ::= LBRACE block_statements_opt RBRACE
481 block_statements_opt ::=
486 | block_statements block_statement
489 local_variable_declaration_statement
492 local_variable_declaration_statement ::=
493 local_variable_declaration SEMICOLON
495 local_variable_declaration ::=
496 type variable_declarators
498 statement ::= statement_without_trailing_substatement
501 | if_then_else_statement
505 statement_no_short_if ::=
506 statement_without_trailing_substatement
507 | labeled_statement_no_short_if
508 | if_then_else_statement_no_short_if
509 | while_statement_no_short_if
510 | for_statement_no_short_if
512 statement_without_trailing_substatement ::=
515 | expression_statement
521 | synchronized_statement
528 labeled_statement ::=
529 IDENTIFIER COLON statement
531 labeled_statement_no_short_if ::=
532 IDENTIFIER COLON statement_no_short_if
534 expression_statement ::=
535 statement_expression SEMICOLON
537 statement_expression ::=
539 | preincrement_expression
540 | predecrement_expression
541 | postincrement_expression
542 | postdecrement_expression
544 | class_instance_creation_expression
546 if_then_statement ::=
547 IF LPAREN expression RPAREN statement
549 if_then_else_statement ::=
550 IF LPAREN expression RPAREN statement_no_short_if
553 if_then_else_statement_no_short_if ::=
554 IF LPAREN expression RPAREN statement_no_short_if
555 ELSE statement_no_short_if
558 SWITCH LPAREN expression RPAREN switch_block
561 LBRACE switch_block_statement_groups switch_labels RBRACE
562 | LBRACE switch_block_statement_groups RBRACE
563 | LBRACE switch_labels RBRACE
566 switch_block_statement_groups ::=
567 switch_block_statement_group
568 | switch_block_statement_groups switch_block_statement_group
570 switch_block_statement_group ::=
571 switch_labels block_statements
575 | switch_labels switch_label
578 CASE constant_expression COLON
583 WHILE LPAREN expression RPAREN statement
585 while_statement_no_short_if ::=
586 WHILE LPAREN expression RPAREN statement_no_short_if
589 DO statement WHILE LPAREN expression RPAREN SEMICOLON
592 FOR LPAREN for_init_opt SEMICOLON expression_opt SEMICOLON
593 for_update_opt RPAREN statement
595 for_statement_no_short_if ::=
596 FOR LPAREN for_init_opt SEMICOLON expression_opt SEMICOLON
597 for_update_opt RPAREN statement_no_short_if
602 for_init ::= statement_expression_list
603 | local_variable_declaration
608 for_update ::= statement_expression_list
610 statement_expression_list ::=
612 | statement_expression_list COMMA statement_expression
620 BREAK identifier_opt SEMICOLON
623 continue_statement ::=
624 CONTINUE identifier_opt SEMICOLON
627 RETURN expression_opt SEMICOLON
630 THROW expression SEMICOLON
632 synchronized_statement ::=
633 SYNCHRONIZED LPAREN expression RPAREN block
637 | TRY block catches_opt finally
642 catches ::= catch_clause
643 | catches catch_clause
646 CATCH LPAREN formal_parameter RPAREN block
648 finally ::= FINALLY block
651 // 19.12) Expressions
652 primary ::= primary_no_new_array
653 | array_creation_expression
655 primary_no_new_array ::=
658 | LPAREN expression RPAREN
659 | class_instance_creation_expression
664 class_instance_creation_expression ::=
665 NEW class_type LPAREN argument_list_opt RPAREN
667 argument_list_opt ::=
672 | argument_list COMMA expression
674 array_creation_expression ::=
675 NEW primitive_type dim_exprs dims_opt
676 | NEW class_or_interface_type dim_exprs dims_opt
678 dim_exprs ::= dim_expr
681 dim_expr ::= LBRACK expression RBRACK
686 dims ::= LBRACK RBRACK
690 primary DOT IDENTIFIER
691 | SUPER DOT IDENTIFIER
693 method_invocation ::=
694 name LPAREN argument_list_opt RPAREN
695 | primary DOT IDENTIFIER LPAREN argument_list_opt RPAREN
696 | SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
699 name LBRACK expression RBRACK
700 | primary_no_new_array LBRACK expression RBRACK
702 postfix_expression ::=
705 | postincrement_expression
706 | postdecrement_expression
708 postincrement_expression ::=
709 postfix_expression PLUSPLUS
711 postdecrement_expression ::=
712 postfix_expression MINUSMINUS
715 preincrement_expression
716 | predecrement_expression
717 | PLUS unary_expression
718 | MINUS unary_expression
719 | unary_expression_not_plus_minus
721 preincrement_expression ::=
722 PLUSPLUS unary_expression
724 predecrement_expression ::=
725 MINUSMINUS unary_expression
727 unary_expression_not_plus_minus ::=
729 | COMP unary_expression
730 | NOT unary_expression
734 LPAREN primitive_type dims_opt RPAREN unary_expression
735 | LPAREN expression RPAREN unary_expression_not_plus_minus
736 | LPAREN name dims RPAREN unary_expression_not_plus_minus
738 multiplicative_expression ::=
740 | multiplicative_expression MULT unary_expression
741 | multiplicative_expression DIV unary_expression
742 | multiplicative_expression MOD unary_expression
744 additive_expression ::=
745 multiplicative_expression
746 | additive_expression PLUS multiplicative_expression
747 | additive_expression MINUS multiplicative_expression
751 | shift_expression LSHIFT additive_expression
752 | shift_expression RSHIFT additive_expression
753 | shift_expression URSHIFT additive_expression
755 relational_expression ::=
757 | relational_expression LT shift_expression
758 | relational_expression GT shift_expression
759 | relational_expression LTEQ shift_expression
760 | relational_expression GTEQ shift_expression
761 | relational_expression INSTANCEOF reference_type
763 equality_expression ::=
764 relational_expression
765 | equality_expression EQEQ relational_expression
766 | equality_expression NOTEQ relational_expression
770 | and_expression AND equality_expression
772 exclusive_or_expression ::=
774 | exclusive_or_expression XOR and_expression
776 inclusive_or_expression ::=
777 exclusive_or_expression
778 | inclusive_or_expression OR exclusive_or_expression
780 conditional_and_expression ::=
781 inclusive_or_expression
782 | conditional_and_expression ANDAND inclusive_or_expression
784 conditional_or_expression ::=
785 conditional_and_expression
786 | conditional_or_expression OROR conditional_and_expression
788 conditional_expression ::=
789 conditional_or_expression
790 | conditional_or_expression QUESTION expression
791 COLON conditional_expression
793 assignment_expression ::=
794 conditional_expression
797 assignment ::= left_hand_side assignment_operator assignment_expression
804 assignment_operator ::=
821 expression ::= assignment_expression
823 constant_expression ::=