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;
283 TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN
287 ParseNode pn=new ParseNode("task_declaration");
288 pn.addChild("name").addChild(id);
291 pn.addChild("body").addChild(body);
295 task_parameter_list ::=
297 ParseNode pn=new ParseNode("task_parameter_list");
301 | task_parameter_list:fpl COMMA task_parameter:fp {:
308 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
309 ParseNode pn=new ParseNode("task_parameter");
312 pn.addChild("flag").addChild(exp);
315 | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
316 ParseNode pn=new ParseNode("task_parameter");
319 pn.addChild("flag").addChild(exp);
320 pn.addChild("tag").addChild(texp);
323 | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
324 ParseNode pn=new ParseNode("task_parameter");
327 pn.addChild("tag").addChild(texp);
330 | OPTIONAL task_parameter:fp {:
331 ParseNode pn=new ParseNode("task_parameter");
332 pn.addChild("optional").addChild(fp);
338 tag_expression_list ::= tag_expression:te {:
339 ParseNode pn=new ParseNode("tag_expression_list");
343 | tag_expression_list:tel COMMA tag_expression:te {:
349 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {:
350 ParseNode pn=new ParseNode("tag_expression");
351 pn.addChild("type").addChild(type);
352 pn.addChild("single").addChild(id);
357 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
358 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
359 | {: RESULT = new ParseNode("empty"); :}
362 tag_list ::= tag_change:fc {:
363 ParseNode pn=new ParseNode("tag_list");
367 | tag_list:fl COMMA tag_change:fc {:
372 tag_change ::= IDENTIFIER:id {:
373 RESULT=new ParseNode("name").addChild(id).getRoot();
375 | NOT IDENTIFIER:id {:
376 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
380 flag_andexpression:exp {:
383 | flag_expression:exp1 OROR flag_andexpression:exp2 {:
384 ParseNode pn=new ParseNode("or");
391 flag_andexpression ::=
392 flag_notexpression:exp {: RESULT=exp; :}
393 | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {:
394 ParseNode pn=new ParseNode("and");
401 flag_notexpression ::=
402 NOT flag_notexpression:exp {:
403 ParseNode pn=new ParseNode("not");
407 | LPAREN flag_expression:exp RPAREN {:
411 ParseNode pn=new ParseNode("name");
417 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
418 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
421 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
422 | {: RESULT = new ParseNode("empty"); :}
425 cons_checks ::= cons_check:cc {:
426 ParseNode pn=new ParseNode("cons_checks");
430 | cons_checks:ccs COMMA cons_check:cc {:
435 cons_check ::= IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {:
436 ParseNode pn=new ParseNode("cons_check");
437 pn.addChild("name").addChild("identifier").addChild(name);
442 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
443 | {: RESULT = new ParseNode("empty"); :}
446 flag_effects ::= flag_effect:fe {:
447 ParseNode pn=new ParseNode("flag_effects_list");
451 | flag_effects:fes COMMA flag_effect:fe {:
456 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {:
457 ParseNode pn=new ParseNode("flag_effect");
458 pn.addChild("name").addChild(id);
463 | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
464 ParseNode pn=new ParseNode("flag_effect");
465 pn.addChild("name").addChild(id);
470 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
471 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
473 {: RESULT = new ParseNode("empty"); :}
476 flag_list ::= flag_change:fc {:
477 ParseNode pn=new ParseNode("flag_list");
481 | flag_list:fl COMMA flag_change:fc {:
486 flag_change ::= IDENTIFIER:id {:
487 RESULT=new ParseNode("name").addChild(id).getRoot();
490 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
493 // 19.2) The Syntactic Grammar
494 goal ::= compilation_unit:cu
500 // 19.3) Lexical Structure.
503 literal ::= INTEGER_LITERAL:integer_lit
505 ParseNode pn=new ParseNode("literal");
506 pn.addChild("integer").setLiteral(integer_lit);
509 | FLOATING_POINT_LITERAL:float_lit
511 ParseNode pn=new ParseNode("literal");
512 pn.addChild("float").setLiteral(float_lit);
515 | BOOLEAN_LITERAL:boolean_lit
517 ParseNode pn=new ParseNode("literal");
518 pn.addChild("boolean").setLiteral(boolean_lit);
521 | CHARACTER_LITERAL:char_lit
523 ParseNode pn=new ParseNode("literal");
524 pn.addChild("char").setLiteral(char_lit);
527 | STRING_LITERAL:string_lit
529 ParseNode pn=new ParseNode("literal");
530 pn.addChild("string").setLiteral(string_lit);
535 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
539 // 19.4) Types, Values, and Variables
540 type ::= primitive_type:type {: RESULT=type; :}
541 | reference_type:type {: RESULT=type; :}
545 numeric_type:type {: RESULT=type; :}
546 | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
548 numeric_type::= integral_type:type {: RESULT=type; :}
549 | floating_point_type:type {: RESULT=type; :}
552 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
553 | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
554 | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
555 | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
556 | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
558 floating_point_type ::=
559 FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
560 | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
564 class_or_interface_type:type {: RESULT=type; :}
565 | array_type:type {: RESULT=type; :}
567 class_or_interface_type ::= name:name {:
568 RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot();
571 class_type ::= class_or_interface_type:type {: RESULT=type; :};
572 interface_type ::= class_or_interface_type:type {: RESULT=type; :};
574 array_type ::= primitive_type:prim dims:dims {:
575 ParseNode pn=(new ParseNode("type")).addChild("array");
576 pn.addChild("basetype").addChild(prim);
577 pn.addChild("dims").setLiteral(dims);
580 | name:name dims:dims {:
581 ParseNode pn=(new ParseNode("type")).addChild("array");
582 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
583 pn.addChild("dims").setLiteral(dims);
589 name ::= simple_name:name {: RESULT=name; :}
590 | qualified_name:name {: RESULT=name; :}
592 simple_name ::= IDENTIFIER:id {:
593 RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot();
596 qualified_name ::= name:name DOT IDENTIFIER:id {:
597 ParseNode pn=new ParseNode("name");
598 pn.addChild("base").addChild(name);
599 pn.addChild("identifier").addChild(id);
606 package_declaration_opt:pdo
607 import_declarations_opt:ido
608 type_declarations_opt:tdo {:
609 ParseNode pn=new ParseNode("compilation_unit");
611 pn.addChild("packages").addChild(pdo);
612 pn.addChild("imports").addChild(ido);
616 package_declaration_opt ::= package_declaration:pdo {:
619 {: RESULT=new ParseNode("empty"); :}
622 import_declarations_opt ::= import_declarations:ido {:
625 {: RESULT=new ParseNode("empty"); :}
627 type_declarations_opt ::= type_declarations:tds {:
630 {: RESULT=new ParseNode("empty"); :}
633 import_declarations ::=
634 import_declaration:id {:
635 ParseNode pn=new ParseNode("import_decls_list");
639 | import_declarations:ids import_declaration:id {:
645 type_declarations ::=
646 type_declaration:td {:
647 ParseNode pn=new ParseNode("type_declaration_list");
651 | type_declarations:tds type_declaration:td {:
657 package_declaration ::=
658 PACKAGE name:name SEMICOLON {:
659 ParseNode pn=new ParseNode("package");
664 import_declaration ::=
665 single_type_import_declaration:sid {: RESULT=sid; :}
666 | type_import_on_demand_declaration:iod {: RESULT=iod; :}
668 single_type_import_declaration ::=
669 IMPORT name:name SEMICOLON {:
670 ParseNode pn=new ParseNode("import_single");
675 type_import_on_demand_declaration ::=
676 IMPORT name:name DOT MULT SEMICOLON {:
677 ParseNode pn=new ParseNode("import_ondemand");
688 | task_declaration:td
692 | interface_declaration:in
696 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
699 // 19.7) Productions used only in the LALR(1) grammar
701 {: RESULT=new ParseNode("empty"); :}
706 modifiers ::= modifier:mo {:
707 ParseNode pn=new ParseNode("modifier_list");
711 | modifiers:mos modifier:mo {:
717 PUBLIC {: RESULT=new ParseNode("public"); :}|
718 PROTECTED {: RESULT=new ParseNode("protected"); :}|
719 PRIVATE {: RESULT=new ParseNode("private"); :}|
720 STATIC {: RESULT=new ParseNode("static"); :} |
721 ABSTRACT {: RESULT=new ParseNode("abstract"); :} |
722 FINAL {: RESULT=new ParseNode("final"); :}|
723 NATIVE {: RESULT=new ParseNode("native"); :} |
724 SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
725 ATOMIC {: RESULT=new ParseNode("atomic"); :}
728 // STRICTFP // note that semantic analysis must check that the
729 // context of the modifier allows strictfp.
734 // 19.8.1) Class Declaration:
735 class_declaration ::=
736 modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo
739 ParseNode pn=new ParseNode("class_declaration");
740 pn.addChild("modifiers").addChild(mo);
741 pn.addChild("name").addChild(id);
742 pn.addChild("super").addChild(so);
743 pn.addChild("superIF").addChild(ifo);
744 pn.addChild("classbody").addChild(body);
748 super ::= EXTENDS class_type:classtype {:
753 {: RESULT=new ParseNode("empty"); :}
759 interfaces ::= IMPLEMENTS interface_type_list:iftl {: RESULT=iftl; :}
762 {: RESULT=new ParseNode("empty"); :}
763 | interfaces:ifs {: RESULT=ifs; :}
765 interface_type_list ::=
766 interface_type:ift {:
767 ParseNode pn=new ParseNode("interface_type_list");
771 | interface_type_list:iftl COMMA interface_type:ift {:
777 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
780 class_body_declarations_opt ::=
781 {: RESULT=new ParseNode("empty"); :}
782 | class_body_declarations:cbd {: RESULT=cbd; :};
784 class_body_declarations ::=
785 class_body_declaration:cbd {:
786 ParseNode pn=new ParseNode("class_body_declaration_list");
790 | class_body_declarations:cbds class_body_declaration:cbd {:
796 class_body_declaration ::=
797 class_member_declaration:member {:
798 RESULT=(new ParseNode("member")).addChild(member).getRoot();
800 | static_initializer:block{:
801 RESULT=(new ParseNode("static_block")).addChild(block).getRoot();
803 | constructor_declaration:constructor {:
804 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
807 RESULT=(new ParseNode("block")).addChild(block).getRoot();
810 class_member_declaration ::=
811 //failure aware computation
812 flag_declaration:flag {:
813 RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
816 field_declaration:field {:
817 RESULT=(new ParseNode("field")).addChild(field).getRoot();
819 | method_declaration:method {:
820 RESULT=(new ParseNode("method")).addChild(method).getRoot();
822 /* repeat the prod for 'class_declaration' here: */
823 // | modifiers_opt CLASS IDENTIFIER super_opt class_body
824 | interface_declaration:interfaced {:
825 RESULT=(new ParseNode("interface")).addChild(interfaced).getRoot();
827 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
830 //Failure aware computation
832 FLAG IDENTIFIER:id SEMICOLON {:
833 ParseNode pn=new ParseNode("flag_declaration");
834 pn.addChild("name").addChild(id);
837 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {:
838 ParseNode pn=new ParseNode("flag_declaration");
839 pn.addChild("name").addChild(id);
840 pn.addChild("external");
845 // 19.8.2) Field Declarations
846 field_declaration ::=
847 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {:
848 ParseNode pn=new ParseNode("field_declaration");
849 pn.addChild("modifier").addChild(mo);
850 pn.addChild("type").addChild(type);
851 pn.addChild("variables").addChild(var);
854 modifiers_opt:mo GLOBAL type:type variable_declarators:var SEMICOLON {:
855 ParseNode pn=new ParseNode("field_declaration");
856 pn.addChild("modifier").addChild(mo);
857 pn.addChild("type").addChild(type);
858 pn.addChild("variables").addChild(var);
859 pn.addChild("global");
864 variable_declarators ::=
865 variable_declarator:vd {:
866 ParseNode pn=new ParseNode("variable_declarators_list");
870 | variable_declarators:vds COMMA variable_declarator:vd {:
875 variable_declarator ::=
876 variable_declarator_id:id {:
877 ParseNode pn=new ParseNode("variable_declarator");
881 | variable_declarator_id:id EQ variable_initializer:init {:
882 ParseNode pn=new ParseNode("variable_declarator");
884 pn.addChild("initializer").addChild(init);
888 variable_declarator_id ::=
890 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
891 | variable_declarator_id:id LBRACK RBRACK {:
892 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
894 variable_initializer ::=
895 expression:exp {: RESULT=exp; :}
896 | array_initializer {: RESULT=new ParseNode("array_initializer"); :}
899 // 19.8.3) Method Declarations
900 method_declaration ::=
901 method_header:header method_body:body {:
902 ParseNode pn=new ParseNode("method_declaration");
904 pn.addChild("body").addChild(body);
909 modifiers_opt:mo type:type method_declarator:decl //throws_opt
911 ParseNode pn=new ParseNode("method_header");
912 pn.addChild("modifiers").addChild(mo);
913 pn.addChild("returntype").addChild(type);
917 | modifiers_opt:mo VOID method_declarator:decl //throws_opt
919 ParseNode pn=new ParseNode("method_header");
920 pn.addChild("modifiers").addChild(mo);
925 method_declarator ::=
926 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {:
927 ParseNode pn=new ParseNode("method_declarator");
928 pn.addChild("name").addChild(id);
929 pn.addChild("parameters").addChild(params);
932 // | method_declarator LBRACK RBRACK // deprecated
933 // be careful; the above production also allows 'void foo() []'
935 formal_parameter_list_opt ::=
936 {: RESULT=new ParseNode("empty"); :}
937 | formal_parameter_list:fpl {:
941 formal_parameter_list ::=
942 formal_parameter:fp {:
943 ParseNode pn=new ParseNode("formal_parameter_list");
947 | formal_parameter_list:fpl COMMA formal_parameter:fp {:
953 type:type variable_declarator_id:name {:
954 ParseNode pn=new ParseNode("formal_parameter");
960 TAG variable_declarator_id:name {:
961 ParseNode pn=new ParseNode("tag_parameter");
965 | FINAL type:type variable_declarator_id:name {:
966 ParseNode pn=new ParseNode("formal_parameter");
975 //throws ::= THROWS class_type_list
977 //class_type_list ::=
979 // | class_type_list COMMA class_type
981 method_body ::= block:block {:
984 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
987 // 19.8.4) Static Initializers
988 static_initializer ::=
990 ParseNode pn=new ParseNode("static_block_declaration");
991 pn.addChild("body").addChild(body);
996 // 19.8.5) Constructor Declarations
997 constructor_declaration ::=
998 modifiers_opt:mo constructor_declarator:cd
1000 constructor_body:body {:
1001 ParseNode pn=new ParseNode("constructor_declaration");
1002 pn.addChild("modifiers").addChild(mo);
1004 pn.addChild("body").addChild(body);
1007 modifiers_opt:mo GLOBAL constructor_declarator:cd
1009 constructor_body:body {:
1010 ParseNode pn=new ParseNode("constructor_declaration");
1011 pn.addChild("global");
1012 pn.addChild("modifiers").addChild(mo);
1014 pn.addChild("body").addChild(body);
1019 constructor_declarator ::=
1020 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {:
1021 ParseNode pn=new ParseNode("constructor_declarator");
1023 pn.addChild("parameters").addChild(fplo);
1027 constructor_body ::=
1028 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {:
1029 ParseNode pn=new ParseNode("constructor_body");
1034 LBRACE explicit_constructor_invocation:eci RBRACE {:
1035 ParseNode pn=new ParseNode("constructor_body");
1039 LBRACE block_statements:block RBRACE {:
1040 ParseNode pn=new ParseNode("constructor_body");
1044 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1046 explicit_constructor_invocation ::=
1047 THIS LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1048 ParseNode pn=new ParseNode("explconstrinv");
1053 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1054 ParseNode pn=new ParseNode("superinvoke");
1058 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1059 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1064 // 19.9.1) Interface Declarations
1065 interface_declaration ::=
1066 modifiers_opt:mo INTERFACE IDENTIFIER:id extends_interfaces_opt:io
1069 ParseNode pn=new ParseNode("interface_declaration");
1070 pn.addChild("modifiers").addChild(mo);
1071 pn.addChild("name").addChild(id);
1072 pn.addChild("superIF").addChild(io);
1073 pn.addChild("interfacebody").addChild(body);
1077 extends_interfaces_opt ::=
1078 {: RESULT=new ParseNode("empty"); :}
1079 | extends_interfaces:eifs {: RESULT=eifs; :}
1081 extends_interfaces ::=
1082 EXTENDS interface_type:ift
1084 ParseNode pn=new ParseNode("extend_interface_list");
1088 | extends_interfaces:eifs COMMA interface_type:ift
1095 LBRACE interface_member_declarations_opt:imdo RBRACE
1098 interface_member_declarations_opt ::=
1099 {: RESULT=new ParseNode("empty"); :}
1100 | interface_member_declarations:imd {: RESULT=imd; :}
1102 interface_member_declarations ::=
1103 interface_member_declaration:imd {:
1104 ParseNode pn=new ParseNode("interface_member_declaration_list");
1108 | interface_member_declarations:imds interface_member_declaration:imd {:
1113 interface_member_declaration ::=
1114 constant_declaration:constant {:
1115 RESULT=(new ParseNode("constant")).addChild(constant).getRoot();
1117 | abstract_method_declaration:method {:
1118 RESULT=(new ParseNode("method")).addChild(method).getRoot();
1120 // | class_declaration:class
1121 // | interface_declaration:interface
1123 RESULT=new ParseNode("empty");
1126 constant_declaration ::=
1127 field_declaration:fd {: RESULT=fd; :}
1128 // need to semantically check that modifiers of field declaration
1129 // include only PUBLIC, STATIC, or FINAL. Other modifiers are
1132 abstract_method_declaration ::=
1133 method_header:header SEMICOLON {:
1134 ParseNode pn=new ParseNode("method_declaration");
1135 pn.addChild("header").addChild(header);
1136 pn.addChild("body").addChild(new ParseNode("empty"));
1143 array_initializer ::=
1144 LBRACE variable_initializers:var_init_list COMMA RBRACE {:
1145 RESULT=var_init_list;
1147 | LBRACE variable_initializers:var_init_list RBRACE {:
1148 RESULT=var_init_list;
1150 | LBRACE COMMA RBRACE {:
1151 RESULT=new ParseNode("empty");
1154 RESULT=new ParseNode("empty");
1157 variable_initializers ::=
1158 variable_initializer:var_init {:
1159 ParseNode pn=new ParseNode("var_init_list");
1160 pn.addChild(var_init);
1163 | variable_initializers:var_init_list COMMA variable_initializer:var_init {:
1164 var_init_list.addChild(var_init);
1165 RESULT=var_init_list;
1169 // 19.11) Blocks and Statements
1170 block ::= LBRACE block_statements_opt:bso RBRACE {:
1174 block_statements_opt ::=
1175 {: RESULT=new ParseNode("empty"); :}
1176 | block_statements:bs {:
1180 block_statements ::=
1181 block_statement:bs {:
1182 ParseNode pn=new ParseNode("block_statement_list");
1186 | block_statements:bss block_statement:bs {:
1192 tag_variable_declaration_statement:tvds {:
1195 | local_variable_declaration_statement:lvds {:
1198 | statement:statement {:
1201 // | class_declaration
1202 // | interface_declaration
1204 tag_variable_declaration_statement ::=
1205 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
1206 ParseNode pn=new ParseNode("tag_declaration");
1207 pn.addChild("single").addChild(id);
1208 pn.addChild("type").addChild(type);
1212 local_variable_declaration_statement ::=
1213 local_variable_declaration:lvd SEMICOLON {:
1217 local_variable_declaration ::=
1218 type:type variable_declarators:var {:
1219 ParseNode pn=new ParseNode("local_variable_declaration");
1224 | FINAL type:type variable_declarators:var {:
1225 ParseNode pn=new ParseNode("local_variable_declaration");
1231 statement ::= statement_without_trailing_substatement:st {:
1234 // | labeled_statement:st {: RESULT=st; :}
1235 | if_then_statement:st {: RESULT=st; :}
1236 | if_then_else_statement:st {: RESULT=st; :}
1237 | while_statement:st {: RESULT=st; :}
1238 | for_statement:st {: RESULT=st; :}
1240 statement_no_short_if ::=
1241 statement_without_trailing_substatement:st {: RESULT=st; :}
1242 // | labeled_statement_no_short_if:st {: RESULT=st; :}
1243 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
1244 | while_statement_no_short_if:st {: RESULT=st; :}
1245 | for_statement_no_short_if:st {: RESULT=st; :}
1247 statement_without_trailing_substatement ::=
1248 block:st {: RESULT=st; :}
1249 | empty_statement:st {: RESULT=st; :}
1250 | expression_statement:st {: RESULT=st; :}
1251 // | switch_statement
1252 | do_statement:dos {:RESULT=dos; :}
1253 | break_statement:st {: RESULT=st; :}
1254 | continue_statement:st {: RESULT=st; :}
1255 | return_statement:st {: RESULT=st; :}
1256 | task_exitstatement:st {: RESULT=st; :}
1257 | atomic_statement:st {: RESULT=st; :}
1258 | sese_statement:st {: RESULT=st; :}
1259 | synchronized_statement:st {: RESULT=st; :}
1260 | genreach_statement:st {: RESULT=st; :}
1261 // | throw_statement
1263 // | assert_statement
1266 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1268 //labeled_statement ::=
1269 // IDENTIFIER COLON statement
1271 //labeled_statement_no_short_if ::=
1272 // IDENTIFIER COLON statement_no_short_if
1274 expression_statement ::=
1275 statement_expression:se SEMICOLON {:
1276 ParseNode pn=new ParseNode("expression");
1280 statement_expression ::=
1281 assignment:st {: RESULT=st; :}
1282 | preincrement_expression:st {: RESULT=st; :}
1283 | predecrement_expression:st {: RESULT=st; :}
1284 | postincrement_expression:st {: RESULT=st; :}
1285 | postdecrement_expression:st {: RESULT=st; :}
1286 | method_invocation:st {: RESULT=st; :}
1287 | class_instance_creation_expression:st {: RESULT=st; :}
1289 if_then_statement ::=
1290 IF LPAREN expression:exp RPAREN statement:st {:
1291 ParseNode pn=new ParseNode("ifstatement");
1292 pn.addChild("condition").addChild(exp);
1293 pn.addChild("statement").addChild(st);
1297 if_then_else_statement ::=
1298 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1299 ELSE statement:else_st {:
1300 ParseNode pn=new ParseNode("ifstatement");
1301 pn.addChild("condition").addChild(exp);
1302 pn.addChild("statement").addChild(st);
1303 pn.addChild("else_statement").addChild(else_st);
1307 if_then_else_statement_no_short_if ::=
1308 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1309 ELSE statement_no_short_if:else_st {:
1310 ParseNode pn=new ParseNode("ifstatement");
1311 pn.addChild("condition").addChild(exp);
1312 pn.addChild("statement").addChild(st);
1313 pn.addChild("else_statement").addChild(else_st);
1317 //switch_statement ::=
1318 // SWITCH LPAREN expression RPAREN switch_block
1321 // LBRACE switch_block_statement_groups switch_labels RBRACE
1322 // | LBRACE switch_block_statement_groups RBRACE
1323 // | LBRACE switch_labels RBRACE
1326 //switch_block_statement_groups ::=
1327 // switch_block_statement_group
1328 // | switch_block_statement_groups switch_block_statement_group
1330 //switch_block_statement_group ::=
1331 // switch_labels block_statements
1335 // | switch_labels switch_label
1338 // CASE constant_expression COLON
1343 WHILE LPAREN expression:exp RPAREN statement:st {:
1344 ParseNode pn=new ParseNode("whilestatement");
1345 pn.addChild("condition").addChild(exp);
1346 pn.addChild("statement").addChild(st);
1350 while_statement_no_short_if ::=
1351 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1352 ParseNode pn=new ParseNode("whilestatement");
1353 pn.addChild("condition").addChild(exp);
1354 pn.addChild("statement").addChild(st);
1359 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1360 ParseNode pn=new ParseNode("dowhilestatement");
1361 pn.addChild("condition").addChild(exp);
1362 pn.addChild("statement").addChild(st);
1367 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1368 for_update_opt:update RPAREN statement:st {:
1369 ParseNode pn=new ParseNode("forstatement");
1370 pn.addChild("initializer").addChild(init);
1371 pn.addChild("condition").addChild(exp);
1372 pn.addChild("update").addChild(update);
1373 pn.addChild("statement").addChild(st);
1377 for_statement_no_short_if ::=
1378 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1379 for_update_opt:update RPAREN statement_no_short_if:st {:
1380 ParseNode pn=new ParseNode("forstatement");
1381 pn.addChild("initializer").addChild(init);
1382 pn.addChild("condition").addChild(exp);
1383 pn.addChild("update").addChild(update);
1384 pn.addChild("statement").addChild(st);
1389 {: RESULT=new ParseNode("empty"); :}
1390 | for_init:init {: RESULT=init; :}
1392 for_init ::= statement_expression_list:list {: RESULT=list; :}
1393 | local_variable_declaration:decl {: RESULT=decl; :}
1396 {: RESULT=new ParseNode("empty"); :}
1397 | for_update:update {: RESULT=update; :}
1399 for_update ::= statement_expression_list:list {: RESULT=list; :}
1401 statement_expression_list ::=
1402 statement_expression:expr {:
1403 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1405 | statement_expression_list:list COMMA statement_expression:expr {:
1406 list.addChild(expr);
1411 //identifier_opt ::=
1418 SEMICOLON {: RESULT=new ParseNode("break"); :}
1421 continue_statement ::=
1425 {: RESULT=new ParseNode("continue"); :}
1427 return_statement ::=
1428 RETURN expression_opt:exp SEMICOLON {:
1429 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1431 //throw_statement ::=
1432 // THROW expression SEMICOLON
1434 synchronized_statement ::=
1435 SYNCHRONIZED LPAREN expression:e RPAREN block:b {:
1436 ParseNode pn=new ParseNode("synchronized");
1437 pn.addChild("expr").addChild(e);
1438 pn.addChild("block").addChild(b);
1442 atomic_statement ::=
1444 RESULT=(new ParseNode("atomic")).addChild(blk).getRoot();
1449 ParseNode pn = new ParseNode("sese");
1450 pn.addChild("body").addChild(blk);
1453 | SESE variable_declarator_id:id block:blk {:
1454 ParseNode pn = new ParseNode("sese");
1455 pn.addChild("body").addChild(blk);
1456 pn.addChild("identifier").addChild(id);
1459 | RBLOCK block:blk {:
1460 ParseNode pn = new ParseNode("sese");
1461 pn.addChild("body").addChild(blk);
1464 | RBLOCK variable_declarator_id:id block:blk {:
1465 ParseNode pn = new ParseNode("sese");
1466 pn.addChild("body").addChild(blk);
1467 pn.addChild("identifier").addChild(id);
1472 // TRY block catches
1473 // | TRY block catches_opt finally
1478 //catches ::= catch_clause
1479 // | catches catch_clause
1482 // CATCH LPAREN formal_parameter RPAREN block
1484 //finally ::= FINALLY block
1486 //assert_statement ::=
1487 // ASSERT expression SEMICOLON
1488 // | ASSERT expression COLON expression SEMICOLON
1491 // 19.12) Expressions
1492 primary ::= primary_no_new_array:st {:
1494 // | array_creation_init:st {:
1497 | array_creation_uninit:st {:
1501 primary_no_new_array ::=
1502 literal:lit {: RESULT=lit; :}
1503 | THIS {: RESULT=new ParseNode("this"); :}
1504 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1505 | class_instance_creation_expression:exp {: RESULT=exp; :}
1506 | field_access:exp {: RESULT=exp; :}
1507 | method_invocation:exp {: RESULT=exp; :}
1508 | array_access:exp {: RESULT=exp; :}
1509 | ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {:
1510 ParseNode pn=new ParseNode("isavailable");
1514 // | primitive_type DOT CLASS
1516 // | array_type DOT CLASS
1520 class_instance_creation_expression ::=
1521 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1522 ParseNode pn=new ParseNode("createobject");
1529 | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1530 ParseNode pn=new ParseNode("createobject");
1534 pn.addChild("global");
1537 | SCRATCH NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1538 ParseNode pn=new ParseNode("createobject");
1542 pn.addChild("scratch");
1545 // Objects we want to track in disjointness analysis
1546 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1547 ParseNode pn=new ParseNode("createobject");
1551 pn.addChild("disjoint").addChild(id);
1554 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
1555 ParseNode pn=new ParseNode("createobject");
1561 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
1562 ParseNode pn=new ParseNode("createobject");
1570 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1571 // | primary DOT NEW IDENTIFIER
1572 // LPAREN argument_list_opt RPAREN {:
1575 // | primary DOT NEW IDENTIFIER
1576 // LPAREN argument_list_opt RPAREN class_body
1577 // | name DOT NEW IDENTIFIER
1578 // LPAREN argument_list_opt RPAREN
1579 // | name DOT NEW IDENTIFIER
1580 // LPAREN argument_list_opt RPAREN class_body
1582 cons_argument_list_opt ::=
1583 {: RESULT=new ParseNode("empty"); :}
1584 | cons_argument_list:args {: RESULT=args; :}
1587 cons_argument_list ::=
1588 IDENTIFIER:id COLON expression:exp {:
1589 ParseNode pn=new ParseNode("cons_argument_list");
1590 ParseNode pnarg=pn.addChild("binding");
1591 pnarg.addChild("var").addChild(id);
1592 pnarg.addChild("exp").addChild(exp);
1595 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1596 ParseNode pnarg=new ParseNode("binding");
1597 pnarg.addChild("var").addChild(id);
1598 pnarg.addChild("exp").addChild(exp);
1599 list.addChild(pnarg);
1604 argument_list_opt ::=
1605 {: RESULT=new ParseNode("empty"); :}
1606 | argument_list:args {: RESULT=args; :}
1611 ParseNode pn=new ParseNode("argument_list");
1615 | argument_list:list COMMA expression:exp {:
1620 array_creation_uninit ::=
1621 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1622 ParseNode pn=new ParseNode("createarray");
1624 pn.addChild(dimexpr);
1625 pn.addChild("dims_opt").setLiteral(dims);
1628 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1629 ParseNode pn=new ParseNode("createarray");
1631 pn.addChild(dimexpr);
1632 pn.addChild("dims_opt").setLiteral(dims);
1635 | GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1636 ParseNode pn=new ParseNode("createarray");
1638 pn.addChild(dimexpr);
1639 pn.addChild("dims_opt").setLiteral(dims);
1640 pn.addChild("global");
1643 | SCRATCH NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1644 ParseNode pn=new ParseNode("createarray");
1646 pn.addChild(dimexpr);
1647 pn.addChild("dims_opt").setLiteral(dims);
1648 pn.addChild("scratch");
1651 | DISJOINT IDENTIFIER:id NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1652 ParseNode pn=new ParseNode("createarray");
1654 pn.addChild(dimexpr);
1655 pn.addChild("dims_opt").setLiteral(dims);
1656 pn.addChild("disjoint").addChild(id);
1659 | GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1660 ParseNode pn=new ParseNode("createarray");
1662 pn.addChild(dimexpr);
1663 pn.addChild("dims_opt").setLiteral(dims);
1664 pn.addChild("global");
1667 | SCRATCH NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1668 ParseNode pn=new ParseNode("createarray");
1670 pn.addChild(dimexpr);
1671 pn.addChild("dims_opt").setLiteral(dims);
1672 pn.addChild("scratch");
1675 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1676 ParseNode pn=new ParseNode("createarray");
1678 pn.addChild(dimexpr);
1679 pn.addChild("dims_opt").setLiteral(dims);
1680 pn.addChild("disjoint").addChild(id);
1684 //array_creation_init ::=
1685 // NEW primitive_type dims array_initializer
1686 // | NEW class_or_interface_type dims array_initializer
1688 dim_exprs ::= dim_expr:exp {:
1689 ParseNode pn=new ParseNode("dim_exprs");
1692 | dim_exprs:base dim_expr:exp {:
1697 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1699 dims_opt ::= {: RESULT=new Integer(0); :}
1700 | dims:dims {: RESULT = dims; :}
1703 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1704 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1708 primary:base DOT IDENTIFIER:id {:
1709 ParseNode pn=new ParseNode("fieldaccess");
1710 pn.addChild("base").addChild(base);
1711 pn.addChild("field").addChild(id);
1714 // | SUPER DOT IDENTIFIER
1715 // | name DOT SUPER DOT IDENTIFIER
1717 method_invocation ::=
1718 name:name LPAREN argument_list_opt:args RPAREN {:
1719 ParseNode pn=new ParseNode("methodinvoke1");
1724 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1725 ParseNode pn=new ParseNode("methodinvoke2");
1726 pn.addChild("base").addChild(base);
1727 pn.addChild("id").addChild(name);
1731 | SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {:
1732 ParseNode name=new ParseNode("name");
1733 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
1734 name.addChild("identifier").addChild(id);
1735 ParseNode pn=new ParseNode("methodinvoke1");
1740 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1743 name:name LBRACK expression:exp RBRACK {:
1744 ParseNode pn=new ParseNode("arrayaccess");
1745 pn.addChild("base").addChild(name);
1746 pn.addChild("index").addChild(exp);
1749 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1750 ParseNode pn=new ParseNode("arrayaccess");
1751 pn.addChild("base").addChild(base);
1752 pn.addChild("index").addChild(exp);
1755 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1756 // ParseNode pn=new ParseNode("arrayaccess");
1757 // pn.addChild("init").addChild(init);
1758 // pn.addChild("index").addChild(exp);
1763 postfix_expression ::=
1766 | name:exp {: RESULT=exp; :}
1767 | postincrement_expression:exp {: RESULT=exp; :}
1768 | postdecrement_expression:exp {: RESULT=exp; :}
1770 postincrement_expression ::=
1771 postfix_expression:exp PLUSPLUS
1772 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1774 postdecrement_expression ::=
1775 postfix_expression:exp MINUSMINUS
1776 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1778 unary_expression ::=
1779 preincrement_expression:exp {: RESULT=exp; :}
1780 | predecrement_expression:exp {: RESULT=exp; :}
1781 | PLUS unary_expression:exp
1782 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1783 | MINUS unary_expression:exp
1784 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1785 | unary_expression_not_plus_minus:exp {:
1788 preincrement_expression ::=
1789 PLUSPLUS unary_expression:exp
1790 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1792 predecrement_expression ::=
1793 MINUSMINUS unary_expression:exp
1794 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1796 unary_expression_not_plus_minus ::=
1797 postfix_expression:exp {:
1799 | COMP unary_expression:exp
1800 {: RESULT=(new ParseNode("comp")).addChild(exp).getRoot(); :}
1801 | NOT unary_expression:exp
1802 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1803 | cast_expression:exp {: RESULT=exp; :}
1806 LPAREN primitive_type:type dims_opt:dims
1807 RPAREN unary_expression:exp {:
1808 ParseNode pn=new ParseNode("cast1");
1809 if (dims.intValue()==0)
1810 pn.addChild("type").addChild(type);
1812 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
1813 arrayt.addChild("basetype").addChild(type);
1814 arrayt.addChild("dims").setLiteral(dims);
1816 pn.addChild("exp").addChild(exp);
1819 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
1820 ParseNode pn=new ParseNode("cast2");
1821 pn.addChild("type").addChild(type);
1822 pn.addChild("exp").addChild(exp);
1826 // | LPAREN name dims RPAREN unary_expression_not_plus_minus
1828 multiplicative_expression ::=
1829 unary_expression:exp {:
1831 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
1832 ParseNode pn=new ParseNode("mult");
1837 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1838 ParseNode pn=new ParseNode("div");
1843 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1844 ParseNode pn=new ParseNode("mod");
1850 additive_expression ::=
1851 multiplicative_expression:exp {:
1853 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
1854 ParseNode pn=new ParseNode("add");
1859 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
1860 ParseNode pn=new ParseNode("sub");
1866 shift_expression ::=
1867 additive_expression:exp {:
1869 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
1870 ParseNode pn=new ParseNode("leftshift");
1875 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
1876 ParseNode pn=new ParseNode("rightshift");
1881 | shift_expression:exp1 URSHIFT additive_expression:exp2 {:
1882 ParseNode pn=new ParseNode("urightshift");
1888 relational_expression ::=
1889 shift_expression:exp {:
1891 | relational_expression:exp1 LT shift_expression:exp2 {:
1892 ParseNode pn=new ParseNode("comp_lt");
1897 | relational_expression:exp1 GT shift_expression:exp2 {:
1898 ParseNode pn=new ParseNode("comp_gt");
1903 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
1904 ParseNode pn=new ParseNode("comp_lte");
1909 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
1910 ParseNode pn=new ParseNode("comp_gte");
1915 | relational_expression:exp INSTANCEOF reference_type:type {:
1916 ParseNode pn=new ParseNode("instanceof");
1917 pn.addChild("exp").addChild(exp);
1923 equality_expression ::=
1924 relational_expression:exp {:
1926 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
1927 ParseNode pn=new ParseNode("equal");
1932 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
1933 ParseNode pn=new ParseNode("not_equal");
1940 equality_expression:exp {:
1942 | and_expression:exp1 AND equality_expression:exp2 {:
1943 ParseNode pn=new ParseNode("bitwise_and");
1949 exclusive_or_expression ::=
1950 and_expression:expr {:
1953 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
1954 ParseNode pn=new ParseNode("bitwise_xor");
1960 inclusive_or_expression ::=
1961 exclusive_or_expression:exclor {:
1963 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
1964 ParseNode pn=new ParseNode("bitwise_or");
1970 conditional_and_expression ::=
1971 inclusive_or_expression:inclor {:
1973 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1974 ParseNode pn=new ParseNode("logical_and");
1980 conditional_or_expression ::=
1981 conditional_and_expression:condand {:
1983 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
1984 ParseNode pn=new ParseNode("logical_or");
1990 conditional_expression ::=
1991 conditional_or_expression:condor {:
1993 | conditional_or_expression:condor QUESTION expression:exptrue
1994 COLON conditional_expression:expfalse {:
1995 ParseNode pn=new ParseNode("tert");
1996 pn.addChild("cond").addChild(condor);
1997 pn.addChild("trueexpr").addChild(exptrue);
1998 pn.addChild("falseexpr").addChild(expfalse);
2002 getoffset_expression ::=
2003 GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
2004 ParseNode pn = new ParseNode("getoffset");
2006 pn.addChild("field").addChild(id);
2011 assignment_expression ::=
2012 conditional_expression:expr {:
2014 assignment:assign {:
2016 getoffset_expression:expr {:
2019 // semantic check necessary here to ensure a valid left-hand side.
2020 // allowing a parenthesized variable here on the lhs was introduced in
2021 // JLS 2; thanks to Eric Blake for pointing this out.
2022 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
2023 ParseNode pn=new ParseNode("assignment");
2024 pn.addChild("op").addChild(op);
2025 ParseNode pnargs=pn.addChild("args");
2026 pnargs.addChild(lvalue);
2027 pnargs.addChild(rvalue);
2031 assignment_operator ::=
2032 EQ {: RESULT=new ParseNode("eq"); :}
2033 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
2034 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
2035 | MODEQ {: RESULT=new ParseNode("modeq"); :}
2036 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
2037 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
2038 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
2039 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
2040 | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
2041 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
2042 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
2043 | OREQ {: RESULT=new ParseNode("oreq"); :}
2046 {: RESULT=new ParseNode("empty"); :}
2050 expression ::= assignment_expression:exp {:
2053 //constant_expression ::=
2058 genreach_statement ::=
2059 GENREACH IDENTIFIER:graphName SEMICOLON {:
2060 ParseNode pn=new ParseNode("genreach");
2061 pn.addChild("graphName").addChild(graphName);