3 import java_cup.runtime.*;
7 /* Java 1.4 parser for CUP.
8 * Copyright (C) 2002-2003 C. Scott Ananian <cananian@alumni.princeton.edu>
9 * This program is released under the terms of the GPL; see the file
10 * COPYING for more details. There is NO WARRANTY on this code.
14 JDK 1.4 Features added:
16 statement_without_trailing_substatement ::= ...
19 ASSERT expression SEMICOLON
20 | ASSERT expression COLON expression SEMICOLON
26 public Parser(Lexer l) {
31 public void syntax_error(java_cup.runtime.Symbol current) {
32 report_error("Syntax error (" + current.sym + ")", current);
34 public void report_error(String message, java_cup.runtime.Symbol info) {
35 lexer.errorMsg(message, info);
39 scan with {: return lexer.nextToken(); :};
41 terminal BOOLEAN; // primitive_type
42 terminal BYTE, SHORT, INT, LONG, CHAR; // integral_type
43 terminal FLOAT, DOUBLE; // floating_point_type
44 terminal LBRACK, RBRACK; // array_type
45 terminal java.lang.String IDENTIFIER; // name
46 terminal DOT; // qualified_name
47 terminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;
48 terminal PACKAGE; // package_declaration
49 terminal IMPORT; // import_declaration
50 terminal PUBLIC, PROTECTED, PRIVATE; // modifier
51 terminal STATIC; // modifier
52 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
53 terminal CLASS; // class_declaration
54 terminal EXTENDS; // super
55 //terminal IMPLEMENTS; // interfaces
56 terminal VOID; // method_header
57 terminal THROWS; // throws
58 terminal THIS, SUPER; // explicit_constructor_invocation
59 //terminal INTERFACE; // interface_declaration
60 terminal IF, ELSE; // if_then_statement, if_then_else_statement
61 terminal SWITCH; // switch_statement
62 terminal CASE, DEFAULT; // switch_label
63 terminal DO, WHILE; // while_statement, do_statement
64 terminal FOR; // for_statement
65 terminal BREAK; // break_statement
66 terminal CONTINUE; // continue_statement
67 terminal RETURN; // return_statement
68 terminal THROW; // throw_statement
69 terminal TRY; // try_statement
70 terminal CATCH; // catch_clause
71 terminal FINALLY; // finally
72 terminal NEW; // class_instance_creation_expression
73 terminal PLUSPLUS; // postincrement_expression
74 terminal MINUSMINUS; // postdecrement_expression
75 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
76 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
77 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
78 terminal EQEQ, NOTEQ; // equality_expression
79 terminal AND; // and_expression
80 terminal XOR; // exclusive_or_expression
81 terminal OR; // inclusive_or_expression
82 terminal ANDAND; // conditional_and_expression
83 terminal OROR; // conditional_or_expression
84 terminal QUESTION; // conditional_expression
85 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
86 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
87 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
89 terminal java.lang.Number INTEGER_LITERAL;
90 terminal java.lang.Number FLOATING_POINT_LITERAL;
91 terminal java.lang.Boolean BOOLEAN_LITERAL;
92 terminal java.lang.Character CHARACTER_LITERAL;
93 terminal java.lang.String STRING_LITERAL;
94 terminal NULL_LITERAL;
96 // Reserved but unused:
98 // strictfp keyword, new in Java 1.2
100 // assert keyword, new in Java 1.4
101 terminal ASSERT; // assert_statement
102 // lexer compatibility with Java 1.5
107 // 19.2) The Syntactic Grammar
108 non terminal ParseNode goal;
109 // 19.3) Lexical Structure
110 non terminal ParseNode literal;
111 // 19.4) Types, Values, and Variables
112 non terminal ParseNode type, primitive_type, numeric_type;
113 non terminal ParseNode integral_type, floating_point_type;
114 non terminal ParseNode reference_type;
115 non terminal ParseNode class_or_interface_type;
116 non terminal ParseNode class_type;
117 //non terminal ParseNode interface_type;
118 non terminal ParseNode array_type;
120 non terminal ParseNode name, simple_name, qualified_name;
122 non terminal ParseNode compilation_unit;
123 non terminal ParseNode package_declaration_opt, package_declaration;
124 non terminal ParseNode import_declarations_opt, import_declarations;
125 non terminal ParseNode type_declarations_opt, type_declarations;
126 non terminal ParseNode import_declaration;
127 non terminal ParseNode single_type_import_declaration;
128 non terminal ParseNode type_import_on_demand_declaration;
129 non terminal ParseNode type_declaration;
130 // 19.7) Productions used only in the LALR(1) grammar
131 non terminal ParseNode modifiers_opt, modifiers, modifier;
132 // 19.8.1) Class Declaration
133 non terminal ParseNode class_declaration, super, super_opt;
134 //non terminal interfaces, interfaces_opt, interface_type_list;
135 non terminal ParseNode class_body;
136 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
137 non terminal ParseNode class_body_declaration, class_member_declaration;
138 // 19.8.2) Field Declarations
139 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
140 non terminal ParseNode variable_declarator_id;
141 non terminal ParseNode variable_initializer;
142 // 19.8.3) Method Declarations
143 non terminal ParseNode method_declaration, method_header, method_declarator;
144 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
145 non terminal ParseNode formal_parameter;
146 //non terminal ParseNode throws_opt;
147 //non terminal ParseNode throws;
148 //non terminal ParseNode class_type_list;
149 non terminal ParseNode method_body;
150 // 19.8.4) Static Initializers
151 //non terminal ParseNode static_initializer;
152 // 19.8.5) Constructor Declarations
153 non terminal ParseNode constructor_declaration, constructor_declarator;
154 non terminal ParseNode constructor_body;
155 non terminal ParseNode explicit_constructor_invocation;
156 // 19.9.1) Interface Declarations
157 //non terminal ParseNode interface_declaration;
158 //non terminal ParseNode extends_interfaces_opt, extends_interfaces;
159 //non terminal ParseNode interface_body;
160 //non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
161 //non terminal ParseNode interface_member_declaration, constant_declaration;
162 //non terminal ParseNode abstract_method_declaration;
164 //non terminal ParseNode array_initializer;
165 //non terminal ParseNode variable_initializers;
166 // 19.11) Blocks and Statements
167 non terminal ParseNode block;
168 non terminal ParseNode block_statements_opt, block_statements, block_statement;
169 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
170 non terminal ParseNode statement, statement_no_short_if;
171 non terminal ParseNode statement_without_trailing_substatement;
172 non terminal ParseNode empty_statement;
173 //non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
174 non terminal ParseNode expression_statement, statement_expression;
175 non terminal ParseNode if_then_statement;
176 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
177 //non terminal ParseNode switch_statement, switch_block;
178 //non terminal ParseNode switch_block_statement_groups;
179 //non terminal ParseNode switch_block_statement_group;
180 //non terminal ParseNode switch_labels, switch_label;
181 non terminal ParseNode while_statement, while_statement_no_short_if;
182 non terminal ParseNode do_statement;
183 non terminal ParseNode for_statement, for_statement_no_short_if;
184 non terminal ParseNode for_init_opt, for_init;
185 non terminal ParseNode for_update_opt, for_update;
186 non terminal ParseNode statement_expression_list;
187 //non terminal ParseNode identifier_opt;
188 non terminal ParseNode break_statement, continue_statement;
189 non terminal ParseNode return_statement;
190 //non terminal ParseNode throw_statement;
191 //non terminal ParseNode synchronized_statement, try_statement;
192 //non terminal ParseNode catches_opt;
193 //non terminal ParseNode catches, catch_clause;
194 //non terminal ParseNode finally;
195 //non terminal ParseNode assert_statement;
196 // 19.12) Expressions
197 non terminal ParseNode primary, primary_no_new_array;
198 non terminal ParseNode class_instance_creation_expression;
199 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
200 non terminal ParseNode argument_list_opt, argument_list;
201 //non terminal ParseNode array_creation_init;
202 non terminal ParseNode array_creation_uninit;
203 non terminal ParseNode dim_exprs, dim_expr;
204 non terminal Integer dims_opt, dims;
205 non terminal ParseNode field_access, method_invocation;
206 non terminal ParseNode array_access;
207 non terminal ParseNode postfix_expression;
208 non terminal ParseNode postincrement_expression, postdecrement_expression;
209 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
210 non terminal ParseNode preincrement_expression, predecrement_expression;
211 non terminal ParseNode cast_expression;
212 non terminal ParseNode multiplicative_expression, additive_expression;
213 non terminal ParseNode shift_expression, relational_expression, equality_expression;
214 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
215 non terminal ParseNode conditional_and_expression, conditional_or_expression;
216 non terminal ParseNode conditional_expression;
217 non terminal ParseNode assignment_expression;
218 non terminal ParseNode assignment;
219 non terminal ParseNode assignment_operator;
220 non terminal ParseNode expression_opt, expression;
221 //non terminal ParseNode constant_expression;
222 //failure aware computation keywords
225 terminal ISAVAILABLE;
230 non terminal ParseNode flag_declaration;
231 non terminal ParseNode task_declaration;
232 non terminal ParseNode task_parameter_list;
233 non terminal ParseNode task_parameter;
234 non terminal ParseNode flag_expression;
235 non terminal ParseNode flag_andexpression;
236 non terminal ParseNode flag_notexpression;
237 non terminal ParseNode task_exitstatement;
238 non terminal ParseNode flag_effects_opt;
239 non terminal ParseNode flag_effects;
240 non terminal ParseNode flag_effect;
241 non terminal ParseNode flag_list;
242 non terminal ParseNode flag_list_opt;
243 non terminal ParseNode flag_change;
245 non terminal ParseNode cons_checks_opt;
246 non terminal ParseNode cons_checks;
247 non terminal ParseNode cons_check;
249 non terminal ParseNode tag_variable_declaration_statement;
250 non terminal ParseNode tag_expression_list;
251 non terminal ParseNode tag_expression;
252 non terminal ParseNode tag_list;
253 non terminal ParseNode tag_list_opt;
254 non terminal ParseNode tag_change;
256 //distributed transaction keywords
260 non terminal ParseNode atomic_statement;
261 non terminal ParseNode getoffset_expression;
263 //disjointness for Java
266 //coarse-grain parallelization
268 non terminal ParseNode sese_statement;
276 TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN
280 ParseNode pn=new ParseNode("task_declaration");
281 pn.addChild("name").addChild(id);
284 pn.addChild("body").addChild(body);
288 task_parameter_list ::=
290 ParseNode pn=new ParseNode("task_parameter_list");
294 | task_parameter_list:fpl COMMA task_parameter:fp {:
301 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
302 ParseNode pn=new ParseNode("task_parameter");
305 pn.addChild("flag").addChild(exp);
308 | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
309 ParseNode pn=new ParseNode("task_parameter");
312 pn.addChild("flag").addChild(exp);
313 pn.addChild("tag").addChild(texp);
316 | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
317 ParseNode pn=new ParseNode("task_parameter");
320 pn.addChild("tag").addChild(texp);
323 | OPTIONAL task_parameter:fp {:
324 ParseNode pn=new ParseNode("task_parameter");
325 pn.addChild("optional").addChild(fp);
331 tag_expression_list ::= tag_expression:te {:
332 ParseNode pn=new ParseNode("tag_expression_list");
336 | tag_expression_list:tel COMMA tag_expression:te {:
342 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {:
343 ParseNode pn=new ParseNode("tag_expression");
344 pn.addChild("type").addChild(type);
345 pn.addChild("single").addChild(id);
350 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
351 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
352 | {: RESULT = new ParseNode("empty"); :}
355 tag_list ::= tag_change:fc {:
356 ParseNode pn=new ParseNode("tag_list");
360 | tag_list:fl COMMA tag_change:fc {:
365 tag_change ::= IDENTIFIER:id {:
366 RESULT=new ParseNode("name").addChild(id).getRoot();
368 | NOT IDENTIFIER:id {:
369 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
373 flag_andexpression:exp {:
376 | flag_expression:exp1 OROR flag_andexpression:exp2 {:
377 ParseNode pn=new ParseNode("or");
384 flag_andexpression ::=
385 flag_notexpression:exp {: RESULT=exp; :}
386 | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {:
387 ParseNode pn=new ParseNode("and");
394 flag_notexpression ::=
395 NOT flag_notexpression:exp {:
396 ParseNode pn=new ParseNode("not");
400 | LPAREN flag_expression:exp RPAREN {:
404 ParseNode pn=new ParseNode("name");
410 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
411 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
414 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
415 | {: RESULT = new ParseNode("empty"); :}
418 cons_checks ::= cons_check:cc {:
419 ParseNode pn=new ParseNode("cons_checks");
423 | cons_checks:ccs COMMA cons_check:cc {:
428 cons_check ::= IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {:
429 ParseNode pn=new ParseNode("cons_check");
430 pn.addChild("name").addChild("identifier").addChild(name);
435 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
436 | {: RESULT = new ParseNode("empty"); :}
439 flag_effects ::= flag_effect:fe {:
440 ParseNode pn=new ParseNode("flag_effects_list");
444 | flag_effects:fes COMMA flag_effect:fe {:
449 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {:
450 ParseNode pn=new ParseNode("flag_effect");
451 pn.addChild("name").addChild(id);
456 | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
457 ParseNode pn=new ParseNode("flag_effect");
458 pn.addChild("name").addChild(id);
463 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
464 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
466 {: RESULT = new ParseNode("empty"); :}
469 flag_list ::= flag_change:fc {:
470 ParseNode pn=new ParseNode("flag_list");
474 | flag_list:fl COMMA flag_change:fc {:
479 flag_change ::= IDENTIFIER:id {:
480 RESULT=new ParseNode("name").addChild(id).getRoot();
483 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
486 // 19.2) The Syntactic Grammar
487 goal ::= compilation_unit:cu
493 // 19.3) Lexical Structure.
496 literal ::= INTEGER_LITERAL:integer_lit
498 ParseNode pn=new ParseNode("literal");
499 pn.addChild("integer").setLiteral(integer_lit);
502 | FLOATING_POINT_LITERAL:float_lit
504 ParseNode pn=new ParseNode("literal");
505 pn.addChild("float").setLiteral(float_lit);
508 | BOOLEAN_LITERAL:boolean_lit
510 ParseNode pn=new ParseNode("literal");
511 pn.addChild("boole
\1aan").setLiteral(boolean_lit);
514 | CHARACTER_LITERAL:char_lit
516 ParseNode pn=new ParseNode("literal");
517 pn.addChild("char").setLiteral(char_lit);
520 | STRING_LITERAL:string_lit
522 ParseNode pn=new ParseNode("literal");
523 pn.addChild("string").setLiteral(string_lit);
528 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
532 // 19.4) Types, Values, and Variables
533 type ::= primitive_type:type {: RESULT=type; :}
534 | reference_type:type {: RESULT=type; :}
538 numeric_type:type {: RESULT=type; :}
539 | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
541 numeric_type::= integral_type:type {: RESULT=type; :}
542 | floating_point_type:type {: RESULT=type; :}
545 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
546 | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
547 | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
548 | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
549 | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
551 floating_point_type ::=
552 FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
553 | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
557 class_or_interface_type:type {: RESULT=type; :}
558 | array_type:type {: RESULT=type; :}
560 class_or_interface_type ::= name:name {:
561 RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot();
564 class_type ::= class_or_interface_type:type {: RESULT=type; :};
565 //interface_type ::= class_or_interface_type;
567 array_type ::= primitive_type:prim dims:dims {:
568 ParseNode pn=(new ParseNode("type")).addChild("array");
569 pn.addChild("basetype").addChild(prim);
570 pn.addChild("dims").setLiteral(dims);
573 | name:name dims:dims {:
574 ParseNode pn=(new ParseNode("type")).addChild("array");
575 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
576 pn.addChild("dims").setLiteral(dims);
582 name ::= simple_name:name {: RESULT=name; :}
583 | qualified_name:name {: RESULT=name; :}
585 simple_name ::= IDENTIFIER:id {:
586 RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot();
589 qualified_name ::= name:name DOT IDENTIFIER:id {:
590 ParseNode pn=new ParseNode("name");
591 pn.addChild("base").addChild(name);
592 pn.addChild("identifier").addChild(id);
599 package_declaration_opt:pdo
600 import_declarations_opt:ido
601 type_declarations_opt:tdo {:
602 ParseNode pn=new ParseNode("compilation_unit");
604 pn.addChild("packages").addChild(pdo);
605 pn.addChild("imports").addChild(ido);
609 package_declaration_opt ::= package_declaration:pdo {:
612 {: RESULT=new ParseNode("empty"); :}
615 import_declarations_opt ::= import_declarations:ido {:
618 {: RESULT=new ParseNode("empty"); :}
620 type_declarations_opt ::= type_declarations:tds {:
623 {: RESULT=new ParseNode("empty"); :}
626 import_declarations ::=
627 import_declaration:id {:
628 ParseNode pn=new ParseNode("import_decls_list");
632 | import_declarations:ids import_declaration:id {:
638 type_declarations ::=
639 type_declaration:td {:
640 ParseNode pn=new ParseNode("type_declaration_list");
644 | type_declarations:tds type_declaration:td {:
650 package_declaration ::=
651 PACKAGE name:name SEMICOLON {:
652 ParseNode pn=new ParseNode("package");
657 import_declaration ::=
658 single_type_import_declaration:sid {: RESULT=sid; :}
659 | type_import_on_demand_declaration:iod {: RESULT=iod; :}
661 single_type_import_declaration ::=
662 IMPORT name:name SEMICOLON {:
663 ParseNode pn=new ParseNode("import_single");
668 type_import_on_demand_declaration ::=
669 IMPORT name:name DOT MULT SEMICOLON {:
670 ParseNode pn=new ParseNode("import_ondemand");
681 | task_declaration:td
685 // | interface_declaration
686 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
689 // 19.7) Productions used only in the LALR(1) grammar
691 {: RESULT=new ParseNode("empty"); :}
696 modifiers ::= modifier:mo {:
697 ParseNode pn=new ParseNode("modifier_list");
701 | modifiers:mos modifier:mo {:
707 PUBLIC {: RESULT=new ParseNode("public"); :}|
708 PROTECTED {: RESULT=new ParseNode("protected"); :}|
709 PRIVATE {: RESULT=new ParseNode("private"); :}|
710 STATIC {: RESULT=new ParseNode("static"); :} |
712 FINAL {: RESULT=new ParseNode("final"); :}|
713 NATIVE {: RESULT=new ParseNode("native"); :} |
714 SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
715 ATOMIC {: RESULT=new ParseNode("atomic"); :}
718 // STRICTFP // note that semantic analysis must check that the
719 // context of the modifier allows strictfp.
724 // 19.8.1) Class Declaration:
725 class_declaration ::=
726 modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so //interfaces_opt
729 ParseNode pn=new ParseNode("class_declaration");
730 pn.addChild("modifiers").addChild(mo);
731 pn.addChild("name").addChild(id);
732 pn.addChild("super").addChild(so);
733 pn.addChild("classbody").addChild(body);
737 super ::= EXTENDS class_type:classtype {:
742 {: RESULT=new ParseNode("empty"); :}
748 //interfaces ::= IMPLEMENTS interface_type_list
753 //interface_type_list ::=
755 // | interface_type_list COMMA interface_type
758 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
761 class_body_declarations_opt ::=
762 {: RESULT=new ParseNode("empty"); :}
763 | class_body_declarations:cbd {: RESULT=cbd; :};
765 class_body_declarations ::=
766 class_body_declaration:cbd {:
767 ParseNode pn=new ParseNode("class_body_declaration_list");
771 | class_body_declarations:cbds class_body_declaration:cbd {:
777 class_body_declaration ::=
778 class_member_declaration:member {:
779 RESULT=(new ParseNode("member")).addChild(member).getRoot();
781 // | static_initializer
782 | constructor_declaration:constructor {:
783 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
786 RESULT=(new ParseNode("block")).addChild(block).getRoot();
789 class_member_declaration ::=
790 //failure aware computation
791 flag_declaration:flag {:
792 RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
795 field_declaration:field {:
796 RESULT=(new ParseNode("field")).addChild(field).getRoot();
798 | method_declaration:method {:
799 RESULT=(new ParseNode("method")).addChild(method).getRoot();
801 /* repeat the prod for 'class_declaration' here: */
802 // | modifiers_opt CLASS IDENTIFIER super_opt class_body
803 // | interface_declaration
804 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
807 //Failure aware computation
809 FLAG IDENTIFIER:id SEMICOLON {:
810 ParseNode pn=new ParseNode("flag_declaration");
811 pn.addChild("name").addChild(id);
814 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {:
815 ParseNode pn=new ParseNode("flag_declaration");
816 pn.addChild("name").addChild(id);
817 pn.addChild("external");
822 // 19.8.2) Field Declarations
823 field_declaration ::=
824 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {:
825 ParseNode pn=new ParseNode("field_declaration");
826 pn.addChild("modifier").addChild(mo);
827 pn.addChild("type").addChild(type);
828 pn.addChild("variables").addChild(var);
831 modifiers_opt:mo GLOBAL type:type variable_declarators:var SEMICOLON {:
832 ParseNode pn=new ParseNode("field_declaration");
833 pn.addChild("modifier").addChild(mo);
834 pn.addChild("type").addChild(type);
835 pn.addChild("variables").addChild(var);
836 pn.addChild("global");
841 variable_declarators ::=
842 variable_declarator:vd {:
843 ParseNode pn=new ParseNode("variable_declarators_list");
847 | variable_declarators:vds COMMA variable_declarator:vd {:
852 variable_declarator ::=
853 variable_declarator_id:id {:
854 ParseNode pn=new ParseNode("variable_declarator");
858 | variable_declarator_id:id EQ variable_initializer:init {:
859 ParseNode pn=new ParseNode("variable_declarator");
861 pn.addChild("initializer").addChild(init);
865 variable_declarator_id ::=
867 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
868 | variable_declarator_id:id LBRACK RBRACK {:
869 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
871 variable_initializer ::=
872 expression:exp {: RESULT=exp; :}
873 // | array_initializer
876 // 19.8.3) Method Declarations
877 method_declaration ::=
878 method_header:header method_body:body {:
879 ParseNode pn=new ParseNode("method_declaration");
881 pn.addChild("body").addChild(body);
886 modifiers_opt:mo type:type method_declarator:decl //throws_opt
888 ParseNode pn=new ParseNode("method_header");
889 pn.addChild("modifiers").addChild(mo);
890 pn.addChild("returntype").addChild(type);
894 | modifiers_opt:mo VOID method_declarator:decl //throws_opt
896 ParseNode pn=new ParseNode("method_header");
897 pn.addChild("modifiers").addChild(mo);
902 method_declarator ::=
903 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {:
904 ParseNode pn=new ParseNode("method_declarator");
905 pn.addChild("name").addChild(id);
906 pn.addChild("parameters").addChild(params);
909 // | method_declarator LBRACK RBRACK // deprecated
910 // be careful; the above production also allows 'void foo() []'
912 formal_parameter_list_opt ::=
913 {: RESULT=new ParseNode("empty"); :}
914 | formal_parameter_list:fpl {:
918 formal_parameter_list ::=
919 formal_parameter:fp {:
920 ParseNode pn=new ParseNode("formal_parameter_list");
924 | formal_parameter_list:fpl COMMA formal_parameter:fp {:
930 type:type variable_declarator_id:name {:
931 ParseNode pn=new ParseNode("formal_parameter");
937 TAG variable_declarator_id:name {:
938 ParseNode pn=new ParseNode("tag_parameter");
942 // | FINAL type variable_declarator_id
947 //throws ::= THROWS class_type_list
949 //class_type_list ::=
951 // | class_type_list COMMA class_type
953 method_body ::= block:block {:
956 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
959 // 19.8.4) Static Initializers
960 //static_initializer ::=
964 // 19.8.5) Constructor Declarations
965 constructor_declaration ::=
966 modifiers_opt:mo constructor_declarator:cd
968 constructor_body:body {:
969 ParseNode pn=new ParseNode("constructor_declaration");
970 pn.addChild("modifiers").addChild(mo);
972 pn.addChild("body").addChild(body);
975 modifiers_opt:mo GLOBAL constructor_declarator:cd
977 constructor_body:body {:
978 ParseNode pn=new ParseNode("constructor_declaration");
979 pn.addChild("global");
980 pn.addChild("modifiers").addChild(mo);
982 pn.addChild("body").addChild(body);
986 constructor_declarator ::=
987 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {:
988 ParseNode pn=new ParseNode("constructor_declarator");
990 pn.addChild("parameters").addChild(fplo);
995 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {:
996 ParseNode pn=new ParseNode("constructor_body");
1001 LBRACE explicit_constructor_invocation:eci RBRACE {:
1002 ParseNode pn=new ParseNode("constructor_body");
1006 LBRACE block_statements:block RBRACE {:
1007 ParseNode pn=new ParseNode("constructor_body");
1011 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1013 explicit_constructor_invocation ::=
1014 // THIS LPAREN argument_list_opt RPAREN SEMICOLON
1016 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1017 ParseNode pn=new ParseNode("superinvoke");
1021 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1022 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1027 // 19.9.1) Interface Declarations
1028 //interface_declaration ::=
1029 // modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
1032 //extends_interfaces_opt ::=
1033 // | extends_interfaces
1035 //extends_interfaces ::=
1036 // EXTENDS interface_type
1037 // | extends_interfaces COMMA interface_type
1039 //interface_body ::=
1040 // LBRACE interface_member_declarations_opt RBRACE
1042 //interface_member_declarations_opt ::=
1043 // | interface_member_declarations
1045 //interface_member_declarations ::=
1046 // interface_member_declaration
1047 // | interface_member_declarations interface_member_declaration
1049 //interface_member_declaration ::=
1050 // constant_declaration
1051 // | abstract_method_declaration
1052 // | class_declaration
1053 // | interface_declaration
1056 //constant_declaration ::=
1057 // field_declaration
1058 // // need to semantically check that modifiers of field declaration
1059 // // include only PUBLIC, STATIC, or FINAL. Other modifiers are
1062 //abstract_method_declaration ::=
1063 // method_header SEMICOLON
1068 //array_initializer ::=
1069 // LBRACE variable_initializers COMMA RBRACE
1070 // | LBRACE variable_initializers RBRACE
1071 // | LBRACE COMMA RBRACE
1074 //variable_initializers ::=
1075 // variable_initializer
1076 // | variable_initializers COMMA variable_initializer
1079 // 19.11) Blocks and Statements
1080 block ::= LBRACE block_statements_opt:bso RBRACE {:
1084 block_statements_opt ::=
1085 {: RESULT=new ParseNode("empty"); :}
1086 | block_statements:bs {:
1090 block_statements ::=
1091 block_statement:bs {:
1092 ParseNode pn=new ParseNode("block_statement_list");
1096 | block_statements:bss block_statement:bs {:
1102 tag_variable_declaration_statement:tvds {:
1105 | local_variable_declaration_statement:lvds {:
1108 | statement:statement {:
1111 // | class_declaration
1112 // | interface_declaration
1114 tag_variable_declaration_statement ::=
1115 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
1116 ParseNode pn=new ParseNode("tag_declaration");
1117 pn.addChild("single").addChild(id);
1118 pn.addChild("type").addChild(type);
1122 local_variable_declaration_statement ::=
1123 local_variable_declaration:lvd SEMICOLON {:
1127 local_variable_declaration ::=
1128 type:type variable_declarators:var {:
1129 ParseNode pn=new ParseNode("local_variable_declaration");
1134 // | FINAL type variable_declarators
1136 statement ::= statement_without_trailing_substatement:st {:
1139 // | labeled_statement:st {: RESULT=st; :}
1140 | if_then_statement:st {: RESULT=st; :}
1141 | if_then_else_statement:st {: RESULT=st; :}
1142 | while_statement:st {: RESULT=st; :}
1143 | for_statement:st {: RESULT=st; :}
1145 statement_no_short_if ::=
1146 statement_without_trailing_substatement:st {: RESULT=st; :}
1147 // | labeled_statement_no_short_if:st {: RESULT=st; :}
1148 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
1149 | while_statement_no_short_if:st {: RESULT=st; :}
1150 | for_statement_no_short_if:st {: RESULT=st; :}
1152 statement_without_trailing_substatement ::=
1153 block:st {: RESULT=st; :}
1154 | empty_statement:st {: RESULT=st; :}
1155 | expression_statement:st {: RESULT=st; :}
1156 // | switch_statement
1157 | do_statement:dos {:RESULT=dos; :}
1158 | break_statement:st {: RESULT=st; :}
1159 | continue_statement:st {: RESULT=st; :}
1160 | return_statement:st {: RESULT=st; :}
1161 | task_exitstatement:st {: RESULT=st; :}
1162 | atomic_statement:st {: RESULT=st; :}
1163 | sese_statement:st {: RESULT=st; :}
1164 // | synchronized_statement
1165 // | throw_statement
1167 // | assert_statement
1170 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1172 //labeled_statement ::=
1173 // IDENTIFIER COLON statement
1175 //labeled_statement_no_short_if ::=
1176 // IDENTIFIER COLON statement_no_short_if
1178 expression_statement ::=
1179 statement_expression:se SEMICOLON {:
1180 ParseNode pn=new ParseNode("expression");
1184 statement_expression ::=
1185 assignment:st {: RESULT=st; :}
1186 | preincrement_expression:st {: RESULT=st; :}
1187 | predecrement_expression:st {: RESULT=st; :}
1188 | postincrement_expression:st {: RESULT=st; :}
1189 | postdecrement_expression:st {: RESULT=st; :}
1190 | method_invocation:st {: RESULT=st; :}
1191 | class_instance_creation_expression:st {: RESULT=st; :}
1193 if_then_statement ::=
1194 IF LPAREN expression:exp RPAREN statement:st {:
1195 ParseNode pn=new ParseNode("ifstatement");
1196 pn.addChild("condition").addChild(exp);
1197 pn.addChild("statement").addChild(st);
1201 if_then_else_statement ::=
1202 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1203 ELSE statement:else_st {:
1204 ParseNode pn=new ParseNode("ifstatement");
1205 pn.addChild("condition").addChild(exp);
1206 pn.addChild("statement").addChild(st);
1207 pn.addChild("else_statement").addChild(else_st);
1211 if_then_else_statement_no_short_if ::=
1212 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1213 ELSE statement_no_short_if:else_st {:
1214 ParseNode pn=new ParseNode("ifstatement");
1215 pn.addChild("condition").addChild(exp);
1216 pn.addChild("statement").addChild(st);
1217 pn.addChild("else_statement").addChild(else_st);
1221 //switch_statement ::=
1222 // SWITCH LPAREN expression RPAREN switch_block
1225 // LBRACE switch_block_statement_groups switch_labels RBRACE
1226 // | LBRACE switch_block_statement_groups RBRACE
1227 // | LBRACE switch_labels RBRACE
1230 //switch_block_statement_groups ::=
1231 // switch_block_statement_group
1232 // | switch_block_statement_groups switch_block_statement_group
1234 //switch_block_statement_group ::=
1235 // switch_labels block_statements
1239 // | switch_labels switch_label
1242 // CASE constant_expression COLON
1247 WHILE LPAREN expression:exp RPAREN statement:st {:
1248 ParseNode pn=new ParseNode("whilestatement");
1249 pn.addChild("condition").addChild(exp);
1250 pn.addChild("statement").addChild(st);
1254 while_statement_no_short_if ::=
1255 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1256 ParseNode pn=new ParseNode("whilestatement");
1257 pn.addChild("condition").addChild(exp);
1258 pn.addChild("statement").addChild(st);
1263 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1264 ParseNode pn=new ParseNode("dowhilestatement");
1265 pn.addChild("condition").addChild(exp);
1266 pn.addChild("statement").addChild(st);
1271 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1272 for_update_opt:update RPAREN statement:st {:
1273 ParseNode pn=new ParseNode("forstatement");
1274 pn.addChild("initializer").addChild(init);
1275 pn.addChild("condition").addChild(exp);
1276 pn.addChild("update").addChild(update);
1277 pn.addChild("statement").addChild(st);
1281 for_statement_no_short_if ::=
1282 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1283 for_update_opt:update RPAREN statement_no_short_if:st {:
1284 ParseNode pn=new ParseNode("forstatement");
1285 pn.addChild("initializer").addChild(init);
1286 pn.addChild("condition").addChild(exp);
1287 pn.addChild("update").addChild(update);
1288 pn.addChild("statement").addChild(st);
1293 {: RESULT=new ParseNode("empty"); :}
1294 | for_init:init {: RESULT=init; :}
1296 for_init ::= statement_expression_list:list {: RESULT=list; :}
1297 | local_variable_declaration:decl {: RESULT=decl; :}
1300 {: RESULT=new ParseNode("empty"); :}
1301 | for_update:update {: RESULT=update; :}
1303 for_update ::= statement_expression_list:list {: RESULT=list; :}
1305 statement_expression_list ::=
1306 statement_expression:expr {:
1307 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1309 | statement_expression_list:list COMMA statement_expression:expr {:
1310 list.addChild(expr);
1315 //identifier_opt ::=
1322 SEMICOLON {: RESULT=new ParseNode("break"); :}
1325 continue_statement ::=
1329 {: RESULT=new ParseNode("continue"); :}
1331 return_statement ::=
1332 RETURN expression_opt:exp SEMICOLON {:
1333 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1335 //throw_statement ::=
1336 // THROW expression SEMICOLON
1338 //synchronized_statement ::=
1339 // SYNCHRONIZED LPAREN expression RPAREN block
1341 atomic_statement ::=
1343 RESULT=(new ParseNode("atomic")).addChild(blk).getRoot();
1348 // SESE variable_declarator_id:id LBRACE statement:st RBRACE {:
1351 ParseNode pn = new ParseNode("sese");
1353 // pn.addChild("identifier").addChild(id);
1355 pn.addChild("body").addChild(blk);
1360 // TRY block catches
1361 // | TRY block catches_opt finally
1366 //catches ::= catch_clause
1367 // | catches catch_clause
1370 // CATCH LPAREN formal_parameter RPAREN block
1372 //finally ::= FINALLY block
1374 //assert_statement ::=
1375 // ASSERT expression SEMICOLON
1376 // | ASSERT expression COLON expression SEMICOLON
1379 // 19.12) Expressions
1380 primary ::= primary_no_new_array:st {:
1382 // | array_creation_init:st {:
1385 | array_creation_uninit:st {:
1389 primary_no_new_array ::=
1390 literal:lit {: RESULT=lit; :}
1391 | THIS {: RESULT=new ParseNode("this"); :}
1392 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1393 | class_instance_creation_expression:exp {: RESULT=exp; :}
1394 | field_access:exp {: RESULT=exp; :}
1395 | method_invocation:exp {: RESULT=exp; :}
1396 | array_access:exp {: RESULT=exp; :}
1397 | ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {:
1398 ParseNode pn=new ParseNode("isavailable");
1402 // | primitive_type DOT CLASS
1404 // | array_type DOT CLASS
1408 class_instance_creation_expression ::=
1409 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1410 ParseNode pn=new ParseNode("createobject");
1417 | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1418 ParseNode pn=new ParseNode("createobject");
1422 pn.addChild("global");
1425 // Objects we want to track in disjointness analysis
1426 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1427 ParseNode pn=new ParseNode("createobject");
1431 pn.addChild("disjoint").addChild(id);
1434 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
1435 ParseNode pn=new ParseNode("createobject");
1441 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
1442 ParseNode pn=new ParseNode("createobject");
1450 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1451 // | primary DOT NEW IDENTIFIER
1452 // LPAREN argument_list_opt RPAREN {:
1455 // | primary DOT NEW IDENTIFIER
1456 // LPAREN argument_list_opt RPAREN class_body
1457 // | name DOT NEW IDENTIFIER
1458 // LPAREN argument_list_opt RPAREN
1459 // | name DOT NEW IDENTIFIER
1460 // LPAREN argument_list_opt RPAREN class_body
1462 cons_argument_list_opt ::=
1463 {: RESULT=new ParseNode("empty"); :}
1464 | cons_argument_list:args {: RESULT=args; :}
1467 cons_argument_list ::=
1468 IDENTIFIER:id COLON expression:exp {:
1469 ParseNode pn=new ParseNode("cons_argument_list");
1470 ParseNode pnarg=pn.addChild("binding");
1471 pnarg.addChild("var").addChild(id);
1472 pnarg.addChild("exp").addChild(exp);
1475 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1476 ParseNode pnarg=new ParseNode("binding");
1477 pnarg.addChild("var").addChild(id);
1478 pnarg.addChild("exp").addChild(exp);
1479 list.addChild(pnarg);
1484 argument_list_opt ::=
1485 {: RESULT=new ParseNode("empty"); :}
1486 | argument_list:args {: RESULT=args; :}
1491 ParseNode pn=new ParseNode("argument_list");
1495 | argument_list:list COMMA expression:exp {:
1500 array_creation_uninit ::=
1501 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1502 ParseNode pn=new ParseNode("createarray");
1504 pn.addChild(dimexpr);
1505 pn.addChild("dims_opt").setLiteral(dims);
1508 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1509 ParseNode pn=new ParseNode("createarray");
1511 pn.addChild(dimexpr);
1512 pn.addChild("dims_opt").setLiteral(dims);
1515 | GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1516 ParseNode pn=new ParseNode("createarray");
1518 pn.addChild(dimexpr);
1519 pn.addChild("dims_opt").setLiteral(dims);
1520 pn.addChild("global");
1523 | DISJOINT IDENTIFIER:id NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1524 ParseNode pn=new ParseNode("createarray");
1526 pn.addChild(dimexpr);
1527 pn.addChild("dims_opt").setLiteral(dims);
1528 pn.addChild("disjoint").addChild(id);
1531 | GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1532 ParseNode pn=new ParseNode("createarray");
1534 pn.addChild(dimexpr);
1535 pn.addChild("dims_opt").setLiteral(dims);
1536 pn.addChild("global");
1539 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1540 ParseNode pn=new ParseNode("createarray");
1542 pn.addChild(dimexpr);
1543 pn.addChild("dims_opt").setLiteral(dims);
1544 pn.addChild("disjoint").addChild(id);
1548 //array_creation_init ::=
1549 // NEW primitive_type dims array_initializer
1550 // | NEW class_or_interface_type dims array_initializer
1552 dim_exprs ::= dim_expr:exp {:
1553 ParseNode pn=new ParseNode("dim_exprs");
1556 | dim_exprs:base dim_expr:exp {:
1561 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1563 dims_opt ::= {: RESULT=new Integer(0); :}
1564 | dims:dims {: RESULT = dims; :}
1567 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1568 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1572 primary:base DOT IDENTIFIER:id {:
1573 ParseNode pn=new ParseNode("fieldaccess");
1574 pn.addChild("base").addChild(base);
1575 pn.addChild("field").addChild(id);
1578 // | SUPER DOT IDENTIFIER
1579 // | name DOT SUPER DOT IDENTIFIER
1581 method_invocation ::=
1582 name:name LPAREN argument_list_opt:args RPAREN {:
1583 ParseNode pn=new ParseNode("methodinvoke1");
1588 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1589 ParseNode pn=new ParseNode("methodinvoke2");
1590 pn.addChild("base").addChild(base);
1591 pn.addChild("id").addChild(name);
1595 | SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {:
1596 ParseNode name=new ParseNode("name");
1597 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
1598 name.addChild("identifier").addChild(id);
1599 ParseNode pn=new ParseNode("methodinvoke1");
1604 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1607 name:name LBRACK expression:exp RBRACK {:
1608 ParseNode pn=new ParseNode("arrayaccess");
1609 pn.addChild("base").addChild(name);
1610 pn.addChild("index").addChild(exp);
1613 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1614 ParseNode pn=new ParseNode("arrayaccess");
1615 pn.addChild("base").addChild(base);
1616 pn.addChild("index").addChild(exp);
1619 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1620 // ParseNode pn=new ParseNode("arrayaccess");
1621 // pn.addChild("init").addChild(init);
1622 // pn.addChild("index").addChild(exp);
1627 postfix_expression ::=
1630 | name:exp {: RESULT=exp; :}
1631 | postincrement_expression:exp {: RESULT=exp; :}
1632 | postdecrement_expression:exp {: RESULT=exp; :}
1634 postincrement_expression ::=
1635 postfix_expression:exp PLUSPLUS
1636 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1638 postdecrement_expression ::=
1639 postfix_expression:exp MINUSMINUS
1640 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1642 unary_expression ::=
1643 preincrement_expression:exp {: RESULT=exp; :}
1644 | predecrement_expression:exp {: RESULT=exp; :}
1645 | PLUS unary_expression:exp
1646 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1647 | MINUS unary_expression:exp
1648 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1649 | unary_expression_not_plus_minus:exp {:
1652 preincrement_expression ::=
1653 PLUSPLUS unary_expression:exp
1654 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1656 predecrement_expression ::=
1657 MINUSMINUS unary_expression:exp
1658 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1660 unary_expression_not_plus_minus ::=
1661 postfix_expression:exp {:
1663 | COMP unary_expression:exp
1664 {: RESULT=(new ParseNode("comp")).addChild(exp).getRoot(); :}
1665 | NOT unary_expression:exp
1666 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1667 | cast_expression:exp {: RESULT=exp; :}
1670 LPAREN primitive_type:type
1672 RPAREN unary_expression:exp {:
1673 ParseNode pn=new ParseNode("cast1");
1674 pn.addChild("type").addChild(type);
1675 pn.addChild("exp").addChild(exp);
1678 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
1679 ParseNode pn=new ParseNode("cast2");
1680 pn.addChild("type").addChild(type);
1681 pn.addChild("exp").addChild(exp);
1685 // | LPAREN name dims RPAREN unary_expression_not_plus_minus
1687 multiplicative_expression ::=
1688 unary_expression:exp {:
1690 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
1691 ParseNode pn=new ParseNode("mult");
1696 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1697 ParseNode pn=new ParseNode("div");
1702 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1703 ParseNode pn=new ParseNode("mod");
1709 additive_expression ::=
1710 multiplicative_expression:exp {:
1712 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
1713 ParseNode pn=new ParseNode("add");
1718 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
1719 ParseNode pn=new ParseNode("sub");
1725 shift_expression ::=
1726 additive_expression:exp {:
1728 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
1729 ParseNode pn=new ParseNode("leftshift");
1734 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
1735 ParseNode pn=new ParseNode("rightshift");
1740 | shift_expression:exp1 URSHIFT additive_expression:exp2 {:
1741 ParseNode pn=new ParseNode("urightshift");
1747 relational_expression ::=
1748 shift_expression:exp {:
1750 | relational_expression:exp1 LT shift_expression:exp2 {:
1751 ParseNode pn=new ParseNode("comp_lt");
1756 | relational_expression:exp1 GT shift_expression:exp2 {:
1757 ParseNode pn=new ParseNode("comp_gt");
1762 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
1763 ParseNode pn=new ParseNode("comp_lte");
1768 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
1769 ParseNode pn=new ParseNode("comp_gte");
1774 // | relational_expression INSTANCEOF reference_type
1777 equality_expression ::=
1778 relational_expression:exp {:
1780 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
1781 ParseNode pn=new ParseNode("equal");
1786 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
1787 ParseNode pn=new ParseNode("not_equal");
1794 equality_expression:exp {:
1796 | and_expression:exp1 AND equality_expression:exp2 {:
1797 ParseNode pn=new ParseNode("bitwise_and");
1803 exclusive_or_expression ::=
1804 and_expression:expr {:
1807 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
1808 ParseNode pn=new ParseNode("bitwise_xor");
1814 inclusive_or_expression ::=
1815 exclusive_or_expression:exclor {:
1817 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
1818 ParseNode pn=new ParseNode("bitwise_or");
1824 conditional_and_expression ::=
1825 inclusive_or_expression:inclor {:
1827 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1828 ParseNode pn=new ParseNode("logical_and");
1834 conditional_or_expression ::=
1835 conditional_and_expression:condand {:
1837 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
1838 ParseNode pn=new ParseNode("logical_or");
1844 conditional_expression ::=
1845 conditional_or_expression:condor {:
1847 // | conditional_or_expression QUESTION expression
1848 // COLON conditional_expression
1850 getoffset_expression ::=
1851 GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
1852 ParseNode pn = new ParseNode("getoffset");
1854 pn.addChild("field").addChild(id);
1859 assignment_expression ::=
1860 conditional_expression:expr {:
1862 assignment:assign {:
1864 getoffset_expression:expr {:
1867 // semantic check necessary here to ensure a valid left-hand side.
1868 // allowing a parenthesized variable here on the lhs was introduced in
1869 // JLS 2; thanks to Eric Blake for pointing this out.
1870 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
1871 ParseNode pn=new ParseNode("assignment");
1872 pn.addChild("op").addChild(op);
1873 ParseNode pnargs=pn.addChild("args");
1874 pnargs.addChild(lvalue);
1875 pnargs.addChild(rvalue);
1879 assignment_operator ::=
1880 EQ {: RESULT=new ParseNode("eq"); :}
1881 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
1882 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
1883 | MODEQ {: RESULT=new ParseNode("modeq"); :}
1884 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
1885 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
1886 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
1887 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
1888 | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
1889 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
1890 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
1891 | OREQ {: RESULT=new ParseNode("oreq"); :}
1894 {: RESULT=new ParseNode("empty"); :}
1898 expression ::= assignment_expression:exp {:
1901 //constant_expression ::=