3 import java_cup.runtime.*;
7 /* Java 1.4 parser for CUP.
8 * Copyright (C) 2002-2003 C. Scott Ananian <cananian@alumni.princeton.edu>
9 * This program is released under the terms of the GPL; see the file
10 * COPYING for more details. There is NO WARRANTY on this code.
14 JDK 1.4 Features added:
16 statement_without_trailing_substatement ::= ...
19 ASSERT expression SEMICOLON
20 | ASSERT expression COLON expression SEMICOLON
26 public Parser(Lexer l) {
31 public void syntax_error(java_cup.runtime.Symbol current) {
32 report_error("Syntax error (" + current.sym + ")", current);
34 public void report_error(String message, java_cup.runtime.Symbol info) {
35 lexer.errorMsg(message, info);
39 scan with {: return lexer.nextToken(); :};
41 terminal BOOLEAN; // primitive_type
42 terminal BYTE, SHORT, INT, LONG, CHAR; // integral_type
43 terminal FLOAT, DOUBLE; // floating_point_type
44 terminal LBRACK, RBRACK; // array_type
45 terminal java.lang.String IDENTIFIER; // name
46 terminal DOT; // qualified_name
47 terminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;
48 terminal PACKAGE; // package_declaration
49 terminal IMPORT; // import_declaration
50 terminal PUBLIC, PROTECTED, PRIVATE; // modifier
51 terminal STATIC; // modifier
52 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
53 terminal CLASS; // class_declaration
54 terminal EXTENDS; // super
55 //terminal IMPLEMENTS; // interfaces
56 terminal VOID; // method_header
57 terminal THROWS; // throws
58 terminal THIS, SUPER; // explicit_constructor_invocation
59 //terminal INTERFACE; // interface_declaration
60 terminal IF, ELSE; // if_then_statement, if_then_else_statement
61 terminal SWITCH; // switch_statement
62 terminal CASE, DEFAULT; // switch_label
63 terminal DO, WHILE; // while_statement, do_statement
64 terminal FOR; // for_statement
65 terminal BREAK; // break_statement
66 terminal CONTINUE; // continue_statement
67 terminal RETURN; // return_statement
68 terminal THROW; // throw_statement
69 terminal TRY; // try_statement
70 terminal CATCH; // catch_clause
71 terminal FINALLY; // finally
72 terminal NEW; // class_instance_creation_expression
73 terminal PLUSPLUS; // postincrement_expression
74 terminal MINUSMINUS; // postdecrement_expression
75 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
76 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
77 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
78 terminal EQEQ, NOTEQ; // equality_expression
79 terminal AND; // and_expression
80 terminal XOR; // exclusive_or_expression
81 terminal OR; // inclusive_or_expression
82 terminal ANDAND; // conditional_and_expression
83 terminal OROR; // conditional_or_expression
84 terminal QUESTION; // conditional_expression
85 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
86 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
87 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
89 terminal java.lang.Number INTEGER_LITERAL;
90 terminal java.lang.Number FLOATING_POINT_LITERAL;
91 terminal java.lang.Boolean BOOLEAN_LITERAL;
92 terminal java.lang.Character CHARACTER_LITERAL;
93 terminal java.lang.String STRING_LITERAL;
94 terminal NULL_LITERAL;
96 // Reserved but unused:
98 // strictfp keyword, new in Java 1.2
100 // assert keyword, new in Java 1.4
101 terminal ASSERT; // assert_statement
102 // lexer compatibility with Java 1.5
107 // 19.2) The Syntactic Grammar
108 non terminal ParseNode goal;
109 // 19.3) Lexical Structure
110 non terminal ParseNode literal;
111 // 19.4) Types, Values, and Variables
112 non terminal ParseNode type, primitive_type, numeric_type;
113 non terminal ParseNode integral_type, floating_point_type;
114 non terminal ParseNode reference_type;
115 non terminal ParseNode class_or_interface_type;
116 non terminal ParseNode class_type;
117 //non terminal ParseNode interface_type;
118 non terminal ParseNode array_type;
120 non terminal ParseNode name, simple_name, qualified_name;
122 non terminal ParseNode compilation_unit;
123 non terminal ParseNode package_declaration_opt, package_declaration;
124 non terminal ParseNode import_declarations_opt, import_declarations;
125 non terminal ParseNode type_declarations_opt, type_declarations;
126 non terminal ParseNode import_declaration;
127 non terminal ParseNode single_type_import_declaration;
128 non terminal ParseNode type_import_on_demand_declaration;
129 non terminal ParseNode type_declaration;
130 // 19.7) Productions used only in the LALR(1) grammar
131 non terminal ParseNode modifiers_opt, modifiers, modifier;
132 // 19.8.1) Class Declaration
133 non terminal ParseNode class_declaration, super, super_opt;
134 //non terminal interfaces, interfaces_opt, interface_type_list;
135 non terminal ParseNode class_body;
136 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
137 non terminal ParseNode class_body_declaration, class_member_declaration;
138 // 19.8.2) Field Declarations
139 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
140 non terminal ParseNode variable_declarator_id;
141 non terminal ParseNode variable_initializer;
142 // 19.8.3) Method Declarations
143 non terminal ParseNode method_declaration, method_header, method_declarator;
144 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
145 non terminal ParseNode formal_parameter;
146 //non terminal ParseNode throws_opt;
147 //non terminal ParseNode throws;
148 //non terminal ParseNode class_type_list;
149 non terminal ParseNode method_body;
150 // 19.8.4) Static Initializers
151 //non terminal ParseNode static_initializer;
152 // 19.8.5) Constructor Declarations
153 non terminal ParseNode constructor_declaration, constructor_declarator;
154 non terminal ParseNode constructor_body;
155 non terminal ParseNode explicit_constructor_invocation;
156 // 19.9.1) Interface Declarations
157 //non terminal ParseNode interface_declaration;
158 //non terminal ParseNode extends_interfaces_opt, extends_interfaces;
159 //non terminal ParseNode interface_body;
160 //non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
161 //non terminal ParseNode interface_member_declaration, constant_declaration;
162 //non terminal ParseNode abstract_method_declaration;
164 non terminal ParseNode array_initializer;
165 non terminal ParseNode variable_initializers;
166 // 19.11) Blocks and Statements
167 non terminal ParseNode block;
168 non terminal ParseNode block_statements_opt, block_statements, block_statement;
169 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
170 non terminal ParseNode statement, statement_no_short_if;
171 non terminal ParseNode statement_without_trailing_substatement;
172 non terminal ParseNode empty_statement;
173 //non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
174 non terminal ParseNode expression_statement, statement_expression;
175 non terminal ParseNode if_then_statement;
176 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
177 //non terminal ParseNode switch_statement, switch_block;
178 //non terminal ParseNode switch_block_statement_groups;
179 //non terminal ParseNode switch_block_statement_group;
180 //non terminal ParseNode switch_labels, switch_label;
181 non terminal ParseNode while_statement, while_statement_no_short_if;
182 non terminal ParseNode do_statement;
183 non terminal ParseNode for_statement, for_statement_no_short_if;
184 non terminal ParseNode for_init_opt, for_init;
185 non terminal ParseNode for_update_opt, for_update;
186 non terminal ParseNode statement_expression_list;
187 //non terminal ParseNode identifier_opt;
188 non terminal ParseNode break_statement, continue_statement;
189 non terminal ParseNode return_statement;
190 //non terminal ParseNode throw_statement;
191 non terminal ParseNode synchronized_statement;
192 //non terminal ParseNode try_statement;
193 //non terminal ParseNode catches_opt;
194 //non terminal ParseNode catches, catch_clause;
195 //non terminal ParseNode finally;
196 //non terminal ParseNode assert_statement;
197 // 19.12) Expressions
198 non terminal ParseNode primary, primary_no_new_array;
199 non terminal ParseNode class_instance_creation_expression;
200 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
201 non terminal ParseNode argument_list_opt, argument_list;
202 //non terminal ParseNode array_creation_init;
203 non terminal ParseNode array_creation_uninit;
204 non terminal ParseNode dim_exprs, dim_expr;
205 non terminal Integer dims_opt, dims;
206 non terminal ParseNode field_access, method_invocation;
207 non terminal ParseNode array_access;
208 non terminal ParseNode postfix_expression;
209 non terminal ParseNode postincrement_expression, postdecrement_expression;
210 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
211 non terminal ParseNode preincrement_expression, predecrement_expression;
212 non terminal ParseNode cast_expression;
213 non terminal ParseNode multiplicative_expression, additive_expression;
214 non terminal ParseNode shift_expression, relational_expression, equality_expression;
215 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
216 non terminal ParseNode conditional_and_expression, conditional_or_expression;
217 non terminal ParseNode conditional_expression;
218 non terminal ParseNode assignment_expression;
219 non terminal ParseNode assignment;
220 non terminal ParseNode assignment_operator;
221 non terminal ParseNode expression_opt, expression;
222 //non terminal ParseNode constant_expression;
223 //failure aware computation keywords
226 terminal ISAVAILABLE;
231 non terminal ParseNode flag_declaration;
232 non terminal ParseNode task_declaration;
233 non terminal ParseNode task_parameter_list;
234 non terminal ParseNode task_parameter;
235 non terminal ParseNode flag_expression;
236 non terminal ParseNode flag_andexpression;
237 non terminal ParseNode flag_notexpression;
238 non terminal ParseNode task_exitstatement;
239 non terminal ParseNode flag_effects_opt;
240 non terminal ParseNode flag_effects;
241 non terminal ParseNode flag_effect;
242 non terminal ParseNode flag_list;
243 non terminal ParseNode flag_list_opt;
244 non terminal ParseNode flag_change;
246 non terminal ParseNode cons_checks_opt;
247 non terminal ParseNode cons_checks;
248 non terminal ParseNode cons_check;
250 non terminal ParseNode tag_variable_declaration_statement;
251 non terminal ParseNode tag_expression_list;
252 non terminal ParseNode tag_expression;
253 non terminal ParseNode tag_list;
254 non terminal ParseNode tag_list_opt;
255 non terminal ParseNode tag_change;
257 //distributed transaction keywords
262 non terminal ParseNode atomic_statement;
263 non terminal ParseNode getoffset_expression;
265 //disjointness for Java
268 //coarse-grain parallelization
270 non terminal ParseNode sese_statement;
278 TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN
282 ParseNode pn=new ParseNode("task_declaration");
283 pn.addChild("name").addChild(id);
286 pn.addChild("body").addChild(body);
290 task_parameter_list ::=
292 ParseNode pn=new ParseNode("task_parameter_list");
296 | task_parameter_list:fpl COMMA task_parameter:fp {:
303 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
304 ParseNode pn=new ParseNode("task_parameter");
307 pn.addChild("flag").addChild(exp);
310 | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
311 ParseNode pn=new ParseNode("task_parameter");
314 pn.addChild("flag").addChild(exp);
315 pn.addChild("tag").addChild(texp);
318 | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
319 ParseNode pn=new ParseNode("task_parameter");
322 pn.addChild("tag").addChild(texp);
325 | OPTIONAL task_parameter:fp {:
326 ParseNode pn=new ParseNode("task_parameter");
327 pn.addChild("optional").addChild(fp);
333 tag_expression_list ::= tag_expression:te {:
334 ParseNode pn=new ParseNode("tag_expression_list");
338 | tag_expression_list:tel COMMA tag_expression:te {:
344 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {:
345 ParseNode pn=new ParseNode("tag_expression");
346 pn.addChild("type").addChild(type);
347 pn.addChild("single").addChild(id);
352 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
353 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
354 | {: RESULT = new ParseNode("empty"); :}
357 tag_list ::= tag_change:fc {:
358 ParseNode pn=new ParseNode("tag_list");
362 | tag_list:fl COMMA tag_change:fc {:
367 tag_change ::= IDENTIFIER:id {:
368 RESULT=new ParseNode("name").addChild(id).getRoot();
370 | NOT IDENTIFIER:id {:
371 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
375 flag_andexpression:exp {:
378 | flag_expression:exp1 OROR flag_andexpression:exp2 {:
379 ParseNode pn=new ParseNode("or");
386 flag_andexpression ::=
387 flag_notexpression:exp {: RESULT=exp; :}
388 | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {:
389 ParseNode pn=new ParseNode("and");
396 flag_notexpression ::=
397 NOT flag_notexpression:exp {:
398 ParseNode pn=new ParseNode("not");
402 | LPAREN flag_expression:exp RPAREN {:
406 ParseNode pn=new ParseNode("name");
412 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
413 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
416 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
417 | {: RESULT = new ParseNode("empty"); :}
420 cons_checks ::= cons_check:cc {:
421 ParseNode pn=new ParseNode("cons_checks");
425 | cons_checks:ccs COMMA cons_check:cc {:
430 cons_check ::= IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {:
431 ParseNode pn=new ParseNode("cons_check");
432 pn.addChild("name").addChild("identifier").addChild(name);
437 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
438 | {: RESULT = new ParseNode("empty"); :}
441 flag_effects ::= flag_effect:fe {:
442 ParseNode pn=new ParseNode("flag_effects_list");
446 | flag_effects:fes COMMA flag_effect:fe {:
451 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {:
452 ParseNode pn=new ParseNode("flag_effect");
453 pn.addChild("name").addChild(id);
458 | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
459 ParseNode pn=new ParseNode("flag_effect");
460 pn.addChild("name").addChild(id);
465 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
466 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
468 {: RESULT = new ParseNode("empty"); :}
471 flag_list ::= flag_change:fc {:
472 ParseNode pn=new ParseNode("flag_list");
476 | flag_list:fl COMMA flag_change:fc {:
481 flag_change ::= IDENTIFIER:id {:
482 RESULT=new ParseNode("name").addChild(id).getRoot();
485 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
488 // 19.2) The Syntactic Grammar
489 goal ::= compilation_unit:cu
495 // 19.3) Lexical Structure.
498 literal ::= INTEGER_LITERAL:integer_lit
500 ParseNode pn=new ParseNode("literal");
501 pn.addChild("integer").setLiteral(integer_lit);
504 | FLOATING_POINT_LITERAL:float_lit
506 ParseNode pn=new ParseNode("literal");
507 pn.addChild("float").setLiteral(float_lit);
510 | BOOLEAN_LITERAL:boolean_lit
512 ParseNode pn=new ParseNode("literal");
513 pn.addChild("boolean").setLiteral(boolean_lit);
516 | CHARACTER_LITERAL:char_lit
518 ParseNode pn=new ParseNode("literal");
519 pn.addChild("char").setLiteral(char_lit);
522 | STRING_LITERAL:string_lit
524 ParseNode pn=new ParseNode("literal");
525 pn.addChild("string").setLiteral(string_lit);
530 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
534 // 19.4) Types, Values, and Variables
535 type ::= primitive_type:type {: RESULT=type; :}
536 | reference_type:type {: RESULT=type; :}
540 numeric_type:type {: RESULT=type; :}
541 | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
543 numeric_type::= integral_type:type {: RESULT=type; :}
544 | floating_point_type:type {: RESULT=type; :}
547 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
548 | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
549 | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
550 | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
551 | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
553 floating_point_type ::=
554 FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
555 | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
559 class_or_interface_type:type {: RESULT=type; :}
560 | array_type:type {: RESULT=type; :}
562 class_or_interface_type ::= name:name {:
563 RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot();
566 class_type ::= class_or_interface_type:type {: RESULT=type; :};
567 //interface_type ::= class_or_interface_type;
569 array_type ::= primitive_type:prim dims:dims {:
570 ParseNode pn=(new ParseNode("type")).addChild("array");
571 pn.addChild("basetype").addChild(prim);
572 pn.addChild("dims").setLiteral(dims);
575 | name:name dims:dims {:
576 ParseNode pn=(new ParseNode("type")).addChild("array");
577 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
578 pn.addChild("dims").setLiteral(dims);
584 name ::= simple_name:name {: RESULT=name; :}
585 | qualified_name:name {: RESULT=name; :}
587 simple_name ::= IDENTIFIER:id {:
588 RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot();
591 qualified_name ::= name:name DOT IDENTIFIER:id {:
592 ParseNode pn=new ParseNode("name");
593 pn.addChild("base").addChild(name);
594 pn.addChild("identifier").addChild(id);
601 package_declaration_opt:pdo
602 import_declarations_opt:ido
603 type_declarations_opt:tdo {:
604 ParseNode pn=new ParseNode("compilation_unit");
606 pn.addChild("packages").addChild(pdo);
607 pn.addChild("imports").addChild(ido);
611 package_declaration_opt ::= package_declaration:pdo {:
614 {: RESULT=new ParseNode("empty"); :}
617 import_declarations_opt ::= import_declarations:ido {:
620 {: RESULT=new ParseNode("empty"); :}
622 type_declarations_opt ::= type_declarations:tds {:
625 {: RESULT=new ParseNode("empty"); :}
628 import_declarations ::=
629 import_declaration:id {:
630 ParseNode pn=new ParseNode("import_decls_list");
634 | import_declarations:ids import_declaration:id {:
640 type_declarations ::=
641 type_declaration:td {:
642 ParseNode pn=new ParseNode("type_declaration_list");
646 | type_declarations:tds type_declaration:td {:
652 package_declaration ::=
653 PACKAGE name:name SEMICOLON {:
654 ParseNode pn=new ParseNode("package");
659 import_declaration ::=
660 single_type_import_declaration:sid {: RESULT=sid; :}
661 | type_import_on_demand_declaration:iod {: RESULT=iod; :}
663 single_type_import_declaration ::=
664 IMPORT name:name SEMICOLON {:
665 ParseNode pn=new ParseNode("import_single");
670 type_import_on_demand_declaration ::=
671 IMPORT name:name DOT MULT SEMICOLON {:
672 ParseNode pn=new ParseNode("import_ondemand");
683 | task_declaration:td
687 // | interface_declaration
688 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
691 // 19.7) Productions used only in the LALR(1) grammar
693 {: RESULT=new ParseNode("empty"); :}
698 modifiers ::= modifier:mo {:
699 ParseNode pn=new ParseNode("modifier_list");
703 | modifiers:mos modifier:mo {:
709 PUBLIC {: RESULT=new ParseNode("public"); :}|
710 PROTECTED {: RESULT=new ParseNode("protected"); :}|
711 PRIVATE {: RESULT=new ParseNode("private"); :}|
712 STATIC {: RESULT=new ParseNode("static"); :} |
714 FINAL {: RESULT=new ParseNode("final"); :}|
715 NATIVE {: RESULT=new ParseNode("native"); :} |
716 SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
717 ATOMIC {: RESULT=new ParseNode("atomic"); :}
720 // STRICTFP // note that semantic analysis must check that the
721 // context of the modifier allows strictfp.
726 // 19.8.1) Class Declaration:
727 class_declaration ::=
728 modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so //interfaces_opt
731 ParseNode pn=new ParseNode("class_declaration");
732 pn.addChild("modifiers").addChild(mo);
733 pn.addChild("name").addChild(id);
734 pn.addChild("super").addChild(so);
735 pn.addChild("classbody").addChild(body);
739 super ::= EXTENDS class_type:classtype {:
744 {: RESULT=new ParseNode("empty"); :}
750 //interfaces ::= IMPLEMENTS interface_type_list
755 //interface_type_list ::=
757 // | interface_type_list COMMA interface_type
760 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
763 class_body_declarations_opt ::=
764 {: RESULT=new ParseNode("empty"); :}
765 | class_body_declarations:cbd {: RESULT=cbd; :};
767 class_body_declarations ::=
768 class_body_declaration:cbd {:
769 ParseNode pn=new ParseNode("class_body_declaration_list");
773 | class_body_declarations:cbds class_body_declaration:cbd {:
779 class_body_declaration ::=
780 class_member_declaration:member {:
781 RESULT=(new ParseNode("member")).addChild(member).getRoot();
783 // | static_initializer
784 | constructor_declaration:constructor {:
785 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
788 RESULT=(new ParseNode("block")).addChild(block).getRoot();
791 class_member_declaration ::=
792 //failure aware computation
793 flag_declaration:flag {:
794 RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
797 field_declaration:field {:
798 RESULT=(new ParseNode("field")).addChild(field).getRoot();
800 | method_declaration:method {:
801 RESULT=(new ParseNode("method")).addChild(method).getRoot();
803 /* repeat the prod for 'class_declaration' here: */
804 // | modifiers_opt CLASS IDENTIFIER super_opt class_body
805 // | interface_declaration
806 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
809 //Failure aware computation
811 FLAG IDENTIFIER:id SEMICOLON {:
812 ParseNode pn=new ParseNode("flag_declaration");
813 pn.addChild("name").addChild(id);
816 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {:
817 ParseNode pn=new ParseNode("flag_declaration");
818 pn.addChild("name").addChild(id);
819 pn.addChild("external");
824 // 19.8.2) Field Declarations
825 field_declaration ::=
826 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {:
827 ParseNode pn=new ParseNode("field_declaration");
828 pn.addChild("modifier").addChild(mo);
829 pn.addChild("type").addChild(type);
830 pn.addChild("variables").addChild(var);
833 modifiers_opt:mo GLOBAL type:type variable_declarators:var SEMICOLON {:
834 ParseNode pn=new ParseNode("field_declaration");
835 pn.addChild("modifier").addChild(mo);
836 pn.addChild("type").addChild(type);
837 pn.addChild("variables").addChild(var);
838 pn.addChild("global");
843 variable_declarators ::=
844 variable_declarator:vd {:
845 ParseNode pn=new ParseNode("variable_declarators_list");
849 | variable_declarators:vds COMMA variable_declarator:vd {:
854 variable_declarator ::=
855 variable_declarator_id:id {:
856 ParseNode pn=new ParseNode("variable_declarator");
860 | variable_declarator_id:id EQ variable_initializer:init {:
861 ParseNode pn=new ParseNode("variable_declarator");
863 pn.addChild("initializer").addChild(init);
867 variable_declarator_id ::=
869 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
870 | variable_declarator_id:id LBRACK RBRACK {:
871 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
873 variable_initializer ::=
874 expression:exp {: RESULT=exp; :}
875 | array_initializer {: RESULT=new ParseNode("array_initializer"); :}
878 // 19.8.3) Method Declarations
879 method_declaration ::=
880 method_header:header method_body:body {:
881 ParseNode pn=new ParseNode("method_declaration");
883 pn.addChild("body").addChild(body);
888 modifiers_opt:mo type:type method_declarator:decl //throws_opt
890 ParseNode pn=new ParseNode("method_header");
891 pn.addChild("modifiers").addChild(mo);
892 pn.addChild("returntype").addChild(type);
896 | modifiers_opt:mo VOID method_declarator:decl //throws_opt
898 ParseNode pn=new ParseNode("method_header");
899 pn.addChild("modifiers").addChild(mo);
904 method_declarator ::=
905 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {:
906 ParseNode pn=new ParseNode("method_declarator");
907 pn.addChild("name").addChild(id);
908 pn.addChild("parameters").addChild(params);
911 // | method_declarator LBRACK RBRACK // deprecated
912 // be careful; the above production also allows 'void foo() []'
914 formal_parameter_list_opt ::=
915 {: RESULT=new ParseNode("empty"); :}
916 | formal_parameter_list:fpl {:
920 formal_parameter_list ::=
921 formal_parameter:fp {:
922 ParseNode pn=new ParseNode("formal_parameter_list");
926 | formal_parameter_list:fpl COMMA formal_parameter:fp {:
932 type:type variable_declarator_id:name {:
933 ParseNode pn=new ParseNode("formal_parameter");
939 TAG variable_declarator_id:name {:
940 ParseNode pn=new ParseNode("tag_parameter");
944 | FINAL type:type variable_declarator_id:name {:
945 ParseNode pn=new ParseNode("formal_parameter");
954 //throws ::= THROWS class_type_list
956 //class_type_list ::=
958 // | class_type_list COMMA class_type
960 method_body ::= block:block {:
963 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
966 // 19.8.4) Static Initializers
967 //static_initializer ::=
971 // 19.8.5) Constructor Declarations
972 constructor_declaration ::=
973 modifiers_opt:mo constructor_declarator:cd
975 constructor_body:body {:
976 ParseNode pn=new ParseNode("constructor_declaration");
977 pn.addChild("modifiers").addChild(mo);
979 pn.addChild("body").addChild(body);
982 modifiers_opt:mo GLOBAL constructor_declarator:cd
984 constructor_body:body {:
985 ParseNode pn=new ParseNode("constructor_declaration");
986 pn.addChild("global");
987 pn.addChild("modifiers").addChild(mo);
989 pn.addChild("body").addChild(body);
994 constructor_declarator ::=
995 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {:
996 ParseNode pn=new ParseNode("constructor_declarator");
998 pn.addChild("parameters").addChild(fplo);
1002 constructor_body ::=
1003 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {:
1004 ParseNode pn=new ParseNode("constructor_body");
1009 LBRACE explicit_constructor_invocation:eci RBRACE {:
1010 ParseNode pn=new ParseNode("constructor_body");
1014 LBRACE block_statements:block RBRACE {:
1015 ParseNode pn=new ParseNode("constructor_body");
1019 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1021 explicit_constructor_invocation ::=
1022 // THIS LPAREN argument_list_opt RPAREN SEMICOLON
1024 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1025 ParseNode pn=new ParseNode("superinvoke");
1029 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1030 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1035 // 19.9.1) Interface Declarations
1036 //interface_declaration ::=
1037 // modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
1040 //extends_interfaces_opt ::=
1041 // | extends_interfaces
1043 //extends_interfaces ::=
1044 // EXTENDS interface_type
1045 // | extends_interfaces COMMA interface_type
1047 //interface_body ::=
1048 // LBRACE interface_member_declarations_opt RBRACE
1050 //interface_member_declarations_opt ::=
1051 // | interface_member_declarations
1053 //interface_member_declarations ::=
1054 // interface_member_declaration
1055 // | interface_member_declarations interface_member_declaration
1057 //interface_member_declaration ::=
1058 // constant_declaration
1059 // | abstract_method_declaration
1060 // | class_declaration
1061 // | interface_declaration
1064 //constant_declaration ::=
1065 // field_declaration
1066 // // need to semantically check that modifiers of field declaration
1067 // // include only PUBLIC, STATIC, or FINAL. Other modifiers are
1070 //abstract_method_declaration ::=
1071 // method_header SEMICOLON
1076 array_initializer ::=
1077 LBRACE variable_initializers:var_init_list COMMA RBRACE {:
1078 RESULT=var_init_list;
1080 | LBRACE variable_initializers:var_init_list RBRACE {:
1081 RESULT=var_init_list;
1083 | LBRACE COMMA RBRACE {:
1084 RESULT=new ParseNode("empty");
1087 RESULT=new ParseNode("empty");
1090 variable_initializers ::=
1091 variable_initializer:var_init {:
1092 ParseNode pn=new ParseNode("var_init_list");
1093 pn.addChild(var_init);
1096 | variable_initializers:var_init_list COMMA variable_initializer:var_init {:
1097 var_init_list.addChild(var_init);
1098 RESULT=var_init_list;
1102 // 19.11) Blocks and Statements
1103 block ::= LBRACE block_statements_opt:bso RBRACE {:
1107 block_statements_opt ::=
1108 {: RESULT=new ParseNode("empty"); :}
1109 | block_statements:bs {:
1113 block_statements ::=
1114 block_statement:bs {:
1115 ParseNode pn=new ParseNode("block_statement_list");
1119 | block_statements:bss block_statement:bs {:
1125 tag_variable_declaration_statement:tvds {:
1128 | local_variable_declaration_statement:lvds {:
1131 | statement:statement {:
1134 // | class_declaration
1135 // | interface_declaration
1137 tag_variable_declaration_statement ::=
1138 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
1139 ParseNode pn=new ParseNode("tag_declaration");
1140 pn.addChild("single").addChild(id);
1141 pn.addChild("type").addChild(type);
1145 local_variable_declaration_statement ::=
1146 local_variable_declaration:lvd SEMICOLON {:
1150 local_variable_declaration ::=
1151 type:type variable_declarators:var {:
1152 ParseNode pn=new ParseNode("local_variable_declaration");
1157 | FINAL type:type variable_declarators:var {:
1158 ParseNode pn=new ParseNode("local_variable_declaration");
1164 statement ::= statement_without_trailing_substatement:st {:
1167 // | labeled_statement:st {: RESULT=st; :}
1168 | if_then_statement:st {: RESULT=st; :}
1169 | if_then_else_statement:st {: RESULT=st; :}
1170 | while_statement:st {: RESULT=st; :}
1171 | for_statement:st {: RESULT=st; :}
1173 statement_no_short_if ::=
1174 statement_without_trailing_substatement:st {: RESULT=st; :}
1175 // | labeled_statement_no_short_if:st {: RESULT=st; :}
1176 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
1177 | while_statement_no_short_if:st {: RESULT=st; :}
1178 | for_statement_no_short_if:st {: RESULT=st; :}
1180 statement_without_trailing_substatement ::=
1181 block:st {: RESULT=st; :}
1182 | empty_statement:st {: RESULT=st; :}
1183 | expression_statement:st {: RESULT=st; :}
1184 // | switch_statement
1185 | do_statement:dos {:RESULT=dos; :}
1186 | break_statement:st {: RESULT=st; :}
1187 | continue_statement:st {: RESULT=st; :}
1188 | return_statement:st {: RESULT=st; :}
1189 | task_exitstatement:st {: RESULT=st; :}
1190 | atomic_statement:st {: RESULT=st; :}
1191 | sese_statement:st {: RESULT=st; :}
1192 | synchronized_statement:st {: RESULT=st; :}
1193 // | throw_statement
1195 // | assert_statement
1198 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1200 //labeled_statement ::=
1201 // IDENTIFIER COLON statement
1203 //labeled_statement_no_short_if ::=
1204 // IDENTIFIER COLON statement_no_short_if
1206 expression_statement ::=
1207 statement_expression:se SEMICOLON {:
1208 ParseNode pn=new ParseNode("expression");
1212 statement_expression ::=
1213 assignment:st {: RESULT=st; :}
1214 | preincrement_expression:st {: RESULT=st; :}
1215 | predecrement_expression:st {: RESULT=st; :}
1216 | postincrement_expression:st {: RESULT=st; :}
1217 | postdecrement_expression:st {: RESULT=st; :}
1218 | method_invocation:st {: RESULT=st; :}
1219 | class_instance_creation_expression:st {: RESULT=st; :}
1221 if_then_statement ::=
1222 IF LPAREN expression:exp RPAREN statement:st {:
1223 ParseNode pn=new ParseNode("ifstatement");
1224 pn.addChild("condition").addChild(exp);
1225 pn.addChild("statement").addChild(st);
1229 if_then_else_statement ::=
1230 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1231 ELSE statement:else_st {:
1232 ParseNode pn=new ParseNode("ifstatement");
1233 pn.addChild("condition").addChild(exp);
1234 pn.addChild("statement").addChild(st);
1235 pn.addChild("else_statement").addChild(else_st);
1239 if_then_else_statement_no_short_if ::=
1240 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1241 ELSE statement_no_short_if:else_st {:
1242 ParseNode pn=new ParseNode("ifstatement");
1243 pn.addChild("condition").addChild(exp);
1244 pn.addChild("statement").addChild(st);
1245 pn.addChild("else_statement").addChild(else_st);
1249 //switch_statement ::=
1250 // SWITCH LPAREN expression RPAREN switch_block
1253 // LBRACE switch_block_statement_groups switch_labels RBRACE
1254 // | LBRACE switch_block_statement_groups RBRACE
1255 // | LBRACE switch_labels RBRACE
1258 //switch_block_statement_groups ::=
1259 // switch_block_statement_group
1260 // | switch_block_statement_groups switch_block_statement_group
1262 //switch_block_statement_group ::=
1263 // switch_labels block_statements
1267 // | switch_labels switch_label
1270 // CASE constant_expression COLON
1275 WHILE LPAREN expression:exp RPAREN statement:st {:
1276 ParseNode pn=new ParseNode("whilestatement");
1277 pn.addChild("condition").addChild(exp);
1278 pn.addChild("statement").addChild(st);
1282 while_statement_no_short_if ::=
1283 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1284 ParseNode pn=new ParseNode("whilestatement");
1285 pn.addChild("condition").addChild(exp);
1286 pn.addChild("statement").addChild(st);
1291 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1292 ParseNode pn=new ParseNode("dowhilestatement");
1293 pn.addChild("condition").addChild(exp);
1294 pn.addChild("statement").addChild(st);
1299 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1300 for_update_opt:update RPAREN statement:st {:
1301 ParseNode pn=new ParseNode("forstatement");
1302 pn.addChild("initializer").addChild(init);
1303 pn.addChild("condition").addChild(exp);
1304 pn.addChild("update").addChild(update);
1305 pn.addChild("statement").addChild(st);
1309 for_statement_no_short_if ::=
1310 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1311 for_update_opt:update RPAREN statement_no_short_if:st {:
1312 ParseNode pn=new ParseNode("forstatement");
1313 pn.addChild("initializer").addChild(init);
1314 pn.addChild("condition").addChild(exp);
1315 pn.addChild("update").addChild(update);
1316 pn.addChild("statement").addChild(st);
1321 {: RESULT=new ParseNode("empty"); :}
1322 | for_init:init {: RESULT=init; :}
1324 for_init ::= statement_expression_list:list {: RESULT=list; :}
1325 | local_variable_declaration:decl {: RESULT=decl; :}
1328 {: RESULT=new ParseNode("empty"); :}
1329 | for_update:update {: RESULT=update; :}
1331 for_update ::= statement_expression_list:list {: RESULT=list; :}
1333 statement_expression_list ::=
1334 statement_expression:expr {:
1335 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1337 | statement_expression_list:list COMMA statement_expression:expr {:
1338 list.addChild(expr);
1343 //identifier_opt ::=
1350 SEMICOLON {: RESULT=new ParseNode("break"); :}
1353 continue_statement ::=
1357 {: RESULT=new ParseNode("continue"); :}
1359 return_statement ::=
1360 RETURN expression_opt:exp SEMICOLON {:
1361 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1363 //throw_statement ::=
1364 // THROW expression SEMICOLON
1366 synchronized_statement ::=
1367 SYNCHRONIZED LPAREN expression:e RPAREN block:b {:
1368 ParseNode pn=new ParseNode("synchronized");
1369 pn.addChild("expr").addChild(e);
1370 pn.addChild("block").addChild(b);
1374 atomic_statement ::=
1376 RESULT=(new ParseNode("atomic")).addChild(blk).getRoot();
1381 ParseNode pn = new ParseNode("sese");
1382 pn.addChild("body").addChild(blk);
1385 | SESE variable_declarator_id:id block:blk {:
1386 ParseNode pn = new ParseNode("sese");
1387 pn.addChild("body").addChild(blk);
1388 pn.addChild("identifier").addChild(id);
1393 // TRY block catches
1394 // | TRY block catches_opt finally
1399 //catches ::= catch_clause
1400 // | catches catch_clause
1403 // CATCH LPAREN formal_parameter RPAREN block
1405 //finally ::= FINALLY block
1407 //assert_statement ::=
1408 // ASSERT expression SEMICOLON
1409 // | ASSERT expression COLON expression SEMICOLON
1412 // 19.12) Expressions
1413 primary ::= primary_no_new_array:st {:
1415 // | array_creation_init:st {:
1418 | array_creation_uninit:st {:
1422 primary_no_new_array ::=
1423 literal:lit {: RESULT=lit; :}
1424 | THIS {: RESULT=new ParseNode("this"); :}
1425 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1426 | class_instance_creation_expression:exp {: RESULT=exp; :}
1427 | field_access:exp {: RESULT=exp; :}
1428 | method_invocation:exp {: RESULT=exp; :}
1429 | array_access:exp {: RESULT=exp; :}
1430 | ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {:
1431 ParseNode pn=new ParseNode("isavailable");
1435 // | primitive_type DOT CLASS
1437 // | array_type DOT CLASS
1441 class_instance_creation_expression ::=
1442 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1443 ParseNode pn=new ParseNode("createobject");
1450 | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1451 ParseNode pn=new ParseNode("createobject");
1455 pn.addChild("global");
1458 | SCRATCH NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1459 ParseNode pn=new ParseNode("createobject");
1463 pn.addChild("scratch");
1466 // Objects we want to track in disjointness analysis
1467 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1468 ParseNode pn=new ParseNode("createobject");
1472 pn.addChild("disjoint").addChild(id);
1475 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
1476 ParseNode pn=new ParseNode("createobject");
1482 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
1483 ParseNode pn=new ParseNode("createobject");
1491 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1492 // | primary DOT NEW IDENTIFIER
1493 // LPAREN argument_list_opt RPAREN {:
1496 // | primary DOT NEW IDENTIFIER
1497 // LPAREN argument_list_opt RPAREN class_body
1498 // | name DOT NEW IDENTIFIER
1499 // LPAREN argument_list_opt RPAREN
1500 // | name DOT NEW IDENTIFIER
1501 // LPAREN argument_list_opt RPAREN class_body
1503 cons_argument_list_opt ::=
1504 {: RESULT=new ParseNode("empty"); :}
1505 | cons_argument_list:args {: RESULT=args; :}
1508 cons_argument_list ::=
1509 IDENTIFIER:id COLON expression:exp {:
1510 ParseNode pn=new ParseNode("cons_argument_list");
1511 ParseNode pnarg=pn.addChild("binding");
1512 pnarg.addChild("var").addChild(id);
1513 pnarg.addChild("exp").addChild(exp);
1516 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1517 ParseNode pnarg=new ParseNode("binding");
1518 pnarg.addChild("var").addChild(id);
1519 pnarg.addChild("exp").addChild(exp);
1520 list.addChild(pnarg);
1525 argument_list_opt ::=
1526 {: RESULT=new ParseNode("empty"); :}
1527 | argument_list:args {: RESULT=args; :}
1532 ParseNode pn=new ParseNode("argument_list");
1536 | argument_list:list COMMA expression:exp {:
1541 array_creation_uninit ::=
1542 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1543 ParseNode pn=new ParseNode("createarray");
1545 pn.addChild(dimexpr);
1546 pn.addChild("dims_opt").setLiteral(dims);
1549 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1550 ParseNode pn=new ParseNode("createarray");
1552 pn.addChild(dimexpr);
1553 pn.addChild("dims_opt").setLiteral(dims);
1556 | GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1557 ParseNode pn=new ParseNode("createarray");
1559 pn.addChild(dimexpr);
1560 pn.addChild("dims_opt").setLiteral(dims);
1561 pn.addChild("global");
1564 | SCRATCH NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1565 ParseNode pn=new ParseNode("createarray");
1567 pn.addChild(dimexpr);
1568 pn.addChild("dims_opt").setLiteral(dims);
1569 pn.addChild("scratch");
1572 | DISJOINT IDENTIFIER:id NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1573 ParseNode pn=new ParseNode("createarray");
1575 pn.addChild(dimexpr);
1576 pn.addChild("dims_opt").setLiteral(dims);
1577 pn.addChild("disjoint").addChild(id);
1580 | GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1581 ParseNode pn=new ParseNode("createarray");
1583 pn.addChild(dimexpr);
1584 pn.addChild("dims_opt").setLiteral(dims);
1585 pn.addChild("global");
1588 | SCRATCH NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1589 ParseNode pn=new ParseNode("createarray");
1591 pn.addChild(dimexpr);
1592 pn.addChild("dims_opt").setLiteral(dims);
1593 pn.addChild("scratch");
1596 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1597 ParseNode pn=new ParseNode("createarray");
1599 pn.addChild(dimexpr);
1600 pn.addChild("dims_opt").setLiteral(dims);
1601 pn.addChild("disjoint").addChild(id);
1605 //array_creation_init ::=
1606 // NEW primitive_type dims array_initializer
1607 // | NEW class_or_interface_type dims array_initializer
1609 dim_exprs ::= dim_expr:exp {:
1610 ParseNode pn=new ParseNode("dim_exprs");
1613 | dim_exprs:base dim_expr:exp {:
1618 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1620 dims_opt ::= {: RESULT=new Integer(0); :}
1621 | dims:dims {: RESULT = dims; :}
1624 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1625 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1629 primary:base DOT IDENTIFIER:id {:
1630 ParseNode pn=new ParseNode("fieldaccess");
1631 pn.addChild("base").addChild(base);
1632 pn.addChild("field").addChild(id);
1635 // | SUPER DOT IDENTIFIER
1636 // | name DOT SUPER DOT IDENTIFIER
1638 method_invocation ::=
1639 name:name LPAREN argument_list_opt:args RPAREN {:
1640 ParseNode pn=new ParseNode("methodinvoke1");
1645 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1646 ParseNode pn=new ParseNode("methodinvoke2");
1647 pn.addChild("base").addChild(base);
1648 pn.addChild("id").addChild(name);
1652 | SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {:
1653 ParseNode name=new ParseNode("name");
1654 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
1655 name.addChild("identifier").addChild(id);
1656 ParseNode pn=new ParseNode("methodinvoke1");
1661 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1664 name:name LBRACK expression:exp RBRACK {:
1665 ParseNode pn=new ParseNode("arrayaccess");
1666 pn.addChild("base").addChild(name);
1667 pn.addChild("index").addChild(exp);
1670 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1671 ParseNode pn=new ParseNode("arrayaccess");
1672 pn.addChild("base").addChild(base);
1673 pn.addChild("index").addChild(exp);
1676 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1677 // ParseNode pn=new ParseNode("arrayaccess");
1678 // pn.addChild("init").addChild(init);
1679 // pn.addChild("index").addChild(exp);
1684 postfix_expression ::=
1687 | name:exp {: RESULT=exp; :}
1688 | postincrement_expression:exp {: RESULT=exp; :}
1689 | postdecrement_expression:exp {: RESULT=exp; :}
1691 postincrement_expression ::=
1692 postfix_expression:exp PLUSPLUS
1693 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1695 postdecrement_expression ::=
1696 postfix_expression:exp MINUSMINUS
1697 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1699 unary_expression ::=
1700 preincrement_expression:exp {: RESULT=exp; :}
1701 | predecrement_expression:exp {: RESULT=exp; :}
1702 | PLUS unary_expression:exp
1703 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1704 | MINUS unary_expression:exp
1705 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1706 | unary_expression_not_plus_minus:exp {:
1709 preincrement_expression ::=
1710 PLUSPLUS unary_expression:exp
1711 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1713 predecrement_expression ::=
1714 MINUSMINUS unary_expression:exp
1715 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1717 unary_expression_not_plus_minus ::=
1718 postfix_expression:exp {:
1720 | COMP unary_expression:exp
1721 {: RESULT=(new ParseNode("comp")).addChild(exp).getRoot(); :}
1722 | NOT unary_expression:exp
1723 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1724 | cast_expression:exp {: RESULT=exp; :}
1727 LPAREN primitive_type:type dims_opt:dims
1728 RPAREN unary_expression:exp {:
1729 ParseNode pn=new ParseNode("cast1");
1730 if (dims.intValue()==0)
1731 pn.addChild("type").addChild(type);
1733 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
1734 arrayt.addChild("basetype").addChild(type);
1735 arrayt.addChild("dims").setLiteral(dims);
1737 pn.addChild("exp").addChild(exp);
1740 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
1741 ParseNode pn=new ParseNode("cast2");
1742 pn.addChild("type").addChild(type);
1743 pn.addChild("exp").addChild(exp);
1747 // | LPAREN name dims RPAREN unary_expression_not_plus_minus
1749 multiplicative_expression ::=
1750 unary_expression:exp {:
1752 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
1753 ParseNode pn=new ParseNode("mult");
1758 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1759 ParseNode pn=new ParseNode("div");
1764 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1765 ParseNode pn=new ParseNode("mod");
1771 additive_expression ::=
1772 multiplicative_expression:exp {:
1774 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
1775 ParseNode pn=new ParseNode("add");
1780 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
1781 ParseNode pn=new ParseNode("sub");
1787 shift_expression ::=
1788 additive_expression:exp {:
1790 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
1791 ParseNode pn=new ParseNode("leftshift");
1796 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
1797 ParseNode pn=new ParseNode("rightshift");
1802 | shift_expression:exp1 URSHIFT additive_expression:exp2 {:
1803 ParseNode pn=new ParseNode("urightshift");
1809 relational_expression ::=
1810 shift_expression:exp {:
1812 | relational_expression:exp1 LT shift_expression:exp2 {:
1813 ParseNode pn=new ParseNode("comp_lt");
1818 | relational_expression:exp1 GT shift_expression:exp2 {:
1819 ParseNode pn=new ParseNode("comp_gt");
1824 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
1825 ParseNode pn=new ParseNode("comp_lte");
1830 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
1831 ParseNode pn=new ParseNode("comp_gte");
1836 | relational_expression:exp INSTANCEOF reference_type:type {:
1837 ParseNode pn=new ParseNode("instanceof");
1838 pn.addChild("exp").addChild(exp);
1844 equality_expression ::=
1845 relational_expression:exp {:
1847 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
1848 ParseNode pn=new ParseNode("equal");
1853 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
1854 ParseNode pn=new ParseNode("not_equal");
1861 equality_expression:exp {:
1863 | and_expression:exp1 AND equality_expression:exp2 {:
1864 ParseNode pn=new ParseNode("bitwise_and");
1870 exclusive_or_expression ::=
1871 and_expression:expr {:
1874 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
1875 ParseNode pn=new ParseNode("bitwise_xor");
1881 inclusive_or_expression ::=
1882 exclusive_or_expression:exclor {:
1884 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
1885 ParseNode pn=new ParseNode("bitwise_or");
1891 conditional_and_expression ::=
1892 inclusive_or_expression:inclor {:
1894 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1895 ParseNode pn=new ParseNode("logical_and");
1901 conditional_or_expression ::=
1902 conditional_and_expression:condand {:
1904 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
1905 ParseNode pn=new ParseNode("logical_or");
1911 conditional_expression ::=
1912 conditional_or_expression:condor {:
1914 | conditional_or_expression:condor QUESTION expression:exptrue
1915 COLON conditional_expression:expfalse {:
1916 ParseNode pn=new ParseNode("tert");
1917 pn.addChild("cond").addChild(condor);
1918 pn.addChild("trueexpr").addChild(exptrue);
1919 pn.addChild("falseexpr").addChild(expfalse);
1923 getoffset_expression ::=
1924 GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
1925 ParseNode pn = new ParseNode("getoffset");
1927 pn.addChild("field").addChild(id);
1932 assignment_expression ::=
1933 conditional_expression:expr {:
1935 assignment:assign {:
1937 getoffset_expression:expr {:
1940 // semantic check necessary here to ensure a valid left-hand side.
1941 // allowing a parenthesized variable here on the lhs was introduced in
1942 // JLS 2; thanks to Eric Blake for pointing this out.
1943 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
1944 ParseNode pn=new ParseNode("assignment");
1945 pn.addChild("op").addChild(op);
1946 ParseNode pnargs=pn.addChild("args");
1947 pnargs.addChild(lvalue);
1948 pnargs.addChild(rvalue);
1952 assignment_operator ::=
1953 EQ {: RESULT=new ParseNode("eq"); :}
1954 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
1955 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
1956 | MODEQ {: RESULT=new ParseNode("modeq"); :}
1957 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
1958 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
1959 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
1960 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
1961 | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
1962 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
1963 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
1964 | OREQ {: RESULT=new ParseNode("oreq"); :}
1967 {: RESULT=new ParseNode("empty"); :}
1971 expression ::= assignment_expression:exp {:
1974 //constant_expression ::=