3 import java_cup.runtime.*;
7 /* Java 1.4 parser for CUP.
8 * Copyright (C) 2002-2003 C. Scott Ananian <cananian@alumni.princeton.edu>
9 * This program is released under the terms of the GPL; see the file
10 * COPYING for more details. There is NO WARRANTY on this code.
14 JDK 1.4 Features added:
16 statement_without_trailing_substatement ::= ...
19 ASSERT expression SEMICOLON
20 | ASSERT expression COLON expression SEMICOLON
26 public Parser(Lexer l) {
31 public void syntax_error(java_cup.runtime.Symbol current) {
32 report_error("Syntax error (" + current.sym + ")", current);
34 public void report_error(String message, java_cup.runtime.Symbol info) {
35 lexer.errorMsg(message, info);
39 scan with {: return lexer.nextToken(); :};
41 terminal BOOLEAN; // primitive_type
42 terminal BYTE, SHORT, INT, LONG, CHAR; // integral_type
43 terminal FLOAT, DOUBLE; // floating_point_type
44 terminal LBRACK, RBRACK; // array_type
45 terminal java.lang.String IDENTIFIER; // name
46 terminal DOT; // qualified_name
47 terminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;
48 terminal PACKAGE; // package_declaration
49 terminal IMPORT; // import_declaration
50 terminal PUBLIC, PROTECTED, PRIVATE; // modifier
51 terminal STATIC; // modifier
52 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
53 terminal CLASS; // class_declaration
54 terminal EXTENDS; // super
55 //terminal IMPLEMENTS; // interfaces
56 terminal VOID; // method_header
57 terminal THROWS; // throws
58 terminal THIS, SUPER; // explicit_constructor_invocation
59 //terminal INTERFACE; // interface_declaration
60 terminal IF, ELSE; // if_then_statement, if_then_else_statement
61 terminal SWITCH; // switch_statement
62 terminal CASE, DEFAULT; // switch_label
63 terminal DO, WHILE; // while_statement, do_statement
64 terminal FOR; // for_statement
65 terminal BREAK; // break_statement
66 terminal CONTINUE; // continue_statement
67 terminal RETURN; // return_statement
68 terminal THROW; // throw_statement
69 terminal TRY; // try_statement
70 terminal CATCH; // catch_clause
71 terminal FINALLY; // finally
72 terminal NEW; // class_instance_creation_expression
73 terminal PLUSPLUS; // postincrement_expression
74 terminal MINUSMINUS; // postdecrement_expression
75 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
76 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
77 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
78 terminal EQEQ, NOTEQ; // equality_expression
79 terminal AND; // and_expression
80 terminal XOR; // exclusive_or_expression
81 terminal OR; // inclusive_or_expression
82 terminal ANDAND; // conditional_and_expression
83 terminal OROR; // conditional_or_expression
84 terminal QUESTION; // conditional_expression
85 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
86 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
87 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
89 terminal java.lang.Number INTEGER_LITERAL;
90 terminal java.lang.Number FLOATING_POINT_LITERAL;
91 terminal java.lang.Boolean BOOLEAN_LITERAL;
92 terminal java.lang.Character CHARACTER_LITERAL;
93 terminal java.lang.String STRING_LITERAL;
94 terminal NULL_LITERAL;
96 // Reserved but unused:
98 // strictfp keyword, new in Java 1.2
100 // assert keyword, new in Java 1.4
101 terminal ASSERT; // assert_statement
102 // lexer compatibility with Java 1.5
107 // 19.2) The Syntactic Grammar
108 non terminal ParseNode goal;
109 // 19.3) Lexical Structure
110 non terminal ParseNode literal;
111 // 19.4) Types, Values, and Variables
112 non terminal ParseNode type, primitive_type, numeric_type;
113 non terminal ParseNode integral_type, floating_point_type;
114 non terminal ParseNode reference_type;
115 non terminal ParseNode class_or_interface_type;
116 non terminal ParseNode class_type;
117 //non terminal ParseNode interface_type;
118 non terminal ParseNode array_type;
120 non terminal ParseNode name, simple_name, qualified_name;
122 non terminal ParseNode compilation_unit;
123 //non terminal ParseNode package_declaration_opt, package_declaration;
124 //non terminal ParseNode import_declarations_opt, import_declarations;
125 non terminal ParseNode type_declarations_opt, type_declarations;
126 //non terminal ParseNode import_declaration;
127 //non terminal ParseNode single_type_import_declaration;
128 //non terminal ParseNode type_import_on_demand_declaration;
129 non terminal ParseNode type_declaration;
130 // 19.7) Productions used only in the LALR(1) grammar
131 non terminal ParseNode modifiers_opt, modifiers, modifier;
132 // 19.8.1) Class Declaration
133 non terminal ParseNode class_declaration, super, super_opt;
134 //non terminal interfaces, interfaces_opt, interface_type_list;
135 non terminal ParseNode class_body;
136 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
137 non terminal ParseNode class_body_declaration, class_member_declaration;
138 // 19.8.2) Field Declarations
139 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
140 non terminal ParseNode variable_declarator_id;
141 non terminal ParseNode variable_initializer;
142 // 19.8.3) Method Declarations
143 non terminal ParseNode method_declaration, method_header, method_declarator;
144 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
145 non terminal ParseNode formal_parameter;
146 //non terminal ParseNode throws_opt;
147 //non terminal ParseNode throws;
148 //non terminal ParseNode class_type_list;
149 non terminal ParseNode method_body;
150 // 19.8.4) Static Initializers
151 //non terminal ParseNode static_initializer;
152 // 19.8.5) Constructor Declarations
153 non terminal ParseNode constructor_declaration, constructor_declarator;
154 non terminal ParseNode constructor_body;
155 //non terminal ParseNode explicit_constructor_invocation;
156 // 19.9.1) Interface Declarations
157 //non terminal ParseNode interface_declaration;
158 //non terminal ParseNode extends_interfaces_opt, extends_interfaces;
159 //non terminal ParseNode interface_body;
160 //non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
161 //non terminal ParseNode interface_member_declaration, constant_declaration;
162 //non terminal ParseNode abstract_method_declaration;
164 //non terminal ParseNode array_initializer;
165 //non terminal ParseNode variable_initializers;
166 // 19.11) Blocks and Statements
167 non terminal ParseNode block;
168 non terminal ParseNode block_statements_opt, block_statements, block_statement;
169 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
170 non terminal ParseNode statement, statement_no_short_if;
171 non terminal ParseNode statement_without_trailing_substatement;
172 non terminal ParseNode empty_statement;
173 //non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
174 non terminal ParseNode expression_statement, statement_expression;
175 non terminal ParseNode if_then_statement;
176 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
177 //non terminal ParseNode switch_statement, switch_block;
178 //non terminal ParseNode switch_block_statement_groups;
179 //non terminal ParseNode switch_block_statement_group;
180 //non terminal ParseNode switch_labels, switch_label;
181 non terminal ParseNode while_statement, while_statement_no_short_if;
182 non terminal ParseNode do_statement;
183 non terminal ParseNode for_statement, for_statement_no_short_if;
184 non terminal ParseNode for_init_opt, for_init;
185 non terminal ParseNode for_update_opt, for_update;
186 non terminal ParseNode statement_expression_list;
187 //non terminal ParseNode identifier_opt;
188 non terminal ParseNode break_statement, continue_statement;
189 non terminal ParseNode return_statement;
190 //non terminal ParseNode throw_statement;
191 //non terminal ParseNode synchronized_statement, try_statement;
192 //non terminal ParseNode catches_opt;
193 //non terminal ParseNode catches, catch_clause;
194 //non terminal ParseNode finally;
195 //non terminal ParseNode assert_statement;
196 // 19.12) Expressions
197 non terminal ParseNode primary, primary_no_new_array;
198 non terminal ParseNode class_instance_creation_expression;
199 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
200 non terminal ParseNode argument_list_opt, argument_list;
201 //non terminal ParseNode array_creation_init;
202 non terminal ParseNode array_creation_uninit;
203 non terminal ParseNode dim_exprs, dim_expr;
204 non terminal Integer dims_opt, dims;
205 non terminal ParseNode field_access, method_invocation;
206 non terminal ParseNode array_access;
207 non terminal ParseNode postfix_expression;
208 non terminal ParseNode postincrement_expression, postdecrement_expression;
209 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
210 non terminal ParseNode preincrement_expression, predecrement_expression;
211 non terminal ParseNode cast_expression;
212 non terminal ParseNode multiplicative_expression, additive_expression;
213 non terminal ParseNode shift_expression, relational_expression, equality_expression;
214 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
215 non terminal ParseNode conditional_and_expression, conditional_or_expression;
216 non terminal ParseNode conditional_expression;
217 non terminal ParseNode assignment_expression;
218 non terminal ParseNode assignment;
219 non terminal ParseNode assignment_operator;
220 non terminal ParseNode expression_opt, expression;
221 //non terminal ParseNode constant_expression;
222 //failure aware computation keywords
227 non terminal ParseNode flag_declaration;
228 non terminal ParseNode task_declaration;
229 non terminal ParseNode task_parameter_list;
230 non terminal ParseNode task_parameter;
231 non terminal ParseNode flag_expression;
232 non terminal ParseNode flag_andexpression;
233 non terminal ParseNode flag_notexpression;
234 non terminal ParseNode task_exitstatement;
235 non terminal ParseNode flag_effects_opt;
236 non terminal ParseNode flag_effects;
237 non terminal ParseNode flag_effect;
238 non terminal ParseNode flag_list;
239 non terminal ParseNode flag_list_opt;
240 non terminal ParseNode flag_change;
242 non terminal ParseNode cons_checks_opt;
243 non terminal ParseNode cons_checks;
244 non terminal ParseNode cons_check;
251 TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN
255 ParseNode pn=new ParseNode("task_declaration");
256 pn.addChild("name").addChild(id);
259 pn.addChild("body").addChild(body);
263 task_parameter_list ::=
265 ParseNode pn=new ParseNode("task_parameter_list");
269 | task_parameter_list:fpl COMMA task_parameter:fp {:
276 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
277 ParseNode pn=new ParseNode("task_parameter");
280 pn.addChild("flag").addChild(exp);
286 flag_andexpression:exp {:
289 | flag_expression:exp1 OROR flag_andexpression:exp2 {:
290 ParseNode pn=new ParseNode("or");
297 flag_andexpression ::=
298 flag_notexpression:exp {: RESULT=exp; :}
299 | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {:
300 ParseNode pn=new ParseNode("and");
307 flag_notexpression ::=
308 NOT flag_notexpression:exp {:
309 ParseNode pn=new ParseNode("not");
313 | LPAREN flag_expression:exp RPAREN {:
317 ParseNode pn=new ParseNode("name");
323 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
324 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
327 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
328 | {: RESULT = new ParseNode("empty"); :}
331 cons_checks ::= cons_check:cc {:
332 ParseNode pn=new ParseNode("cons_checks");
336 | cons_checks:ccs COMMA cons_check:cc {:
341 cons_check ::= IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {:
342 ParseNode pn=new ParseNode("cons_check");
343 pn.addChild("name").addChild("identifier").addChild(name);
348 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
349 | {: RESULT = new ParseNode("empty"); :}
352 flag_effects ::= flag_effect:fe {:
353 ParseNode pn=new ParseNode("flag_effects_list");
357 | flag_effects:fes COMMA flag_effect:fe {:
362 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE {:
363 ParseNode pn=new ParseNode("flag_effect");
364 pn.addChild("name").addChild(id);
369 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
370 | {: RESULT = new ParseNode("empty"); :}
373 flag_list ::= flag_change:fc {:
374 ParseNode pn=new ParseNode("flag_list");
378 | flag_list:fl COMMA flag_change:fc {:
383 flag_change ::= IDENTIFIER:id {:
384 RESULT=new ParseNode("name").addChild(id).getRoot();
387 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
390 // 19.2) The Syntactic Grammar
391 goal ::= compilation_unit:cu
397 // 19.3) Lexical Structure.
400 literal ::= INTEGER_LITERAL:integer_lit
402 ParseNode pn=new ParseNode("literal");
403 pn.addChild("integer").setLiteral(integer_lit);
406 | FLOATING_POINT_LITERAL:float_lit
408 ParseNode pn=new ParseNode("literal");
409 pn.addChild("float").setLiteral(float_lit);
412 | BOOLEAN_LITERAL:boolean_lit
414 ParseNode pn=new ParseNode("literal");
415 pn.addChild("boolean").setLiteral(boolean_lit);
418 | CHARACTER_LITERAL:char_lit
420 ParseNode pn=new ParseNode("literal");
421 pn.addChild("char").setLiteral(char_lit);
424 | STRING_LITERAL:string_lit
426 ParseNode pn=new ParseNode("literal");
427 pn.addChild("string").setLiteral(string_lit);
432 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
436 // 19.4) Types, Values, and Variables
437 type ::= primitive_type:type {: RESULT=type; :}
438 | reference_type:type {: RESULT=type; :}
442 numeric_type:type {: RESULT=type; :}
443 | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
445 numeric_type::= integral_type:type {: RESULT=type; :}
446 | floating_point_type:type {: RESULT=type; :}
449 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
450 | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
451 | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
452 | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
453 | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
455 floating_point_type ::=
456 FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
457 | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
461 class_or_interface_type:type {: RESULT=type; :}
462 | array_type:type {: RESULT=type; :}
464 class_or_interface_type ::= name:name {:
465 RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot();
468 class_type ::= class_or_interface_type:type {: RESULT=type; :};
469 //interface_type ::= class_or_interface_type;
471 array_type ::= primitive_type:prim dims:dims {:
472 ParseNode pn=(new ParseNode("type")).addChild("array");
473 pn.addChild("basetype").addChild(prim);
474 pn.addChild("dims").setLiteral(dims);
477 | name:name dims:dims {:
478 ParseNode pn=(new ParseNode("type")).addChild("array");
479 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
480 pn.addChild("dims").setLiteral(dims);
486 name ::= simple_name:name {: RESULT=name; :}
487 | qualified_name:name {: RESULT=name; :}
489 simple_name ::= IDENTIFIER:id {:
490 RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot();
493 qualified_name ::= name:name DOT IDENTIFIER:id {:
494 ParseNode pn=new ParseNode("name");
495 pn.addChild("base").addChild(name);
496 pn.addChild("identifier").addChild(id);
503 // package_declaration_opt
504 // import_declarations_opt
505 type_declarations_opt:tdo {:
506 ParseNode pn=new ParseNode("compilation_unit");
511 //package_declaration_opt ::= package_declaration | ;
512 //import_declarations_opt ::= import_declarations | ;
513 type_declarations_opt ::= type_declarations:tds {:
516 {: RESULT=new ParseNode("empty"); :}
519 //import_declarations ::=
520 // import_declaration
521 // | import_declarations import_declaration
524 type_declarations ::=
525 type_declaration:td {:
526 ParseNode pn=new ParseNode("type_declaration_list");
530 | type_declarations:tds type_declaration:td {:
536 //package_declaration ::=
537 // PACKAGE name SEMICOLON
539 //import_declaration ::=
540 // single_type_import_declaration
541 // | type_import_on_demand_declaration
543 //single_type_import_declaration ::=
544 // IMPORT name SEMICOLON
546 //type_import_on_demand_declaration ::=
547 // IMPORT name DOT MULT SEMICOLON
555 | task_declaration:td
559 // | interface_declaration
560 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
563 // 19.7) Productions used only in the LALR(1) grammar
565 {: RESULT=new ParseNode("empty"); :}
570 modifiers ::= modifier:mo {:
571 ParseNode pn=new ParseNode("modifier_list");
575 | modifiers:mos modifier:mo {:
581 PUBLIC {: RESULT=new ParseNode("public"); :}|
582 PROTECTED {: RESULT=new ParseNode("protected"); :}|
583 PRIVATE {: RESULT=new ParseNode("private"); :}|
584 STATIC {: RESULT=new ParseNode("static"); :} |
586 FINAL {: RESULT=new ParseNode("final"); :}|
587 NATIVE {: RESULT=new ParseNode("native"); :}
591 // STRICTFP // note that semantic analysis must check that the
592 // context of the modifier allows strictfp.
597 // 19.8.1) Class Declaration:
598 class_declaration ::=
599 modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so //interfaces_opt
602 ParseNode pn=new ParseNode("class_declaration");
603 pn.addChild("modifiers").addChild(mo);
604 pn.addChild("name").addChild(id);
605 pn.addChild("super").addChild(so);
606 pn.addChild("classbody").addChild(body);
610 super ::= EXTENDS class_type:classtype {:
615 {: RESULT=new ParseNode("empty"); :}
621 //interfaces ::= IMPLEMENTS interface_type_list
626 //interface_type_list ::=
628 // | interface_type_list COMMA interface_type
631 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
634 class_body_declarations_opt ::=
635 {: RESULT=new ParseNode("empty"); :}
636 | class_body_declarations:cbd {: RESULT=cbd; :};
638 class_body_declarations ::=
639 class_body_declaration:cbd {:
640 ParseNode pn=new ParseNode("class_body_declaration_list");
644 | class_body_declarations:cbds class_body_declaration:cbd {:
650 class_body_declaration ::=
651 class_member_declaration:member {:
652 RESULT=(new ParseNode("member")).addChild(member).getRoot();
654 // | static_initializer
655 | constructor_declaration:constructor {:
656 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
659 RESULT=(new ParseNode("block")).addChild(block).getRoot();
662 class_member_declaration ::=
663 //failure aware computation
664 flag_declaration:flag {:
665 RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
668 field_declaration:field {:
669 RESULT=(new ParseNode("field")).addChild(field).getRoot();
671 | method_declaration:method {:
672 RESULT=(new ParseNode("method")).addChild(method).getRoot();
674 /* repeat the prod for 'class_declaration' here: */
675 // | modifiers_opt CLASS IDENTIFIER super_opt class_body
676 // | interface_declaration
677 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
680 //Failure aware computation
682 FLAG IDENTIFIER:id SEMICOLON {:
683 ParseNode pn=new ParseNode("flag_declaration");
684 pn.addChild("name").addChild(id);
689 // 19.8.2) Field Declarations
690 field_declaration ::=
691 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {:
692 ParseNode pn=new ParseNode("field_declaration");
693 pn.addChild("modifier").addChild(mo);
694 pn.addChild("type").addChild(type);
695 pn.addChild("variables").addChild(var);
700 variable_declarators ::=
701 variable_declarator:vd {:
702 ParseNode pn=new ParseNode("variable_declarators_list");
706 | variable_declarators:vds COMMA variable_declarator:vd {:
711 variable_declarator ::=
712 variable_declarator_id:id {:
713 ParseNode pn=new ParseNode("variable_declarator");
717 | variable_declarator_id:id EQ variable_initializer:init {:
718 ParseNode pn=new ParseNode("variable_declarator");
720 pn.addChild("initializer").addChild(init);
724 variable_declarator_id ::=
726 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
727 | variable_declarator_id:id LBRACK RBRACK {:
728 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
730 variable_initializer ::=
731 expression:exp {: RESULT=exp; :}
732 // | array_initializer
735 // 19.8.3) Method Declarations
736 method_declaration ::=
737 method_header:header method_body:body {:
738 ParseNode pn=new ParseNode("method_declaration");
740 pn.addChild("body").addChild(body);
745 modifiers_opt:mo type:type method_declarator:decl //throws_opt
747 ParseNode pn=new ParseNode("method_header");
748 pn.addChild("modifiers").addChild(mo);
749 pn.addChild("returntype").addChild(type);
753 | modifiers_opt:mo VOID method_declarator:decl //throws_opt
755 ParseNode pn=new ParseNode("method_header");
756 pn.addChild("modifiers").addChild(mo);
761 method_declarator ::=
762 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {:
763 ParseNode pn=new ParseNode("method_declarator");
764 pn.addChild("name").addChild(id);
765 pn.addChild("parameters").addChild(params);
768 // | method_declarator LBRACK RBRACK // deprecated
769 // be careful; the above production also allows 'void foo() []'
771 formal_parameter_list_opt ::=
772 {: RESULT=new ParseNode("empty"); :}
773 | formal_parameter_list:fpl {:
777 formal_parameter_list ::=
778 formal_parameter:fp {:
779 ParseNode pn=new ParseNode("formal_parameter_list");
783 | formal_parameter_list:fpl COMMA formal_parameter:fp {:
789 type:type variable_declarator_id:name {:
790 ParseNode pn=new ParseNode("formal_parameter");
795 // | FINAL type variable_declarator_id
800 //throws ::= THROWS class_type_list
802 //class_type_list ::=
804 // | class_type_list COMMA class_type
806 method_body ::= block:block {:
809 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
812 // 19.8.4) Static Initializers
813 //static_initializer ::=
817 // 19.8.5) Constructor Declarations
818 constructor_declaration ::=
819 modifiers_opt:mo constructor_declarator:cd
821 constructor_body:body {:
822 ParseNode pn=new ParseNode("constructor_declaration");
823 pn.addChild("modifiers").addChild(mo);
825 pn.addChild("body").addChild(body);
829 constructor_declarator ::=
830 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {:
831 ParseNode pn=new ParseNode("constructor_declarator");
833 pn.addChild("parameters").addChild(fplo);
838 // LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE |
839 // LBRACE explicit_constructor_invocation RBRACE |
840 LBRACE block_statements:block RBRACE {:
841 ParseNode pn=new ParseNode("constructor_body");
845 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
847 //explicit_constructor_invocation ::=
848 // THIS LPAREN argument_list_opt RPAREN SEMICOLON
849 // | SUPER LPAREN argument_list_opt RPAREN SEMICOLON
850 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
851 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
856 // 19.9.1) Interface Declarations
857 //interface_declaration ::=
858 // modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
861 //extends_interfaces_opt ::=
862 // | extends_interfaces
864 //extends_interfaces ::=
865 // EXTENDS interface_type
866 // | extends_interfaces COMMA interface_type
869 // LBRACE interface_member_declarations_opt RBRACE
871 //interface_member_declarations_opt ::=
872 // | interface_member_declarations
874 //interface_member_declarations ::=
875 // interface_member_declaration
876 // | interface_member_declarations interface_member_declaration
878 //interface_member_declaration ::=
879 // constant_declaration
880 // | abstract_method_declaration
881 // | class_declaration
882 // | interface_declaration
885 //constant_declaration ::=
887 // // need to semantically check that modifiers of field declaration
888 // // include only PUBLIC, STATIC, or FINAL. Other modifiers are
891 //abstract_method_declaration ::=
892 // method_header SEMICOLON
897 //array_initializer ::=
898 // LBRACE variable_initializers COMMA RBRACE
899 // | LBRACE variable_initializers RBRACE
900 // | LBRACE COMMA RBRACE
903 //variable_initializers ::=
904 // variable_initializer
905 // | variable_initializers COMMA variable_initializer
908 // 19.11) Blocks and Statements
909 block ::= LBRACE block_statements_opt:bso RBRACE {:
913 block_statements_opt ::=
914 {: RESULT=new ParseNode("empty"); :}
915 | block_statements:bs {:
920 block_statement:bs {:
921 ParseNode pn=new ParseNode("block_statement_list");
925 | block_statements:bss block_statement:bs {:
931 local_variable_declaration_statement:lvds {:
934 | statement:statement {:
937 // | class_declaration
938 // | interface_declaration
940 local_variable_declaration_statement ::=
941 local_variable_declaration:lvd SEMICOLON {:
945 local_variable_declaration ::=
946 type:type variable_declarators:var {:
947 ParseNode pn=new ParseNode("local_variable_declaration");
952 // | FINAL type variable_declarators
954 statement ::= statement_without_trailing_substatement:st {:
957 // | labeled_statement:st {: RESULT=st; :}
958 | if_then_statement:st {: RESULT=st; :}
959 | if_then_else_statement:st {: RESULT=st; :}
960 | while_statement:st {: RESULT=st; :}
961 | for_statement:st {: RESULT=st; :}
963 statement_no_short_if ::=
964 statement_without_trailing_substatement:st {: RESULT=st; :}
965 // | labeled_statement_no_short_if:st {: RESULT=st; :}
966 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
967 | while_statement_no_short_if:st {: RESULT=st; :}
968 | for_statement_no_short_if:st {: RESULT=st; :}
970 statement_without_trailing_substatement ::=
971 block:st {: RESULT=st; :}
972 | empty_statement:st {: RESULT=st; :}
973 | expression_statement:st {: RESULT=st; :}
974 // | switch_statement
975 | do_statement:dos {:RESULT=dos; :}
976 | break_statement:st {: RESULT=st; :}
977 | continue_statement:st {: RESULT=st; :}
978 | return_statement:st {: RESULT=st; :}
979 | task_exitstatement:st {: RESULT=st; :}
980 // | synchronized_statement
983 // | assert_statement
986 SEMICOLON {: RESULT=new ParseNode("nop"); :}
988 //labeled_statement ::=
989 // IDENTIFIER COLON statement
991 //labeled_statement_no_short_if ::=
992 // IDENTIFIER COLON statement_no_short_if
994 expression_statement ::=
995 statement_expression:se SEMICOLON {:
996 ParseNode pn=new ParseNode("expression");
1000 statement_expression ::=
1001 assignment:st {: RESULT=st; :}
1002 | preincrement_expression:st {: RESULT=st; :}
1003 | predecrement_expression:st {: RESULT=st; :}
1004 | postincrement_expression:st {: RESULT=st; :}
1005 | postdecrement_expression:st {: RESULT=st; :}
1006 | method_invocation:st {: RESULT=st; :}
1007 | class_instance_creation_expression:st {: RESULT=st; :}
1009 if_then_statement ::=
1010 IF LPAREN expression:exp RPAREN statement:st {:
1011 ParseNode pn=new ParseNode("ifstatement");
1012 pn.addChild("condition").addChild(exp);
1013 pn.addChild("statement").addChild(st);
1017 if_then_else_statement ::=
1018 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1019 ELSE statement:else_st {:
1020 ParseNode pn=new ParseNode("ifstatement");
1021 pn.addChild("condition").addChild(exp);
1022 pn.addChild("statement").addChild(st);
1023 pn.addChild("else_statement").addChild(else_st);
1027 if_then_else_statement_no_short_if ::=
1028 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1029 ELSE statement_no_short_if:else_st {:
1030 ParseNode pn=new ParseNode("ifstatement");
1031 pn.addChild("condition").addChild(exp);
1032 pn.addChild("statement").addChild(st);
1033 pn.addChild("else_statement").addChild(else_st);
1037 //switch_statement ::=
1038 // SWITCH LPAREN expression RPAREN switch_block
1041 // LBRACE switch_block_statement_groups switch_labels RBRACE
1042 // | LBRACE switch_block_statement_groups RBRACE
1043 // | LBRACE switch_labels RBRACE
1046 //switch_block_statement_groups ::=
1047 // switch_block_statement_group
1048 // | switch_block_statement_groups switch_block_statement_group
1050 //switch_block_statement_group ::=
1051 // switch_labels block_statements
1055 // | switch_labels switch_label
1058 // CASE constant_expression COLON
1063 WHILE LPAREN expression:exp RPAREN statement:st {:
1064 ParseNode pn=new ParseNode("whilestatement");
1065 pn.addChild("condition").addChild(exp);
1066 pn.addChild("statement").addChild(st);
1070 while_statement_no_short_if ::=
1071 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1072 ParseNode pn=new ParseNode("whilestatement");
1073 pn.addChild("condition").addChild(exp);
1074 pn.addChild("statement").addChild(st);
1079 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1080 ParseNode pn=new ParseNode("dowhilestatement");
1081 pn.addChild("condition").addChild(exp);
1082 pn.addChild("statement").addChild(st);
1087 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1088 for_update_opt:update RPAREN statement:st {:
1089 ParseNode pn=new ParseNode("forstatement");
1090 pn.addChild("initializer").addChild(init);
1091 pn.addChild("condition").addChild(exp);
1092 pn.addChild("update").addChild(update);
1093 pn.addChild("statement").addChild(st);
1097 for_statement_no_short_if ::=
1098 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1099 for_update_opt:update RPAREN statement_no_short_if:st {:
1100 ParseNode pn=new ParseNode("forstatement");
1101 pn.addChild("initializer").addChild(init);
1102 pn.addChild("condition").addChild(exp);
1103 pn.addChild("update").addChild(update);
1104 pn.addChild("statement").addChild(st);
1109 {: RESULT=new ParseNode("empty"); :}
1110 | for_init:init {: RESULT=init; :}
1112 for_init ::= statement_expression_list:list {: RESULT=list; :}
1113 | local_variable_declaration:decl {: RESULT=decl; :}
1116 {: RESULT=new ParseNode("empty"); :}
1117 | for_update:update {: RESULT=update; :}
1119 for_update ::= statement_expression_list:list {: RESULT=list; :}
1121 statement_expression_list ::=
1122 statement_expression:expr {:
1123 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1125 | statement_expression_list:list COMMA statement_expression:expr {:
1126 list.addChild(expr);
1131 //identifier_opt ::=
1138 SEMICOLON {: RESULT=new ParseNode("break"); :}
1141 continue_statement ::=
1145 {: RESULT=new ParseNode("continue"); :}
1147 return_statement ::=
1148 RETURN expression_opt:exp SEMICOLON {:
1149 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1151 //throw_statement ::=
1152 // THROW expression SEMICOLON
1154 //synchronized_statement ::=
1155 // SYNCHRONIZED LPAREN expression RPAREN block
1158 // TRY block catches
1159 // | TRY block catches_opt finally
1164 //catches ::= catch_clause
1165 // | catches catch_clause
1168 // CATCH LPAREN formal_parameter RPAREN block
1170 //finally ::= FINALLY block
1172 //assert_statement ::=
1173 // ASSERT expression SEMICOLON
1174 // | ASSERT expression COLON expression SEMICOLON
1177 // 19.12) Expressions
1178 primary ::= primary_no_new_array:st {:
1180 // | array_creation_init:st {:
1183 | array_creation_uninit:st {:
1187 primary_no_new_array ::=
1188 literal:lit {: RESULT=lit; :}
1189 | THIS {: RESULT=new ParseNode("this"); :}
1190 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1191 | class_instance_creation_expression:exp {: RESULT=exp; :}
1192 | field_access:exp {: RESULT=exp; :}
1193 | method_invocation:exp {: RESULT=exp; :}
1194 | array_access:exp {: RESULT=exp; :}
1195 // | primitive_type DOT CLASS
1197 // | array_type DOT CLASS
1201 class_instance_creation_expression ::=
1202 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1203 ParseNode pn=new ParseNode("createobject");
1209 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1210 // | primary DOT NEW IDENTIFIER
1211 // LPAREN argument_list_opt RPAREN {:
1214 // | primary DOT NEW IDENTIFIER
1215 // LPAREN argument_list_opt RPAREN class_body
1216 // | name DOT NEW IDENTIFIER
1217 // LPAREN argument_list_opt RPAREN
1218 // | name DOT NEW IDENTIFIER
1219 // LPAREN argument_list_opt RPAREN class_body
1221 cons_argument_list_opt ::=
1222 {: RESULT=new ParseNode("empty"); :}
1223 | cons_argument_list:args {: RESULT=args; :}
1226 cons_argument_list ::=
1227 IDENTIFIER:id COLON expression:exp {:
1228 ParseNode pn=new ParseNode("cons_argument_list");
1229 ParseNode pnarg=pn.addChild("binding");
1230 pnarg.addChild("var").addChild(id);
1231 pnarg.addChild("exp").addChild(exp);
1234 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1235 ParseNode pnarg=new ParseNode("binding");
1236 pnarg.addChild("var").addChild(id);
1237 pnarg.addChild("exp").addChild(exp);
1238 list.addChild(pnarg);
1243 argument_list_opt ::=
1244 {: RESULT=new ParseNode("empty"); :}
1245 | argument_list:args {: RESULT=args; :}
1250 ParseNode pn=new ParseNode("argument_list");
1254 | argument_list:list COMMA expression:exp {:
1259 array_creation_uninit ::=
1260 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1261 ParseNode pn=new ParseNode("createarray");
1263 pn.addChild(dimexpr);
1264 pn.addChild("dims_opt").setLiteral(dims);
1267 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1268 ParseNode pn=new ParseNode("createarray");
1270 pn.addChild(dimexpr);
1271 pn.addChild("dims_opt").setLiteral(dims);
1275 //array_creation_init ::=
1276 // NEW primitive_type dims array_initializer
1277 // | NEW class_or_interface_type dims array_initializer
1279 dim_exprs ::= dim_expr:exp {:
1280 ParseNode pn=new ParseNode("dim_exprs");
1283 | dim_exprs:base dim_expr:exp {:
1288 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1290 dims_opt ::= {: RESULT=new Integer(0); :}
1291 | dims:dims {: RESULT = dims; :}
1294 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1295 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1299 primary:base DOT IDENTIFIER:id {:
1300 ParseNode pn=new ParseNode("fieldaccess");
1301 pn.addChild("base").addChild(base);
1302 pn.addChild("field").addChild(id);
1305 // | SUPER DOT IDENTIFIER
1306 // | name DOT SUPER DOT IDENTIFIER
1308 method_invocation ::=
1309 name:name LPAREN argument_list_opt:args RPAREN {:
1310 ParseNode pn=new ParseNode("methodinvoke1");
1315 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1316 ParseNode pn=new ParseNode("methodinvoke2");
1317 pn.addChild("base").addChild(base);
1318 pn.addChild("id").addChild(name);
1322 // | SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1323 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1326 name:name LBRACK expression:exp RBRACK {:
1327 ParseNode pn=new ParseNode("arrayaccess");
1328 pn.addChild("base").addChild(name);
1329 pn.addChild("index").addChild(exp);
1332 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1333 ParseNode pn=new ParseNode("arrayaccess");
1334 pn.addChild("base").addChild(base);
1335 pn.addChild("index").addChild(exp);
1338 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1339 // ParseNode pn=new ParseNode("arrayaccess");
1340 // pn.addChild("init").addChild(init);
1341 // pn.addChild("index").addChild(exp);
1345 postfix_expression ::=
1348 | name:exp {: RESULT=exp; :}
1349 | postincrement_expression:exp {: RESULT=exp; :}
1350 | postdecrement_expression:exp {: RESULT=exp; :}
1352 postincrement_expression ::=
1353 postfix_expression:exp PLUSPLUS
1354 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1356 postdecrement_expression ::=
1357 postfix_expression:exp MINUSMINUS
1358 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1360 unary_expression ::=
1361 preincrement_expression:exp {: RESULT=exp; :}
1362 | predecrement_expression:exp {: RESULT=exp; :}
1363 | PLUS unary_expression:exp
1364 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1365 | MINUS unary_expression:exp
1366 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1367 | unary_expression_not_plus_minus:exp {:
1370 preincrement_expression ::=
1371 PLUSPLUS unary_expression:exp
1372 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1374 predecrement_expression ::=
1375 MINUSMINUS unary_expression:exp
1376 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1378 unary_expression_not_plus_minus ::=
1379 postfix_expression:exp {:
1381 // | COMP unary_expression
1382 | NOT unary_expression:exp
1383 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1384 | cast_expression:exp {: RESULT=exp; :}
1387 LPAREN primitive_type:type
1389 RPAREN unary_expression:exp {:
1390 ParseNode pn=new ParseNode("cast1");
1391 pn.addChild("type").addChild(type);
1392 pn.addChild("exp").addChild(exp);
1395 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
1396 ParseNode pn=new ParseNode("cast2");
1397 pn.addChild("type").addChild(type);
1398 pn.addChild("exp").addChild(exp);
1402 // | LPAREN name dims RPAREN unary_expression_not_plus_minus
1404 multiplicative_expression ::=
1405 unary_expression:exp {:
1407 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
1408 ParseNode pn=new ParseNode("mult");
1413 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1414 ParseNode pn=new ParseNode("div");
1419 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1420 ParseNode pn=new ParseNode("mod");
1426 additive_expression ::=
1427 multiplicative_expression:exp {:
1429 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
1430 ParseNode pn=new ParseNode("add");
1435 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
1436 ParseNode pn=new ParseNode("sub");
1442 shift_expression ::=
1443 additive_expression:exp {:
1445 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
1446 ParseNode pn=new ParseNode("leftshift");
1451 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
1452 ParseNode pn=new ParseNode("rightshift");
1457 // | shift_expression URSHIFT additive_expression
1459 relational_expression ::=
1460 shift_expression:exp {:
1462 | relational_expression:exp1 LT shift_expression:exp2 {:
1463 ParseNode pn=new ParseNode("comp_lt");
1468 | relational_expression:exp1 GT shift_expression:exp2 {:
1469 ParseNode pn=new ParseNode("comp_gt");
1474 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
1475 ParseNode pn=new ParseNode("comp_lte");
1480 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
1481 ParseNode pn=new ParseNode("comp_gte");
1486 // | relational_expression INSTANCEOF reference_type
1489 equality_expression ::=
1490 relational_expression:exp {:
1492 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
1493 ParseNode pn=new ParseNode("equal");
1498 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
1499 ParseNode pn=new ParseNode("not_equal");
1506 equality_expression:exp {:
1508 | and_expression:exp1 AND equality_expression:exp2 {:
1509 ParseNode pn=new ParseNode("bitwise_and");
1515 exclusive_or_expression ::=
1516 and_expression:expr {:
1519 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
1520 ParseNode pn=new ParseNode("bitwise_xor");
1526 inclusive_or_expression ::=
1527 exclusive_or_expression:exclor {:
1529 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
1530 ParseNode pn=new ParseNode("bitwise_or");
1536 conditional_and_expression ::=
1537 inclusive_or_expression:inclor {:
1539 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1540 ParseNode pn=new ParseNode("logical_and");
1546 conditional_or_expression ::=
1547 conditional_and_expression:condand {:
1549 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
1550 ParseNode pn=new ParseNode("logical_or");
1556 conditional_expression ::=
1557 conditional_or_expression:condor {:
1559 // | conditional_or_expression QUESTION expression
1560 // COLON conditional_expression
1562 assignment_expression ::=
1563 conditional_expression:expr {:
1565 assignment:assign {:
1568 // semantic check necessary here to ensure a valid left-hand side.
1569 // allowing a parenthesized variable here on the lhs was introduced in
1570 // JLS 2; thanks to Eric Blake for pointing this out.
1571 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
1572 ParseNode pn=new ParseNode("assignment");
1573 pn.addChild("op").addChild(op);
1574 ParseNode pnargs=pn.addChild("args");
1575 pnargs.addChild(lvalue);
1576 pnargs.addChild(rvalue);
1580 assignment_operator ::=
1581 EQ {: RESULT=new ParseNode("eq"); :}
1582 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
1583 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
1584 | MODEQ {: RESULT=new ParseNode("modeq"); :}
1585 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
1586 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
1587 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
1588 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
1589 // | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
1590 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
1591 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
1592 | OREQ {: RESULT=new ParseNode("oreq"); :}
1595 {: RESULT=new ParseNode("empty"); :}
1599 expression ::= assignment_expression:exp {:
1602 //constant_expression ::=