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
106 // added for disjoint reachability analysis
110 // 19.2) The Syntactic Grammar
111 non terminal ParseNode goal;
112 // 19.3) Lexical Structure
113 non terminal ParseNode literal;
114 // 19.4) Types, Values, and Variables
115 non terminal ParseNode type, primitive_type, numeric_type;
116 non terminal ParseNode integral_type, floating_point_type;
117 non terminal ParseNode reference_type;
118 non terminal ParseNode class_or_interface_type;
119 non terminal ParseNode class_type;
120 non terminal ParseNode interface_type;
121 non terminal ParseNode array_type;
123 non terminal ParseNode name, simple_name, qualified_name;
125 non terminal ParseNode compilation_unit;
126 non terminal ParseNode package_declaration_opt, package_declaration;
127 non terminal ParseNode import_declarations_opt, import_declarations;
128 non terminal ParseNode type_declarations_opt, type_declarations;
129 non terminal ParseNode import_declaration;
130 non terminal ParseNode single_type_import_declaration;
131 non terminal ParseNode type_import_on_demand_declaration;
132 non terminal ParseNode type_declaration;
133 // 19.7) Productions used only in the LALR(1) grammar
134 non terminal ParseNode modifiers_opt, modifiers, modifier;
135 // 19.8.1) Class Declaration
136 non terminal ParseNode class_declaration, super, super_opt;
137 non terminal ParseNode interfaces, interfaces_opt, interface_type_list;
138 non terminal ParseNode class_body;
139 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
140 non terminal ParseNode class_body_declaration, class_member_declaration;
141 // 19.8.2) Field Declarations
142 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
143 non terminal ParseNode variable_declarator_id;
144 non terminal ParseNode variable_initializer;
145 // 19.8.3) Method Declarations
146 non terminal ParseNode method_declaration, method_header, method_declarator;
147 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
148 non terminal ParseNode formal_parameter;
149 //non terminal ParseNode throws_opt;
150 //non terminal ParseNode throws;
151 //non terminal ParseNode class_type_list;
152 non terminal ParseNode method_body;
153 // 19.8.4) Static Initializers
154 non terminal ParseNode static_initializer;
155 // 19.8.5) Constructor Declarations
156 non terminal ParseNode constructor_declaration, constructor_declarator;
157 non terminal ParseNode constructor_body;
158 non terminal ParseNode explicit_constructor_invocation;
159 // 19.9.1) Interface Declarations
160 non terminal ParseNode interface_declaration;
161 non terminal ParseNode extends_interfaces_opt, extends_interfaces;
162 non terminal ParseNode interface_body;
163 non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
164 non terminal ParseNode interface_member_declaration, constant_declaration;
165 non terminal ParseNode abstract_method_declaration;
167 non terminal ParseNode array_initializer;
168 non terminal ParseNode variable_initializers;
169 // 19.11) Blocks and Statements
170 non terminal ParseNode block;
171 non terminal ParseNode block_statements_opt, block_statements, block_statement;
172 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
173 non terminal ParseNode statement, statement_no_short_if;
174 non terminal ParseNode statement_without_trailing_substatement;
175 non terminal ParseNode empty_statement;
176 //non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
177 non terminal ParseNode expression_statement, statement_expression;
178 non terminal ParseNode if_then_statement;
179 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
180 non terminal ParseNode switch_statement, switch_block;
181 non terminal ParseNode switch_block_statement_groups;
182 non terminal ParseNode switch_block_statement_group;
183 non terminal ParseNode switch_labels, switch_label;
184 non terminal ParseNode while_statement, while_statement_no_short_if;
185 non terminal ParseNode do_statement;
186 non terminal ParseNode for_statement, for_statement_no_short_if;
187 non terminal ParseNode for_init_opt, for_init;
188 non terminal ParseNode for_update_opt, for_update;
189 non terminal ParseNode statement_expression_list;
190 //non terminal ParseNode identifier_opt;
191 non terminal ParseNode break_statement, continue_statement;
192 non terminal ParseNode return_statement;
193 //non terminal ParseNode throw_statement;
194 non terminal ParseNode synchronized_statement;
195 //non terminal ParseNode try_statement;
196 //non terminal ParseNode catches_opt;
197 //non terminal ParseNode catches, catch_clause;
198 //non terminal ParseNode finally;
199 //non terminal ParseNode assert_statement;
200 non terminal ParseNode genreach_statement;
201 // 19.12) Expressions
202 non terminal ParseNode primary, primary_no_new_array;
203 non terminal ParseNode class_instance_creation_expression;
204 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
205 non terminal ParseNode argument_list_opt, argument_list;
206 //non terminal ParseNode array_creation_init;
207 non terminal ParseNode array_creation_uninit;
208 non terminal ParseNode dim_exprs, dim_expr;
209 non terminal Integer dims_opt, dims;
210 non terminal ParseNode field_access, method_invocation;
211 non terminal ParseNode array_access;
212 non terminal ParseNode postfix_expression;
213 non terminal ParseNode postincrement_expression, postdecrement_expression;
214 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
215 non terminal ParseNode preincrement_expression, predecrement_expression;
216 non terminal ParseNode cast_expression;
217 non terminal ParseNode multiplicative_expression, additive_expression;
218 non terminal ParseNode shift_expression, relational_expression, equality_expression;
219 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
220 non terminal ParseNode conditional_and_expression, conditional_or_expression;
221 non terminal ParseNode conditional_expression;
222 non terminal ParseNode assignment_expression;
223 non terminal ParseNode assignment;
224 non terminal ParseNode assignment_operator;
225 non terminal ParseNode expression_opt, expression;
226 non terminal ParseNode constant_expression;
227 //failure aware computation keywords
230 terminal ISAVAILABLE;
235 non terminal ParseNode flag_declaration;
236 non terminal ParseNode task_declaration;
237 non terminal ParseNode task_parameter_list;
238 non terminal ParseNode task_parameter;
239 non terminal ParseNode flag_expression;
240 non terminal ParseNode flag_andexpression;
241 non terminal ParseNode flag_notexpression;
242 non terminal ParseNode task_exitstatement;
243 non terminal ParseNode flag_effects_opt;
244 non terminal ParseNode flag_effects;
245 non terminal ParseNode flag_effect;
246 non terminal ParseNode flag_list;
247 non terminal ParseNode flag_list_opt;
248 non terminal ParseNode flag_change;
250 non terminal ParseNode cons_checks_opt;
251 non terminal ParseNode cons_checks;
252 non terminal ParseNode cons_check;
254 non terminal ParseNode tag_variable_declaration_statement;
255 non terminal ParseNode tag_expression_list;
256 non terminal ParseNode tag_expression;
257 non terminal ParseNode tag_list;
258 non terminal ParseNode tag_list_opt;
259 non terminal ParseNode tag_change;
261 //distributed transaction keywords
266 non terminal ParseNode atomic_statement;
267 non terminal ParseNode getoffset_expression;
269 //disjointness for Java
272 //coarse-grain parallelization
275 non terminal ParseNode sese_statement;
278 // JSR-201) Enum Declaration
279 non terminal ParseNode enum_declaration;
280 non terminal ParseNode enum_body, enum_constants_opt, enum_constants, enum_constant;
281 //non terminal ParseNode enum_arguments_opt, enum_body_declarations_opt;
289 TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN
293 ParseNode pn=new ParseNode("task_declaration");
294 pn.addChild("name").addChild(id);
297 pn.addChild("body").addChild(body);
301 task_parameter_list ::=
303 ParseNode pn=new ParseNode("task_parameter_list");
307 | task_parameter_list:fpl COMMA task_parameter:fp {:
314 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
315 ParseNode pn=new ParseNode("task_parameter");
318 pn.addChild("flag").addChild(exp);
321 | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
322 ParseNode pn=new ParseNode("task_parameter");
325 pn.addChild("flag").addChild(exp);
326 pn.addChild("tag").addChild(texp);
329 | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
330 ParseNode pn=new ParseNode("task_parameter");
333 pn.addChild("tag").addChild(texp);
336 | OPTIONAL task_parameter:fp {:
337 ParseNode pn=new ParseNode("task_parameter");
338 pn.addChild("optional").addChild(fp);
344 tag_expression_list ::= tag_expression:te {:
345 ParseNode pn=new ParseNode("tag_expression_list");
349 | tag_expression_list:tel COMMA tag_expression:te {:
355 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {:
356 ParseNode pn=new ParseNode("tag_expression");
357 pn.addChild("type").addChild(type);
358 pn.addChild("single").addChild(id);
363 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
364 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
365 | {: RESULT = new ParseNode("empty"); :}
368 tag_list ::= tag_change:fc {:
369 ParseNode pn=new ParseNode("tag_list");
373 | tag_list:fl COMMA tag_change:fc {:
378 tag_change ::= IDENTIFIER:id {:
379 RESULT=new ParseNode("name").addChild(id).getRoot();
381 | NOT IDENTIFIER:id {:
382 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
386 flag_andexpression:exp {:
389 | flag_expression:exp1 OROR flag_andexpression:exp2 {:
390 ParseNode pn=new ParseNode("or");
397 flag_andexpression ::=
398 flag_notexpression:exp {: RESULT=exp; :}
399 | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {:
400 ParseNode pn=new ParseNode("and");
407 flag_notexpression ::=
408 NOT flag_notexpression:exp {:
409 ParseNode pn=new ParseNode("not");
413 | LPAREN flag_expression:exp RPAREN {:
417 ParseNode pn=new ParseNode("name");
423 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
424 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
427 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
428 | {: RESULT = new ParseNode("empty"); :}
431 cons_checks ::= cons_check:cc {:
432 ParseNode pn=new ParseNode("cons_checks");
436 | cons_checks:ccs COMMA cons_check:cc {:
441 cons_check ::= IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {:
442 ParseNode pn=new ParseNode("cons_check");
443 pn.addChild("name").addChild("identifier").addChild(name);
448 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
449 | {: RESULT = new ParseNode("empty"); :}
452 flag_effects ::= flag_effect:fe {:
453 ParseNode pn=new ParseNode("flag_effects_list");
457 | flag_effects:fes COMMA flag_effect:fe {:
462 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {:
463 ParseNode pn=new ParseNode("flag_effect");
464 pn.addChild("name").addChild(id);
469 | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
470 ParseNode pn=new ParseNode("flag_effect");
471 pn.addChild("name").addChild(id);
476 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
477 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
479 {: RESULT = new ParseNode("empty"); :}
482 flag_list ::= flag_change:fc {:
483 ParseNode pn=new ParseNode("flag_list");
487 | flag_list:fl COMMA flag_change:fc {:
492 flag_change ::= IDENTIFIER:id {:
493 RESULT=new ParseNode("name").addChild(id).getRoot();
496 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
499 // 19.2) The Syntactic Grammar
500 goal ::= compilation_unit:cu
506 // 19.3) Lexical Structure.
509 literal ::= INTEGER_LITERAL:integer_lit
511 ParseNode pn=new ParseNode("literal");
512 pn.addChild("integer").setLiteral(integer_lit);
515 | FLOATING_POINT_LITERAL:float_lit
517 ParseNode pn=new ParseNode("literal");
518 pn.addChild("float").setLiteral(float_lit);
521 | BOOLEAN_LITERAL:boolean_lit
523 ParseNode pn=new ParseNode("literal");
524 pn.addChild("boolean").setLiteral(boolean_lit);
527 | CHARACTER_LITERAL:char_lit
529 ParseNode pn=new ParseNode("literal");
530 pn.addChild("char").setLiteral(char_lit);
533 | STRING_LITERAL:string_lit
535 ParseNode pn=new ParseNode("literal");
536 pn.addChild("string").setLiteral(string_lit);
541 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
545 // 19.4) Types, Values, and Variables
546 type ::= primitive_type:type {: RESULT=type; :}
547 | reference_type:type {: RESULT=type; :}
551 numeric_type:type {: RESULT=type; :}
552 | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
554 numeric_type::= integral_type:type {: RESULT=type; :}
555 | floating_point_type:type {: RESULT=type; :}
558 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
559 | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
560 | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
561 | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
562 | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
564 floating_point_type ::=
565 FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
566 | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
570 class_or_interface_type:type {: RESULT=type; :}
571 | array_type:type {: RESULT=type; :}
573 class_or_interface_type ::= name:name {:
574 RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot();
577 class_type ::= class_or_interface_type:type {: RESULT=type; :};
578 interface_type ::= class_or_interface_type:type {: RESULT=type; :};
580 array_type ::= primitive_type:prim dims:dims {:
581 ParseNode pn=(new ParseNode("type")).addChild("array");
582 pn.addChild("basetype").addChild(prim);
583 pn.addChild("dims").setLiteral(dims);
586 | name:name dims:dims {:
587 ParseNode pn=(new ParseNode("type")).addChild("array");
588 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
589 pn.addChild("dims").setLiteral(dims);
595 name ::= simple_name:name {: RESULT=name; :}
596 | qualified_name:name {: RESULT=name; :}
598 simple_name ::= IDENTIFIER:id {:
599 RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot();
602 qualified_name ::= name:name DOT IDENTIFIER:id {:
603 ParseNode pn=new ParseNode("name");
604 pn.addChild("base").addChild(name);
605 pn.addChild("identifier").addChild(id);
612 package_declaration_opt:pdo
613 import_declarations_opt:ido
614 type_declarations_opt:tdo {:
615 ParseNode pn=new ParseNode("compilation_unit");
617 pn.addChild("packages").addChild(pdo);
618 pn.addChild("imports").addChild(ido);
622 package_declaration_opt ::= package_declaration:pdo {:
625 {: RESULT=new ParseNode("empty"); :}
628 import_declarations_opt ::= import_declarations:ido {:
631 {: RESULT=new ParseNode("empty"); :}
633 type_declarations_opt ::= type_declarations:tds {:
636 {: RESULT=new ParseNode("empty"); :}
639 import_declarations ::=
640 import_declaration:id {:
641 ParseNode pn=new ParseNode("import_decls_list");
645 | import_declarations:ids import_declaration:id {:
651 type_declarations ::=
652 type_declaration:td {:
653 ParseNode pn=new ParseNode("type_declaration_list");
657 | type_declarations:tds type_declaration:td {:
663 package_declaration ::=
664 PACKAGE name:name SEMICOLON {:
665 ParseNode pn=new ParseNode("package");
670 import_declaration ::=
671 single_type_import_declaration:sid {: RESULT=sid; :}
672 | type_import_on_demand_declaration:iod {: RESULT=iod; :}
674 single_type_import_declaration ::=
675 IMPORT name:name SEMICOLON {:
676 ParseNode pn=new ParseNode("import_single");
681 type_import_on_demand_declaration ::=
682 IMPORT name:name DOT MULT SEMICOLON {:
683 ParseNode pn=new ParseNode("import_ondemand");
694 | enum_declaration:ed
698 | task_declaration:td
702 | interface_declaration:in
706 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
709 // 19.7) Productions used only in the LALR(1) grammar
711 {: RESULT=new ParseNode("empty"); :}
716 modifiers ::= modifier:mo {:
717 ParseNode pn=new ParseNode("modifier_list");
721 | modifiers:mos modifier:mo {:
727 PUBLIC {: RESULT=new ParseNode("public"); :}|
728 PROTECTED {: RESULT=new ParseNode("protected"); :}|
729 PRIVATE {: RESULT=new ParseNode("private"); :}|
730 STATIC {: RESULT=new ParseNode("static"); :} |
731 ABSTRACT {: RESULT=new ParseNode("abstract"); :} |
732 FINAL {: RESULT=new ParseNode("final"); :}|
733 NATIVE {: RESULT=new ParseNode("native"); :} |
734 SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
735 ATOMIC {: RESULT=new ParseNode("atomic"); :} |
736 VOLATILE {: RESULT=new ParseNode("volatile"); :}
739 // STRICTFP // note that semantic analysis must check that the
740 // context of the modifier allows strictfp.
745 // 19.8.1) Class Declaration:
746 class_declaration ::=
747 modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo
750 ParseNode pn=new ParseNode("class_declaration");
751 pn.addChild("modifiers").addChild(mo);
752 pn.addChild("name").addChild(id);
753 pn.addChild("super").addChild(so);
754 pn.addChild("superIF").addChild(ifo);
755 pn.addChild("classbody").addChild(body);
759 super ::= EXTENDS class_type:classtype {:
764 {: RESULT=new ParseNode("empty"); :}
770 interfaces ::= IMPLEMENTS interface_type_list:iftl {: RESULT=iftl; :}
773 {: RESULT=new ParseNode("empty"); :}
774 | interfaces:ifs {: RESULT=ifs; :}
776 interface_type_list ::=
777 interface_type:ift {:
778 ParseNode pn=new ParseNode("interface_type_list");
782 | interface_type_list:iftl COMMA interface_type:ift {:
788 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
791 class_body_declarations_opt ::=
792 {: RESULT=new ParseNode("empty"); :}
793 | class_body_declarations:cbd {: RESULT=cbd; :};
795 class_body_declarations ::=
796 class_body_declaration:cbd {:
797 ParseNode pn=new ParseNode("class_body_declaration_list");
801 | class_body_declarations:cbds class_body_declaration:cbd {:
807 class_body_declaration ::=
808 class_member_declaration:member {:
809 RESULT=(new ParseNode("member")).addChild(member).getRoot();
811 | static_initializer:block{:
812 RESULT=(new ParseNode("static_block")).addChild(block).getRoot();
814 | constructor_declaration:constructor {:
815 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
818 RESULT=(new ParseNode("block")).addChild(block).getRoot();
821 class_member_declaration ::=
822 //failure aware computation
823 flag_declaration:flag {:
824 RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
827 field_declaration:field {:
828 RESULT=(new ParseNode("field")).addChild(field).getRoot();
830 | method_declaration:method {:
831 RESULT=(new ParseNode("method")).addChild(method).getRoot();
833 /* repeat the prod for 'class_declaration' here: */
834 | modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo class_body:body
836 ParseNode pn=new ParseNode("inner_class_declaration");
837 pn.addChild("modifiers").addChild(mo);
838 pn.addChild("name").addChild(id);
839 pn.addChild("super").addChild(so);
840 pn.addChild("superIF").addChild(ifo);
841 pn.addChild("classbody").addChild(body);
844 | enum_declaration:ed
848 // | interface_declaration:interfaced {:
849 // RESULT=(new ParseNode("interface")).addChild(interfaced).getRoot();
851 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
855 // JSR-201) Enum Declaration
857 modifiers_opt:mo ENUM IDENTIFIER:id /*interfaces_opt:io*/ enum_body:body
859 ParseNode pn=new ParseNode("enum_declaration");
860 pn.addChild("modifiers").addChild(mo);
861 pn.addChild("name").addChild(id);
862 //pn.addChild("superIF").addChild(ifo);
863 pn.addChild("enumbody").addChild(body);
868 LBRACE enum_constants_opt:eco /*enum_body_declarations_opt:ebdo*/ RBRACE
871 enum_constants_opt ::=
872 {: RESULT=new ParseNode("empty"); :}
878 ParseNode pn=new ParseNode("enum_constants_list");
882 | enum_constants:ecs COMMA enum_constant:ec {:
888 IDENTIFIER:id /*enum_arguments_opt*/
890 ParseNode pn=new ParseNode("enum_constant");
891 pn.addChild("name").addChild(id);
894 // | IDENTIFIER enum_arguments_opt class_body
896 //enum_arguments_opt ::=
897 // | LPAREN argument_list_opt RPAREN
899 //enum_body_declarations_opt ::=
900 // | SEMICOLON class_body_declarations_opt:cbdo
904 //Failure aware computation
906 FLAG IDENTIFIER:id SEMICOLON {:
907 ParseNode pn=new ParseNode("flag_declaration");
908 pn.addChild("name").addChild(id);
911 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {:
912 ParseNode pn=new ParseNode("flag_declaration");
913 pn.addChild("name").addChild(id);
914 pn.addChild("external");
919 // 19.8.2) Field Declarations
920 field_declaration ::=
921 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {:
922 ParseNode pn=new ParseNode("field_declaration");
923 pn.addChild("modifier").addChild(mo);
924 pn.addChild("type").addChild(type);
925 pn.addChild("variables").addChild(var);
928 modifiers_opt:mo GLOBAL type:type variable_declarators:var SEMICOLON {:
929 ParseNode pn=new ParseNode("field_declaration");
930 pn.addChild("modifier").addChild(mo);
931 pn.addChild("type").addChild(type);
932 pn.addChild("variables").addChild(var);
933 pn.addChild("global");
938 variable_declarators ::=
939 variable_declarator:vd {:
940 ParseNode pn=new ParseNode("variable_declarators_list");
944 | variable_declarators:vds COMMA variable_declarator:vd {:
949 variable_declarator ::=
950 variable_declarator_id:id {:
951 ParseNode pn=new ParseNode("variable_declarator");
955 | variable_declarator_id:id EQ variable_initializer:init {:
956 ParseNode pn=new ParseNode("variable_declarator");
958 pn.addChild("initializer").addChild(init);
962 variable_declarator_id ::=
964 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
965 | variable_declarator_id:id LBRACK RBRACK {:
966 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
968 variable_initializer ::=
969 expression:exp {: RESULT=exp; :}
970 | array_initializer {: RESULT=new ParseNode("array_initializer"); :}
973 // 19.8.3) Method Declarations
974 method_declaration ::=
975 method_header:header method_body:body {:
976 ParseNode pn=new ParseNode("method_declaration");
978 pn.addChild("body").addChild(body);
983 modifiers_opt:mo type:type method_declarator:decl //throws_opt
985 ParseNode pn=new ParseNode("method_header");
986 pn.addChild("modifiers").addChild(mo);
987 pn.addChild("returntype").addChild(type);
991 | modifiers_opt:mo VOID method_declarator:decl //throws_opt
993 ParseNode pn=new ParseNode("method_header");
994 pn.addChild("modifiers").addChild(mo);
999 method_declarator ::=
1000 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {:
1001 ParseNode pn=new ParseNode("method_declarator");
1002 pn.addChild("name").addChild(id);
1003 pn.addChild("parameters").addChild(params);
1006 // | method_declarator LBRACK RBRACK // deprecated
1007 // be careful; the above production also allows 'void foo() []'
1009 formal_parameter_list_opt ::=
1010 {: RESULT=new ParseNode("empty"); :}
1011 | formal_parameter_list:fpl {:
1015 formal_parameter_list ::=
1016 formal_parameter:fp {:
1017 ParseNode pn=new ParseNode("formal_parameter_list");
1021 | formal_parameter_list:fpl COMMA formal_parameter:fp {:
1026 formal_parameter ::=
1027 type:type variable_declarator_id:name {:
1028 ParseNode pn=new ParseNode("formal_parameter");
1034 TAG variable_declarator_id:name {:
1035 ParseNode pn=new ParseNode("tag_parameter");
1039 | FINAL type:type variable_declarator_id:name {:
1040 ParseNode pn=new ParseNode("formal_parameter");
1049 //throws ::= THROWS class_type_list
1051 //class_type_list ::=
1053 // | class_type_list COMMA class_type
1055 method_body ::= block:block {:
1058 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
1061 // 19.8.4) Static Initializers
1062 static_initializer ::=
1063 STATIC block:body {:
1064 ParseNode pn=new ParseNode("static_block_declaration");
1065 pn.addChild("body").addChild(body);
1070 // 19.8.5) Constructor Declarations
1071 constructor_declaration ::=
1072 modifiers_opt:mo constructor_declarator:cd
1074 constructor_body:body {:
1075 ParseNode pn=new ParseNode("constructor_declaration");
1076 pn.addChild("modifiers").addChild(mo);
1078 pn.addChild("body").addChild(body);
1081 modifiers_opt:mo GLOBAL constructor_declarator:cd
1083 constructor_body:body {:
1084 ParseNode pn=new ParseNode("constructor_declaration");
1085 pn.addChild("global");
1086 pn.addChild("modifiers").addChild(mo);
1088 pn.addChild("body").addChild(body);
1093 constructor_declarator ::=
1094 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {:
1095 ParseNode pn=new ParseNode("constructor_declarator");
1097 pn.addChild("parameters").addChild(fplo);
1101 constructor_body ::=
1102 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {:
1103 ParseNode pn=new ParseNode("constructor_body");
1108 LBRACE explicit_constructor_invocation:eci RBRACE {:
1109 ParseNode pn=new ParseNode("constructor_body");
1113 LBRACE block_statements:block RBRACE {:
1114 ParseNode pn=new ParseNode("constructor_body");
1118 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1120 explicit_constructor_invocation ::=
1121 THIS LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1122 ParseNode pn=new ParseNode("explconstrinv");
1127 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1128 ParseNode pn=new ParseNode("superinvoke");
1132 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1133 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1138 // 19.9.1) Interface Declarations
1139 interface_declaration ::=
1140 modifiers_opt:mo INTERFACE IDENTIFIER:id extends_interfaces_opt:io
1143 ParseNode pn=new ParseNode("interface_declaration");
1144 pn.addChild("modifiers").addChild(mo);
1145 pn.addChild("name").addChild(id);
1146 pn.addChild("superIF").addChild(io);
1147 pn.addChild("interfacebody").addChild(body);
1151 extends_interfaces_opt ::=
1152 {: RESULT=new ParseNode("empty"); :}
1153 | extends_interfaces:eifs {: RESULT=eifs; :}
1155 extends_interfaces ::=
1156 EXTENDS interface_type:ift
1158 ParseNode pn=new ParseNode("extend_interface_list");
1162 | extends_interfaces:eifs COMMA interface_type:ift
1169 LBRACE interface_member_declarations_opt:imdo RBRACE
1172 interface_member_declarations_opt ::=
1173 {: RESULT=new ParseNode("empty"); :}
1174 | interface_member_declarations:imd {: RESULT=imd; :}
1176 interface_member_declarations ::=
1177 interface_member_declaration:imd {:
1178 ParseNode pn=new ParseNode("interface_member_declaration_list");
1182 | interface_member_declarations:imds interface_member_declaration:imd {:
1187 interface_member_declaration ::=
1188 constant_declaration:constant {:
1189 RESULT=(new ParseNode("constant")).addChild(constant).getRoot();
1191 | abstract_method_declaration:method {:
1192 RESULT=(new ParseNode("method")).addChild(method).getRoot();
1194 | enum_declaration:ed {:
1195 RESULT=(new ParseNode("enum_declaration")).addChild(ed).getRoot();
1197 // | class_declaration:class
1198 // | interface_declaration:interface
1200 RESULT=new ParseNode("empty");
1203 constant_declaration ::=
1204 field_declaration:fd {: RESULT=fd; :}
1205 // need to semantically check that modifiers of field declaration
1206 // include only PUBLIC, STATIC, or FINAL. Other modifiers are
1209 abstract_method_declaration ::=
1210 method_header:header SEMICOLON {:
1211 ParseNode pn=new ParseNode("method_declaration");
1212 pn.addChild("header").addChild(header);
1213 pn.addChild("body").addChild(new ParseNode("empty"));
1220 array_initializer ::=
1221 LBRACE variable_initializers:var_init_list COMMA RBRACE {:
1222 RESULT=var_init_list;
1224 | LBRACE variable_initializers:var_init_list RBRACE {:
1225 RESULT=var_init_list;
1227 | LBRACE COMMA RBRACE {:
1228 RESULT=new ParseNode("empty");
1231 RESULT=new ParseNode("empty");
1234 variable_initializers ::=
1235 variable_initializer:var_init {:
1236 ParseNode pn=new ParseNode("var_init_list");
1237 pn.addChild(var_init);
1240 | variable_initializers:var_init_list COMMA variable_initializer:var_init {:
1241 var_init_list.addChild(var_init);
1242 RESULT=var_init_list;
1246 // 19.11) Blocks and Statements
1247 block ::= LBRACE block_statements_opt:bso RBRACE {:
1251 block_statements_opt ::=
1252 {: RESULT=new ParseNode("empty"); :}
1253 | block_statements:bs {:
1257 block_statements ::=
1258 block_statement:bs {:
1259 ParseNode pn=new ParseNode("block_statement_list");
1263 | block_statements:bss block_statement:bs {:
1269 tag_variable_declaration_statement:tvds {:
1272 | local_variable_declaration_statement:lvds {:
1275 | statement:statement {:
1278 // | enum_declaration:ed {:
1281 // | class_declaration
1282 // | interface_declaration
1284 tag_variable_declaration_statement ::=
1285 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
1286 ParseNode pn=new ParseNode("tag_declaration");
1287 pn.addChild("single").addChild(id);
1288 pn.addChild("type").addChild(type);
1292 local_variable_declaration_statement ::=
1293 local_variable_declaration:lvd SEMICOLON {:
1297 local_variable_declaration ::=
1298 type:type variable_declarators:var {:
1299 ParseNode pn=new ParseNode("local_variable_declaration");
1304 | FINAL type:type variable_declarators:var {:
1305 ParseNode pn=new ParseNode("local_variable_declaration");
1311 statement ::= statement_without_trailing_substatement:st {:
1314 // | labeled_statement:st {: RESULT=st; :}
1315 | if_then_statement:st {: RESULT=st; :}
1316 | if_then_else_statement:st {: RESULT=st; :}
1317 | while_statement:st {: RESULT=st; :}
1318 | for_statement:st {: RESULT=st; :}
1320 statement_no_short_if ::=
1321 statement_without_trailing_substatement:st {: RESULT=st; :}
1322 // | labeled_statement_no_short_if:st {: RESULT=st; :}
1323 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
1324 | while_statement_no_short_if:st {: RESULT=st; :}
1325 | for_statement_no_short_if:st {: RESULT=st; :}
1327 statement_without_trailing_substatement ::=
1328 block:st {: RESULT=st; :}
1329 | empty_statement:st {: RESULT=st; :}
1330 | expression_statement:st {: RESULT=st; :}
1331 | switch_statement:st {: RESULT=st; :}
1332 | do_statement:dos {:RESULT=dos; :}
1333 | break_statement:st {: RESULT=st; :}
1334 | continue_statement:st {: RESULT=st; :}
1335 | return_statement:st {: RESULT=st; :}
1336 | task_exitstatement:st {: RESULT=st; :}
1337 | atomic_statement:st {: RESULT=st; :}
1338 | sese_statement:st {: RESULT=st; :}
1339 | synchronized_statement:st {: RESULT=st; :}
1340 | genreach_statement:st {: RESULT=st; :}
1341 // | throw_statement
1343 // | assert_statement
1346 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1348 //labeled_statement ::=
1349 // IDENTIFIER COLON statement
1351 //labeled_statement_no_short_if ::=
1352 // IDENTIFIER COLON statement_no_short_if
1354 expression_statement ::=
1355 statement_expression:se SEMICOLON {:
1356 ParseNode pn=new ParseNode("expression");
1360 statement_expression ::=
1361 assignment:st {: RESULT=st; :}
1362 | preincrement_expression:st {: RESULT=st; :}
1363 | predecrement_expression:st {: RESULT=st; :}
1364 | postincrement_expression:st {: RESULT=st; :}
1365 | postdecrement_expression:st {: RESULT=st; :}
1366 | method_invocation:st {: RESULT=st; :}
1367 | class_instance_creation_expression:st {: RESULT=st; :}
1369 if_then_statement ::=
1370 IF LPAREN expression:exp RPAREN statement:st {:
1371 ParseNode pn=new ParseNode("ifstatement");
1372 pn.addChild("condition").addChild(exp);
1373 pn.addChild("statement").addChild(st);
1377 if_then_else_statement ::=
1378 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1379 ELSE statement:else_st {:
1380 ParseNode pn=new ParseNode("ifstatement");
1381 pn.addChild("condition").addChild(exp);
1382 pn.addChild("statement").addChild(st);
1383 pn.addChild("else_statement").addChild(else_st);
1387 if_then_else_statement_no_short_if ::=
1388 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1389 ELSE statement_no_short_if:else_st {:
1390 ParseNode pn=new ParseNode("ifstatement");
1391 pn.addChild("condition").addChild(exp);
1392 pn.addChild("statement").addChild(st);
1393 pn.addChild("else_statement").addChild(else_st);
1397 switch_statement ::=
1398 SWITCH LPAREN expression:exp RPAREN switch_block:body
1400 ParseNode pn=new ParseNode("switch_statement");
1401 pn.addChild("condition").addChild(exp);
1402 pn.addChild("statement").addChild(body);
1407 LBRACE switch_block_statement_groups:sbsg switch_labels:sl RBRACE
1409 ParseNode pn = new ParseNode("switch_block");
1410 pn.addChild("switch_labels").addChild(sl);
1411 pn.addChild("switch_statements").addChild(new ParseNode("empty"));
1415 | LBRACE switch_block_statement_groups:sbsg RBRACE
1419 | LBRACE switch_labels:sl RBRACE
1421 ParseNode pnb = new ParseNode("switch_block_list");
1422 ParseNode pn = new ParseNode("switch_block");
1423 pn.addChild("switch_labels").addChild(sl);
1424 pn.addChild("switch_statements").addChild(new ParseNode("empty"));
1428 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1430 switch_block_statement_groups ::=
1431 switch_block_statement_group:sbsg
1433 ParseNode pn = new ParseNode("switch_block_list");
1437 | switch_block_statement_groups:sbsgs switch_block_statement_group:sbsg
1439 sbsgs.addChild(sbsg);
1443 switch_block_statement_group ::=
1444 switch_labels:sls block_statements:body
1446 ParseNode pn=new ParseNode("switch_block");
1447 pn.addChild("switch_labels").addChild(sls);
1448 pn.addChild("switch_statements").addChild(body);
1455 ParseNode pn=new ParseNode("switch_label_list");
1459 | switch_labels:sls switch_label:sl
1466 CASE constant_expression:ce COLON
1468 ParseNode pn=new ParseNode("switch_label");
1474 RESULT=new ParseNode("default_switch_label");
1479 WHILE LPAREN expression:exp RPAREN statement:st {:
1480 ParseNode pn=new ParseNode("whilestatement");
1481 pn.addChild("condition").addChild(exp);
1482 pn.addChild("statement").addChild(st);
1486 while_statement_no_short_if ::=
1487 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1488 ParseNode pn=new ParseNode("whilestatement");
1489 pn.addChild("condition").addChild(exp);
1490 pn.addChild("statement").addChild(st);
1495 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1496 ParseNode pn=new ParseNode("dowhilestatement");
1497 pn.addChild("condition").addChild(exp);
1498 pn.addChild("statement").addChild(st);
1503 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1504 for_update_opt:update RPAREN statement:st {:
1505 ParseNode pn=new ParseNode("forstatement");
1506 pn.addChild("initializer").addChild(init);
1507 pn.addChild("condition").addChild(exp);
1508 pn.addChild("update").addChild(update);
1509 pn.addChild("statement").addChild(st);
1513 for_statement_no_short_if ::=
1514 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1515 for_update_opt:update RPAREN statement_no_short_if:st {:
1516 ParseNode pn=new ParseNode("forstatement");
1517 pn.addChild("initializer").addChild(init);
1518 pn.addChild("condition").addChild(exp);
1519 pn.addChild("update").addChild(update);
1520 pn.addChild("statement").addChild(st);
1525 {: RESULT=new ParseNode("empty"); :}
1526 | for_init:init {: RESULT=init; :}
1528 for_init ::= statement_expression_list:list {: RESULT=list; :}
1529 | local_variable_declaration:decl {: RESULT=decl; :}
1532 {: RESULT=new ParseNode("empty"); :}
1533 | for_update:update {: RESULT=update; :}
1535 for_update ::= statement_expression_list:list {: RESULT=list; :}
1537 statement_expression_list ::=
1538 statement_expression:expr {:
1539 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1541 | statement_expression_list:list COMMA statement_expression:expr {:
1542 list.addChild(expr);
1547 //identifier_opt ::=
1554 SEMICOLON {: RESULT=new ParseNode("break"); :}
1557 continue_statement ::=
1561 {: RESULT=new ParseNode("continue"); :}
1563 return_statement ::=
1564 RETURN expression_opt:exp SEMICOLON {:
1565 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1567 //throw_statement ::=
1568 // THROW expression SEMICOLON
1570 synchronized_statement ::=
1571 SYNCHRONIZED LPAREN expression:e RPAREN block:b {:
1572 ParseNode pn=new ParseNode("synchronized");
1573 pn.addChild("expr").addChild(e);
1574 pn.addChild("block").addChild(b);
1578 atomic_statement ::=
1580 RESULT=(new ParseNode("atomic")).addChild(blk).getRoot();
1585 ParseNode pn = new ParseNode("sese");
1586 pn.addChild("body").addChild(blk);
1589 | SESE variable_declarator_id:id block:blk {:
1590 ParseNode pn = new ParseNode("sese");
1591 pn.addChild("body").addChild(blk);
1592 pn.addChild("identifier").addChild(id);
1595 | RBLOCK block:blk {:
1596 ParseNode pn = new ParseNode("sese");
1597 pn.addChild("body").addChild(blk);
1600 | RBLOCK variable_declarator_id:id block:blk {:
1601 ParseNode pn = new ParseNode("sese");
1602 pn.addChild("body").addChild(blk);
1603 pn.addChild("identifier").addChild(id);
1608 // TRY block catches
1609 // | TRY block catches_opt finally
1614 //catches ::= catch_clause
1615 // | catches catch_clause
1618 // CATCH LPAREN formal_parameter RPAREN block
1620 //finally ::= FINALLY block
1622 //assert_statement ::=
1623 // ASSERT expression SEMICOLON
1624 // | ASSERT expression COLON expression SEMICOLON
1627 // 19.12) Expressions
1628 primary ::= primary_no_new_array:st {:
1630 // | array_creation_init:st {:
1633 | array_creation_uninit:st {:
1637 primary_no_new_array ::=
1638 literal:lit {: RESULT=lit; :}
1639 | THIS {: RESULT=new ParseNode("this"); :}
1640 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1641 | class_instance_creation_expression:exp {: RESULT=exp; :}
1642 | field_access:exp {: RESULT=exp; :}
1643 | method_invocation:exp {: RESULT=exp; :}
1644 | array_access:exp {: RESULT=exp; :}
1645 | ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {:
1646 ParseNode pn=new ParseNode("isavailable");
1650 // | primitive_type DOT CLASS
1652 // | array_type DOT CLASS
1656 class_instance_creation_expression ::=
1657 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1658 ParseNode pn=new ParseNode("createobject");
1665 | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1666 ParseNode pn=new ParseNode("createobject");
1670 pn.addChild("global");
1673 | SCRATCH NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1674 ParseNode pn=new ParseNode("createobject");
1678 pn.addChild("scratch");
1681 // Objects we want to track in disjointness analysis
1682 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1683 ParseNode pn=new ParseNode("createobject");
1687 pn.addChild("disjoint").addChild(id);
1690 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
1691 ParseNode pn=new ParseNode("createobject");
1697 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
1698 ParseNode pn=new ParseNode("createobject");
1706 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1707 // | primary DOT NEW IDENTIFIER
1708 // LPAREN argument_list_opt RPAREN {:
1711 // | primary DOT NEW IDENTIFIER
1712 // LPAREN argument_list_opt RPAREN class_body
1713 // | name DOT NEW IDENTIFIER
1714 // LPAREN argument_list_opt RPAREN
1715 // | name DOT NEW IDENTIFIER
1716 // LPAREN argument_list_opt RPAREN class_body
1718 cons_argument_list_opt ::=
1719 {: RESULT=new ParseNode("empty"); :}
1720 | cons_argument_list:args {: RESULT=args; :}
1723 cons_argument_list ::=
1724 IDENTIFIER:id COLON expression:exp {:
1725 ParseNode pn=new ParseNode("cons_argument_list");
1726 ParseNode pnarg=pn.addChild("binding");
1727 pnarg.addChild("var").addChild(id);
1728 pnarg.addChild("exp").addChild(exp);
1731 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1732 ParseNode pnarg=new ParseNode("binding");
1733 pnarg.addChild("var").addChild(id);
1734 pnarg.addChild("exp").addChild(exp);
1735 list.addChild(pnarg);
1740 argument_list_opt ::=
1741 {: RESULT=new ParseNode("empty"); :}
1742 | argument_list:args {: RESULT=args; :}
1747 ParseNode pn=new ParseNode("argument_list");
1751 | argument_list:list COMMA expression:exp {:
1756 array_creation_uninit ::=
1757 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1758 ParseNode pn=new ParseNode("createarray");
1760 pn.addChild(dimexpr);
1761 pn.addChild("dims_opt").setLiteral(dims);
1764 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1765 ParseNode pn=new ParseNode("createarray");
1767 pn.addChild(dimexpr);
1768 pn.addChild("dims_opt").setLiteral(dims);
1771 | GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1772 ParseNode pn=new ParseNode("createarray");
1774 pn.addChild(dimexpr);
1775 pn.addChild("dims_opt").setLiteral(dims);
1776 pn.addChild("global");
1779 | SCRATCH NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1780 ParseNode pn=new ParseNode("createarray");
1782 pn.addChild(dimexpr);
1783 pn.addChild("dims_opt").setLiteral(dims);
1784 pn.addChild("scratch");
1787 | DISJOINT IDENTIFIER:id NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1788 ParseNode pn=new ParseNode("createarray");
1790 pn.addChild(dimexpr);
1791 pn.addChild("dims_opt").setLiteral(dims);
1792 pn.addChild("disjoint").addChild(id);
1795 | GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1796 ParseNode pn=new ParseNode("createarray");
1798 pn.addChild(dimexpr);
1799 pn.addChild("dims_opt").setLiteral(dims);
1800 pn.addChild("global");
1803 | SCRATCH NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1804 ParseNode pn=new ParseNode("createarray");
1806 pn.addChild(dimexpr);
1807 pn.addChild("dims_opt").setLiteral(dims);
1808 pn.addChild("scratch");
1811 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1812 ParseNode pn=new ParseNode("createarray");
1814 pn.addChild(dimexpr);
1815 pn.addChild("dims_opt").setLiteral(dims);
1816 pn.addChild("disjoint").addChild(id);
1820 //array_creation_init ::=
1821 // NEW primitive_type dims array_initializer
1822 // | NEW class_or_interface_type dims array_initializer
1824 dim_exprs ::= dim_expr:exp {:
1825 ParseNode pn=new ParseNode("dim_exprs");
1828 | dim_exprs:base dim_expr:exp {:
1833 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1835 dims_opt ::= {: RESULT=new Integer(0); :}
1836 | dims:dims {: RESULT = dims; :}
1839 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1840 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1844 primary:base DOT IDENTIFIER:id {:
1845 ParseNode pn=new ParseNode("fieldaccess");
1846 pn.addChild("base").addChild(base);
1847 pn.addChild("field").addChild(id);
1850 // | SUPER DOT IDENTIFIER
1851 // | name DOT SUPER DOT IDENTIFIER
1853 method_invocation ::=
1854 name:name LPAREN argument_list_opt:args RPAREN {:
1855 ParseNode pn=new ParseNode("methodinvoke1");
1860 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1861 ParseNode pn=new ParseNode("methodinvoke2");
1862 pn.addChild("base").addChild(base);
1863 pn.addChild("id").addChild(name);
1867 | SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {:
1868 ParseNode name=new ParseNode("name");
1869 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
1870 name.addChild("identifier").addChild(id);
1871 ParseNode pn=new ParseNode("methodinvoke1");
1876 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1879 name:name LBRACK expression:exp RBRACK {:
1880 ParseNode pn=new ParseNode("arrayaccess");
1881 pn.addChild("base").addChild(name);
1882 pn.addChild("index").addChild(exp);
1885 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1886 ParseNode pn=new ParseNode("arrayaccess");
1887 pn.addChild("base").addChild(base);
1888 pn.addChild("index").addChild(exp);
1891 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1892 // ParseNode pn=new ParseNode("arrayaccess");
1893 // pn.addChild("init").addChild(init);
1894 // pn.addChild("index").addChild(exp);
1899 postfix_expression ::=
1902 | name:exp {: RESULT=exp; :}
1903 | postincrement_expression:exp {: RESULT=exp; :}
1904 | postdecrement_expression:exp {: RESULT=exp; :}
1906 postincrement_expression ::=
1907 postfix_expression:exp PLUSPLUS
1908 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1910 postdecrement_expression ::=
1911 postfix_expression:exp MINUSMINUS
1912 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1914 unary_expression ::=
1915 preincrement_expression:exp {: RESULT=exp; :}
1916 | predecrement_expression:exp {: RESULT=exp; :}
1917 | PLUS unary_expression:exp
1918 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1919 | MINUS unary_expression:exp
1920 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1921 | unary_expression_not_plus_minus:exp {:
1924 preincrement_expression ::=
1925 PLUSPLUS unary_expression:exp
1926 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1928 predecrement_expression ::=
1929 MINUSMINUS unary_expression:exp
1930 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1932 unary_expression_not_plus_minus ::=
1933 postfix_expression:exp {:
1935 | COMP unary_expression:exp
1936 {: RESULT=(new ParseNode("comp")).addChild(exp).getRoot(); :}
1937 | NOT unary_expression:exp
1938 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1939 | cast_expression:exp {: RESULT=exp; :}
1942 LPAREN primitive_type:type dims_opt:dims
1943 RPAREN unary_expression:exp {:
1944 ParseNode pn=new ParseNode("cast1");
1945 if (dims.intValue()==0)
1946 pn.addChild("type").addChild(type);
1948 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
1949 arrayt.addChild("basetype").addChild(type);
1950 arrayt.addChild("dims").setLiteral(dims);
1952 pn.addChild("exp").addChild(exp);
1955 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
1956 ParseNode pn=new ParseNode("cast2");
1957 pn.addChild("type").addChild(type);
1958 pn.addChild("exp").addChild(exp);
1962 // | LPAREN name dims RPAREN unary_expression_not_plus_minus
1964 multiplicative_expression ::=
1965 unary_expression:exp {:
1967 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
1968 ParseNode pn=new ParseNode("mult");
1973 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1974 ParseNode pn=new ParseNode("div");
1979 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1980 ParseNode pn=new ParseNode("mod");
1986 additive_expression ::=
1987 multiplicative_expression:exp {:
1989 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
1990 ParseNode pn=new ParseNode("add");
1995 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
1996 ParseNode pn=new ParseNode("sub");
2002 shift_expression ::=
2003 additive_expression:exp {:
2005 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
2006 ParseNode pn=new ParseNode("leftshift");
2011 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
2012 ParseNode pn=new ParseNode("rightshift");
2017 | shift_expression:exp1 URSHIFT additive_expression:exp2 {:
2018 ParseNode pn=new ParseNode("urightshift");
2024 relational_expression ::=
2025 shift_expression:exp {:
2027 | relational_expression:exp1 LT shift_expression:exp2 {:
2028 ParseNode pn=new ParseNode("comp_lt");
2033 | relational_expression:exp1 GT shift_expression:exp2 {:
2034 ParseNode pn=new ParseNode("comp_gt");
2039 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
2040 ParseNode pn=new ParseNode("comp_lte");
2045 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
2046 ParseNode pn=new ParseNode("comp_gte");
2051 | relational_expression:exp INSTANCEOF reference_type:type {:
2052 ParseNode pn=new ParseNode("instanceof");
2053 pn.addChild("exp").addChild(exp);
2059 equality_expression ::=
2060 relational_expression:exp {:
2062 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
2063 ParseNode pn=new ParseNode("equal");
2068 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
2069 ParseNode pn=new ParseNode("not_equal");
2076 equality_expression:exp {:
2078 | and_expression:exp1 AND equality_expression:exp2 {:
2079 ParseNode pn=new ParseNode("bitwise_and");
2085 exclusive_or_expression ::=
2086 and_expression:expr {:
2089 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
2090 ParseNode pn=new ParseNode("bitwise_xor");
2096 inclusive_or_expression ::=
2097 exclusive_or_expression:exclor {:
2099 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
2100 ParseNode pn=new ParseNode("bitwise_or");
2106 conditional_and_expression ::=
2107 inclusive_or_expression:inclor {:
2109 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
2110 ParseNode pn=new ParseNode("logical_and");
2116 conditional_or_expression ::=
2117 conditional_and_expression:condand {:
2119 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
2120 ParseNode pn=new ParseNode("logical_or");
2126 conditional_expression ::=
2127 conditional_or_expression:condor {:
2129 | conditional_or_expression:condor QUESTION expression:exptrue
2130 COLON conditional_expression:expfalse {:
2131 ParseNode pn=new ParseNode("tert");
2132 pn.addChild("cond").addChild(condor);
2133 pn.addChild("trueexpr").addChild(exptrue);
2134 pn.addChild("falseexpr").addChild(expfalse);
2138 getoffset_expression ::=
2139 GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
2140 ParseNode pn = new ParseNode("getoffset");
2142 pn.addChild("field").addChild(id);
2147 assignment_expression ::=
2148 conditional_expression:expr {:
2150 assignment:assign {:
2152 getoffset_expression:expr {:
2155 // semantic check necessary here to ensure a valid left-hand side.
2156 // allowing a parenthesized variable here on the lhs was introduced in
2157 // JLS 2; thanks to Eric Blake for pointing this out.
2158 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
2159 ParseNode pn=new ParseNode("assignment");
2160 pn.addChild("op").addChild(op);
2161 ParseNode pnargs=pn.addChild("args");
2162 pnargs.addChild(lvalue);
2163 pnargs.addChild(rvalue);
2167 assignment_operator ::=
2168 EQ {: RESULT=new ParseNode("eq"); :}
2169 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
2170 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
2171 | MODEQ {: RESULT=new ParseNode("modeq"); :}
2172 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
2173 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
2174 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
2175 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
2176 | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
2177 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
2178 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
2179 | OREQ {: RESULT=new ParseNode("oreq"); :}
2182 {: RESULT=new ParseNode("empty"); :}
2186 expression ::= assignment_expression:exp {:
2189 // note that this constraint must be enforced during semantic checking
2190 // 'constant_expression' should include enumerated constants.
2191 constant_expression ::=
2194 ParseNode pn = new ParseNode("constant_expression");
2201 genreach_statement ::=
2202 GENREACH IDENTIFIER:graphName SEMICOLON {:
2203 ParseNode pn=new ParseNode("genreach");
2204 pn.addChild("graphName").addChild(graphName);