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;
269 TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN
273 ParseNode pn=new ParseNode("task_declaration");
274 pn.addChild("name").addChild(id);
277 pn.addChild("body").addChild(body);
281 task_parameter_list ::=
283 ParseNode pn=new ParseNode("task_parameter_list");
287 | task_parameter_list:fpl COMMA task_parameter:fp {:
294 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
295 ParseNode pn=new ParseNode("task_parameter");
298 pn.addChild("flag").addChild(exp);
301 | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
302 ParseNode pn=new ParseNode("task_parameter");
305 pn.addChild("flag").addChild(exp);
306 pn.addChild("tag").addChild(texp);
309 | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
310 ParseNode pn=new ParseNode("task_parameter");
313 pn.addChild("tag").addChild(texp);
316 | OPTIONAL task_parameter:fp {:
317 ParseNode pn=new ParseNode("task_parameter");
318 pn.addChild("optional").addChild(fp);
324 tag_expression_list ::= tag_expression:te {:
325 ParseNode pn=new ParseNode("tag_expression_list");
329 | tag_expression_list:tel COMMA tag_expression:te {:
335 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {:
336 ParseNode pn=new ParseNode("tag_expression");
337 pn.addChild("type").addChild(type);
338 pn.addChild("single").addChild(id);
343 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
344 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
345 | {: RESULT = new ParseNode("empty"); :}
348 tag_list ::= tag_change:fc {:
349 ParseNode pn=new ParseNode("tag_list");
353 | tag_list:fl COMMA tag_change:fc {:
358 tag_change ::= IDENTIFIER:id {:
359 RESULT=new ParseNode("name").addChild(id).getRoot();
361 | NOT IDENTIFIER:id {:
362 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
366 flag_andexpression:exp {:
369 | flag_expression:exp1 OROR flag_andexpression:exp2 {:
370 ParseNode pn=new ParseNode("or");
377 flag_andexpression ::=
378 flag_notexpression:exp {: RESULT=exp; :}
379 | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {:
380 ParseNode pn=new ParseNode("and");
387 flag_notexpression ::=
388 NOT flag_notexpression:exp {:
389 ParseNode pn=new ParseNode("not");
393 | LPAREN flag_expression:exp RPAREN {:
397 ParseNode pn=new ParseNode("name");
403 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
404 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
407 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
408 | {: RESULT = new ParseNode("empty"); :}
411 cons_checks ::= cons_check:cc {:
412 ParseNode pn=new ParseNode("cons_checks");
416 | cons_checks:ccs COMMA cons_check:cc {:
421 cons_check ::= IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {:
422 ParseNode pn=new ParseNode("cons_check");
423 pn.addChild("name").addChild("identifier").addChild(name);
428 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
429 | {: RESULT = new ParseNode("empty"); :}
432 flag_effects ::= flag_effect:fe {:
433 ParseNode pn=new ParseNode("flag_effects_list");
437 | flag_effects:fes COMMA flag_effect:fe {:
442 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {:
443 ParseNode pn=new ParseNode("flag_effect");
444 pn.addChild("name").addChild(id);
449 | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
450 ParseNode pn=new ParseNode("flag_effect");
451 pn.addChild("name").addChild(id);
456 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
457 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
459 {: RESULT = new ParseNode("empty"); :}
462 flag_list ::= flag_change:fc {:
463 ParseNode pn=new ParseNode("flag_list");
467 | flag_list:fl COMMA flag_change:fc {:
472 flag_change ::= IDENTIFIER:id {:
473 RESULT=new ParseNode("name").addChild(id).getRoot();
476 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
479 // 19.2) The Syntactic Grammar
480 goal ::= compilation_unit:cu
486 // 19.3) Lexical Structure.
489 literal ::= INTEGER_LITERAL:integer_lit
491 ParseNode pn=new ParseNode("literal");
492 pn.addChild("integer").setLiteral(integer_lit);
495 | FLOATING_POINT_LITERAL:float_lit
497 ParseNode pn=new ParseNode("literal");
498 pn.addChild("float").setLiteral(float_lit);
501 | BOOLEAN_LITERAL:boolean_lit
503 ParseNode pn=new ParseNode("literal");
504 pn.addChild("boole
\1aan").setLiteral(boolean_lit);
507 | CHARACTER_LITERAL:char_lit
509 ParseNode pn=new ParseNode("literal");
510 pn.addChild("char").setLiteral(char_lit);
513 | STRING_LITERAL:string_lit
515 ParseNode pn=new ParseNode("literal");
516 pn.addChild("string").setLiteral(string_lit);
521 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
525 // 19.4) Types, Values, and Variables
526 type ::= primitive_type:type {: RESULT=type; :}
527 | reference_type:type {: RESULT=type; :}
531 numeric_type:type {: RESULT=type; :}
532 | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
534 numeric_type::= integral_type:type {: RESULT=type; :}
535 | floating_point_type:type {: RESULT=type; :}
538 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
539 | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
540 | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
541 | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
542 | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
544 floating_point_type ::=
545 FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
546 | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
550 class_or_interface_type:type {: RESULT=type; :}
551 | array_type:type {: RESULT=type; :}
553 class_or_interface_type ::= name:name {:
554 RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot();
557 class_type ::= class_or_interface_type:type {: RESULT=type; :};
558 //interface_type ::= class_or_interface_type;
560 array_type ::= primitive_type:prim dims:dims {:
561 ParseNode pn=(new ParseNode("type")).addChild("array");
562 pn.addChild("basetype").addChild(prim);
563 pn.addChild("dims").setLiteral(dims);
566 | name:name dims:dims {:
567 ParseNode pn=(new ParseNode("type")).addChild("array");
568 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
569 pn.addChild("dims").setLiteral(dims);
575 name ::= simple_name:name {: RESULT=name; :}
576 | qualified_name:name {: RESULT=name; :}
578 simple_name ::= IDENTIFIER:id {:
579 RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot();
582 qualified_name ::= name:name DOT IDENTIFIER:id {:
583 ParseNode pn=new ParseNode("name");
584 pn.addChild("base").addChild(name);
585 pn.addChild("identifier").addChild(id);
592 package_declaration_opt:pdo
593 import_declarations_opt:ido
594 type_declarations_opt:tdo {:
595 ParseNode pn=new ParseNode("compilation_unit");
597 pn.addChild("packages").addChild(pdo);
598 pn.addChild("imports").addChild(ido);
602 package_declaration_opt ::= package_declaration:pdo {:
605 {: RESULT=new ParseNode("empty"); :}
608 import_declarations_opt ::= import_declarations:ido {:
611 {: RESULT=new ParseNode("empty"); :}
613 type_declarations_opt ::= type_declarations:tds {:
616 {: RESULT=new ParseNode("empty"); :}
619 import_declarations ::=
620 import_declaration:id {:
621 ParseNode pn=new ParseNode("import_decls_list");
625 | import_declarations:ids import_declaration:id {:
631 type_declarations ::=
632 type_declaration:td {:
633 ParseNode pn=new ParseNode("type_declaration_list");
637 | type_declarations:tds type_declaration:td {:
643 package_declaration ::=
644 PACKAGE name:name SEMICOLON {:
645 ParseNode pn=new ParseNode("package");
650 import_declaration ::=
651 single_type_import_declaration:sid {: RESULT=sid; :}
652 | type_import_on_demand_declaration:iod {: RESULT=iod; :}
654 single_type_import_declaration ::=
655 IMPORT name:name SEMICOLON {:
656 ParseNode pn=new ParseNode("import_single");
661 type_import_on_demand_declaration ::=
662 IMPORT name:name DOT MULT SEMICOLON {:
663 ParseNode pn=new ParseNode("import_ondemand");
674 | task_declaration:td
678 // | interface_declaration
679 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
682 // 19.7) Productions used only in the LALR(1) grammar
684 {: RESULT=new ParseNode("empty"); :}
689 modifiers ::= modifier:mo {:
690 ParseNode pn=new ParseNode("modifier_list");
694 | modifiers:mos modifier:mo {:
700 PUBLIC {: RESULT=new ParseNode("public"); :}|
701 PROTECTED {: RESULT=new ParseNode("protected"); :}|
702 PRIVATE {: RESULT=new ParseNode("private"); :}|
703 STATIC {: RESULT=new ParseNode("static"); :} |
705 FINAL {: RESULT=new ParseNode("final"); :}|
706 NATIVE {: RESULT=new ParseNode("native"); :} |
707 SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
708 ATOMIC {: RESULT=new ParseNode("atomic"); :}
711 // STRICTFP // note that semantic analysis must check that the
712 // context of the modifier allows strictfp.
717 // 19.8.1) Class Declaration:
718 class_declaration ::=
719 modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so //interfaces_opt
722 ParseNode pn=new ParseNode("class_declaration");
723 pn.addChild("modifiers").addChild(mo);
724 pn.addChild("name").addChild(id);
725 pn.addChild("super").addChild(so);
726 pn.addChild("classbody").addChild(body);
730 super ::= EXTENDS class_type:classtype {:
735 {: RESULT=new ParseNode("empty"); :}
741 //interfaces ::= IMPLEMENTS interface_type_list
746 //interface_type_list ::=
748 // | interface_type_list COMMA interface_type
751 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
754 class_body_declarations_opt ::=
755 {: RESULT=new ParseNode("empty"); :}
756 | class_body_declarations:cbd {: RESULT=cbd; :};
758 class_body_declarations ::=
759 class_body_declaration:cbd {:
760 ParseNode pn=new ParseNode("class_body_declaration_list");
764 | class_body_declarations:cbds class_body_declaration:cbd {:
770 class_body_declaration ::=
771 class_member_declaration:member {:
772 RESULT=(new ParseNode("member")).addChild(member).getRoot();
774 // | static_initializer
775 | constructor_declaration:constructor {:
776 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
779 RESULT=(new ParseNode("block")).addChild(block).getRoot();
782 class_member_declaration ::=
783 //failure aware computation
784 flag_declaration:flag {:
785 RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
788 field_declaration:field {:
789 RESULT=(new ParseNode("field")).addChild(field).getRoot();
791 | method_declaration:method {:
792 RESULT=(new ParseNode("method")).addChild(method).getRoot();
794 /* repeat the prod for 'class_declaration' here: */
795 // | modifiers_opt CLASS IDENTIFIER super_opt class_body
796 // | interface_declaration
797 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
800 //Failure aware computation
802 FLAG IDENTIFIER:id SEMICOLON {:
803 ParseNode pn=new ParseNode("flag_declaration");
804 pn.addChild("name").addChild(id);
807 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {:
808 ParseNode pn=new ParseNode("flag_declaration");
809 pn.addChild("name").addChild(id);
810 pn.addChild("external");
815 // 19.8.2) Field Declarations
816 field_declaration ::=
817 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {:
818 ParseNode pn=new ParseNode("field_declaration");
819 pn.addChild("modifier").addChild(mo);
820 pn.addChild("type").addChild(type);
821 pn.addChild("variables").addChild(var);
824 modifiers_opt:mo GLOBAL 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);
829 pn.addChild("global");
834 variable_declarators ::=
835 variable_declarator:vd {:
836 ParseNode pn=new ParseNode("variable_declarators_list");
840 | variable_declarators:vds COMMA variable_declarator:vd {:
845 variable_declarator ::=
846 variable_declarator_id:id {:
847 ParseNode pn=new ParseNode("variable_declarator");
851 | variable_declarator_id:id EQ variable_initializer:init {:
852 ParseNode pn=new ParseNode("variable_declarator");
854 pn.addChild("initializer").addChild(init);
858 variable_declarator_id ::=
860 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
861 | variable_declarator_id:id LBRACK RBRACK {:
862 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
864 variable_initializer ::=
865 expression:exp {: RESULT=exp; :}
866 // | array_initializer
869 // 19.8.3) Method Declarations
870 method_declaration ::=
871 method_header:header method_body:body {:
872 ParseNode pn=new ParseNode("method_declaration");
874 pn.addChild("body").addChild(body);
879 modifiers_opt:mo type:type method_declarator:decl //throws_opt
881 ParseNode pn=new ParseNode("method_header");
882 pn.addChild("modifiers").addChild(mo);
883 pn.addChild("returntype").addChild(type);
887 | modifiers_opt:mo VOID method_declarator:decl //throws_opt
889 ParseNode pn=new ParseNode("method_header");
890 pn.addChild("modifiers").addChild(mo);
895 method_declarator ::=
896 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {:
897 ParseNode pn=new ParseNode("method_declarator");
898 pn.addChild("name").addChild(id);
899 pn.addChild("parameters").addChild(params);
902 // | method_declarator LBRACK RBRACK // deprecated
903 // be careful; the above production also allows 'void foo() []'
905 formal_parameter_list_opt ::=
906 {: RESULT=new ParseNode("empty"); :}
907 | formal_parameter_list:fpl {:
911 formal_parameter_list ::=
912 formal_parameter:fp {:
913 ParseNode pn=new ParseNode("formal_parameter_list");
917 | formal_parameter_list:fpl COMMA formal_parameter:fp {:
923 type:type variable_declarator_id:name {:
924 ParseNode pn=new ParseNode("formal_parameter");
930 TAG variable_declarator_id:name {:
931 ParseNode pn=new ParseNode("tag_parameter");
935 // | FINAL type variable_declarator_id
940 //throws ::= THROWS class_type_list
942 //class_type_list ::=
944 // | class_type_list COMMA class_type
946 method_body ::= block:block {:
949 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
952 // 19.8.4) Static Initializers
953 //static_initializer ::=
957 // 19.8.5) Constructor Declarations
958 constructor_declaration ::=
959 modifiers_opt:mo constructor_declarator:cd
961 constructor_body:body {:
962 ParseNode pn=new ParseNode("constructor_declaration");
963 pn.addChild("modifiers").addChild(mo);
965 pn.addChild("body").addChild(body);
968 modifiers_opt:mo GLOBAL constructor_declarator:cd
970 constructor_body:body {:
971 ParseNode pn=new ParseNode("constructor_declaration");
972 pn.addChild("global");
973 pn.addChild("modifiers").addChild(mo);
975 pn.addChild("body").addChild(body);
979 constructor_declarator ::=
980 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {:
981 ParseNode pn=new ParseNode("constructor_declarator");
983 pn.addChild("parameters").addChild(fplo);
988 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {:
989 ParseNode pn=new ParseNode("constructor_body");
994 LBRACE explicit_constructor_invocation:eci RBRACE {:
995 ParseNode pn=new ParseNode("constructor_body");
999 LBRACE block_statements:block RBRACE {:
1000 ParseNode pn=new ParseNode("constructor_body");
1004 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1006 explicit_constructor_invocation ::=
1007 // THIS LPAREN argument_list_opt RPAREN SEMICOLON
1009 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1010 ParseNode pn=new ParseNode("superinvoke");
1014 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1015 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1020 // 19.9.1) Interface Declarations
1021 //interface_declaration ::=
1022 // modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
1025 //extends_interfaces_opt ::=
1026 // | extends_interfaces
1028 //extends_interfaces ::=
1029 // EXTENDS interface_type
1030 // | extends_interfaces COMMA interface_type
1032 //interface_body ::=
1033 // LBRACE interface_member_declarations_opt RBRACE
1035 //interface_member_declarations_opt ::=
1036 // | interface_member_declarations
1038 //interface_member_declarations ::=
1039 // interface_member_declaration
1040 // | interface_member_declarations interface_member_declaration
1042 //interface_member_declaration ::=
1043 // constant_declaration
1044 // | abstract_method_declaration
1045 // | class_declaration
1046 // | interface_declaration
1049 //constant_declaration ::=
1050 // field_declaration
1051 // // need to semantically check that modifiers of field declaration
1052 // // include only PUBLIC, STATIC, or FINAL. Other modifiers are
1055 //abstract_method_declaration ::=
1056 // method_header SEMICOLON
1061 //array_initializer ::=
1062 // LBRACE variable_initializers COMMA RBRACE
1063 // | LBRACE variable_initializers RBRACE
1064 // | LBRACE COMMA RBRACE
1067 //variable_initializers ::=
1068 // variable_initializer
1069 // | variable_initializers COMMA variable_initializer
1072 // 19.11) Blocks and Statements
1073 block ::= LBRACE block_statements_opt:bso RBRACE {:
1077 block_statements_opt ::=
1078 {: RESULT=new ParseNode("empty"); :}
1079 | block_statements:bs {:
1083 block_statements ::=
1084 block_statement:bs {:
1085 ParseNode pn=new ParseNode("block_statement_list");
1089 | block_statements:bss block_statement:bs {:
1095 tag_variable_declaration_statement:tvds {:
1098 | local_variable_declaration_statement:lvds {:
1101 | statement:statement {:
1104 // | class_declaration
1105 // | interface_declaration
1107 tag_variable_declaration_statement ::=
1108 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
1109 ParseNode pn=new ParseNode("tag_declaration");
1110 pn.addChild("single").addChild(id);
1111 pn.addChild("type").addChild(type);
1115 local_variable_declaration_statement ::=
1116 local_variable_declaration:lvd SEMICOLON {:
1120 local_variable_declaration ::=
1121 type:type variable_declarators:var {:
1122 ParseNode pn=new ParseNode("local_variable_declaration");
1127 // | FINAL type variable_declarators
1129 statement ::= statement_without_trailing_substatement:st {:
1132 // | labeled_statement:st {: RESULT=st; :}
1133 | if_then_statement:st {: RESULT=st; :}
1134 | if_then_else_statement:st {: RESULT=st; :}
1135 | while_statement:st {: RESULT=st; :}
1136 | for_statement:st {: RESULT=st; :}
1138 statement_no_short_if ::=
1139 statement_without_trailing_substatement:st {: RESULT=st; :}
1140 // | labeled_statement_no_short_if:st {: RESULT=st; :}
1141 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
1142 | while_statement_no_short_if:st {: RESULT=st; :}
1143 | for_statement_no_short_if:st {: RESULT=st; :}
1145 statement_without_trailing_substatement ::=
1146 block:st {: RESULT=st; :}
1147 | empty_statement:st {: RESULT=st; :}
1148 | expression_statement:st {: RESULT=st; :}
1149 // | switch_statement
1150 | do_statement:dos {:RESULT=dos; :}
1151 | break_statement:st {: RESULT=st; :}
1152 | continue_statement:st {: RESULT=st; :}
1153 | return_statement:st {: RESULT=st; :}
1154 | task_exitstatement:st {: RESULT=st; :}
1155 | atomic_statement:st {: RESULT=st; :}
1156 // | synchronized_statement
1157 // | throw_statement
1159 // | assert_statement
1162 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1164 //labeled_statement ::=
1165 // IDENTIFIER COLON statement
1167 //labeled_statement_no_short_if ::=
1168 // IDENTIFIER COLON statement_no_short_if
1170 expression_statement ::=
1171 statement_expression:se SEMICOLON {:
1172 ParseNode pn=new ParseNode("expression");
1176 statement_expression ::=
1177 assignment:st {: RESULT=st; :}
1178 | preincrement_expression:st {: RESULT=st; :}
1179 | predecrement_expression:st {: RESULT=st; :}
1180 | postincrement_expression:st {: RESULT=st; :}
1181 | postdecrement_expression:st {: RESULT=st; :}
1182 | method_invocation:st {: RESULT=st; :}
1183 | class_instance_creation_expression:st {: RESULT=st; :}
1185 if_then_statement ::=
1186 IF LPAREN expression:exp RPAREN statement:st {:
1187 ParseNode pn=new ParseNode("ifstatement");
1188 pn.addChild("condition").addChild(exp);
1189 pn.addChild("statement").addChild(st);
1193 if_then_else_statement ::=
1194 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1195 ELSE statement:else_st {:
1196 ParseNode pn=new ParseNode("ifstatement");
1197 pn.addChild("condition").addChild(exp);
1198 pn.addChild("statement").addChild(st);
1199 pn.addChild("else_statement").addChild(else_st);
1203 if_then_else_statement_no_short_if ::=
1204 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1205 ELSE statement_no_short_if:else_st {:
1206 ParseNode pn=new ParseNode("ifstatement");
1207 pn.addChild("condition").addChild(exp);
1208 pn.addChild("statement").addChild(st);
1209 pn.addChild("else_statement").addChild(else_st);
1213 //switch_statement ::=
1214 // SWITCH LPAREN expression RPAREN switch_block
1217 // LBRACE switch_block_statement_groups switch_labels RBRACE
1218 // | LBRACE switch_block_statement_groups RBRACE
1219 // | LBRACE switch_labels RBRACE
1222 //switch_block_statement_groups ::=
1223 // switch_block_statement_group
1224 // | switch_block_statement_groups switch_block_statement_group
1226 //switch_block_statement_group ::=
1227 // switch_labels block_statements
1231 // | switch_labels switch_label
1234 // CASE constant_expression COLON
1239 WHILE LPAREN expression:exp RPAREN statement:st {:
1240 ParseNode pn=new ParseNode("whilestatement");
1241 pn.addChild("condition").addChild(exp);
1242 pn.addChild("statement").addChild(st);
1246 while_statement_no_short_if ::=
1247 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1248 ParseNode pn=new ParseNode("whilestatement");
1249 pn.addChild("condition").addChild(exp);
1250 pn.addChild("statement").addChild(st);
1255 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1256 ParseNode pn=new ParseNode("dowhilestatement");
1257 pn.addChild("condition").addChild(exp);
1258 pn.addChild("statement").addChild(st);
1263 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1264 for_update_opt:update RPAREN statement:st {:
1265 ParseNode pn=new ParseNode("forstatement");
1266 pn.addChild("initializer").addChild(init);
1267 pn.addChild("condition").addChild(exp);
1268 pn.addChild("update").addChild(update);
1269 pn.addChild("statement").addChild(st);
1273 for_statement_no_short_if ::=
1274 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1275 for_update_opt:update RPAREN statement_no_short_if:st {:
1276 ParseNode pn=new ParseNode("forstatement");
1277 pn.addChild("initializer").addChild(init);
1278 pn.addChild("condition").addChild(exp);
1279 pn.addChild("update").addChild(update);
1280 pn.addChild("statement").addChild(st);
1285 {: RESULT=new ParseNode("empty"); :}
1286 | for_init:init {: RESULT=init; :}
1288 for_init ::= statement_expression_list:list {: RESULT=list; :}
1289 | local_variable_declaration:decl {: RESULT=decl; :}
1292 {: RESULT=new ParseNode("empty"); :}
1293 | for_update:update {: RESULT=update; :}
1295 for_update ::= statement_expression_list:list {: RESULT=list; :}
1297 statement_expression_list ::=
1298 statement_expression:expr {:
1299 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1301 | statement_expression_list:list COMMA statement_expression:expr {:
1302 list.addChild(expr);
1307 //identifier_opt ::=
1314 SEMICOLON {: RESULT=new ParseNode("break"); :}
1317 continue_statement ::=
1321 {: RESULT=new ParseNode("continue"); :}
1323 return_statement ::=
1324 RETURN expression_opt:exp SEMICOLON {:
1325 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1327 //throw_statement ::=
1328 // THROW expression SEMICOLON
1330 //synchronized_statement ::=
1331 // SYNCHRONIZED LPAREN expression RPAREN block
1333 atomic_statement ::=
1335 RESULT=(new ParseNode("atomic")).addChild(blk).getRoot();
1339 // TRY block catches
1340 // | TRY block catches_opt finally
1345 //catches ::= catch_clause
1346 // | catches catch_clause
1349 // CATCH LPAREN formal_parameter RPAREN block
1351 //finally ::= FINALLY block
1353 //assert_statement ::=
1354 // ASSERT expression SEMICOLON
1355 // | ASSERT expression COLON expression SEMICOLON
1358 // 19.12) Expressions
1359 primary ::= primary_no_new_array:st {:
1361 // | array_creation_init:st {:
1364 | array_creation_uninit:st {:
1368 primary_no_new_array ::=
1369 literal:lit {: RESULT=lit; :}
1370 | THIS {: RESULT=new ParseNode("this"); :}
1371 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1372 | class_instance_creation_expression:exp {: RESULT=exp; :}
1373 | field_access:exp {: RESULT=exp; :}
1374 | method_invocation:exp {: RESULT=exp; :}
1375 | array_access:exp {: RESULT=exp; :}
1376 | ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {:
1377 ParseNode pn=new ParseNode("isavailable");
1381 // | primitive_type DOT CLASS
1383 // | array_type DOT CLASS
1387 class_instance_creation_expression ::=
1388 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1389 ParseNode pn=new ParseNode("createobject");
1396 | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1397 ParseNode pn=new ParseNode("createobject");
1401 pn.addChild("global");
1404 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
1405 ParseNode pn=new ParseNode("createobject");
1411 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
1412 ParseNode pn=new ParseNode("createobject");
1420 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1421 // | primary DOT NEW IDENTIFIER
1422 // LPAREN argument_list_opt RPAREN {:
1425 // | primary DOT NEW IDENTIFIER
1426 // LPAREN argument_list_opt RPAREN class_body
1427 // | name DOT NEW IDENTIFIER
1428 // LPAREN argument_list_opt RPAREN
1429 // | name DOT NEW IDENTIFIER
1430 // LPAREN argument_list_opt RPAREN class_body
1432 cons_argument_list_opt ::=
1433 {: RESULT=new ParseNode("empty"); :}
1434 | cons_argument_list:args {: RESULT=args; :}
1437 cons_argument_list ::=
1438 IDENTIFIER:id COLON expression:exp {:
1439 ParseNode pn=new ParseNode("cons_argument_list");
1440 ParseNode pnarg=pn.addChild("binding");
1441 pnarg.addChild("var").addChild(id);
1442 pnarg.addChild("exp").addChild(exp);
1445 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1446 ParseNode pnarg=new ParseNode("binding");
1447 pnarg.addChild("var").addChild(id);
1448 pnarg.addChild("exp").addChild(exp);
1449 list.addChild(pnarg);
1454 argument_list_opt ::=
1455 {: RESULT=new ParseNode("empty"); :}
1456 | argument_list:args {: RESULT=args; :}
1461 ParseNode pn=new ParseNode("argument_list");
1465 | argument_list:list COMMA expression:exp {:
1470 array_creation_uninit ::=
1471 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1472 ParseNode pn=new ParseNode("createarray");
1474 pn.addChild(dimexpr);
1475 pn.addChild("dims_opt").setLiteral(dims);
1478 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1479 ParseNode pn=new ParseNode("createarray");
1481 pn.addChild(dimexpr);
1482 pn.addChild("dims_opt").setLiteral(dims);
1485 | GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1486 ParseNode pn=new ParseNode("createarray");
1488 pn.addChild(dimexpr);
1489 pn.addChild("dims_opt").setLiteral(dims);
1490 pn.addChild("global");
1493 | GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1494 ParseNode pn=new ParseNode("createarray");
1496 pn.addChild(dimexpr);
1497 pn.addChild("dims_opt").setLiteral(dims);
1498 pn.addChild("global");
1502 //array_creation_init ::=
1503 // NEW primitive_type dims array_initializer
1504 // | NEW class_or_interface_type dims array_initializer
1506 dim_exprs ::= dim_expr:exp {:
1507 ParseNode pn=new ParseNode("dim_exprs");
1510 | dim_exprs:base dim_expr:exp {:
1515 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1517 dims_opt ::= {: RESULT=new Integer(0); :}
1518 | dims:dims {: RESULT = dims; :}
1521 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1522 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1526 primary:base DOT IDENTIFIER:id {:
1527 ParseNode pn=new ParseNode("fieldaccess");
1528 pn.addChild("base").addChild(base);
1529 pn.addChild("field").addChild(id);
1532 // | SUPER DOT IDENTIFIER
1533 // | name DOT SUPER DOT IDENTIFIER
1535 method_invocation ::=
1536 name:name LPAREN argument_list_opt:args RPAREN {:
1537 ParseNode pn=new ParseNode("methodinvoke1");
1542 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1543 ParseNode pn=new ParseNode("methodinvoke2");
1544 pn.addChild("base").addChild(base);
1545 pn.addChild("id").addChild(name);
1549 | SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {:
1550 ParseNode name=new ParseNode("name");
1551 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
1552 name.addChild("identifier").addChild(id);
1553 ParseNode pn=new ParseNode("methodinvoke1");
1558 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1561 name:name LBRACK expression:exp RBRACK {:
1562 ParseNode pn=new ParseNode("arrayaccess");
1563 pn.addChild("base").addChild(name);
1564 pn.addChild("index").addChild(exp);
1567 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1568 ParseNode pn=new ParseNode("arrayaccess");
1569 pn.addChild("base").addChild(base);
1570 pn.addChild("index").addChild(exp);
1573 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1574 // ParseNode pn=new ParseNode("arrayaccess");
1575 // pn.addChild("init").addChild(init);
1576 // pn.addChild("index").addChild(exp);
1581 postfix_expression ::=
1584 | name:exp {: RESULT=exp; :}
1585 | postincrement_expression:exp {: RESULT=exp; :}
1586 | postdecrement_expression:exp {: RESULT=exp; :}
1588 postincrement_expression ::=
1589 postfix_expression:exp PLUSPLUS
1590 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1592 postdecrement_expression ::=
1593 postfix_expression:exp MINUSMINUS
1594 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1596 unary_expression ::=
1597 preincrement_expression:exp {: RESULT=exp; :}
1598 | predecrement_expression:exp {: RESULT=exp; :}
1599 | PLUS unary_expression:exp
1600 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1601 | MINUS unary_expression:exp
1602 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1603 | unary_expression_not_plus_minus:exp {:
1606 preincrement_expression ::=
1607 PLUSPLUS unary_expression:exp
1608 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1610 predecrement_expression ::=
1611 MINUSMINUS unary_expression:exp
1612 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1614 unary_expression_not_plus_minus ::=
1615 postfix_expression:exp {:
1617 | COMP unary_expression:exp
1618 {: RESULT=(new ParseNode("comp")).addChild(exp).getRoot(); :}
1619 | NOT unary_expression:exp
1620 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1621 | cast_expression:exp {: RESULT=exp; :}
1624 LPAREN primitive_type:type
1626 RPAREN unary_expression:exp {:
1627 ParseNode pn=new ParseNode("cast1");
1628 pn.addChild("type").addChild(type);
1629 pn.addChild("exp").addChild(exp);
1632 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
1633 ParseNode pn=new ParseNode("cast2");
1634 pn.addChild("type").addChild(type);
1635 pn.addChild("exp").addChild(exp);
1639 // | LPAREN name dims RPAREN unary_expression_not_plus_minus
1641 multiplicative_expression ::=
1642 unary_expression:exp {:
1644 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
1645 ParseNode pn=new ParseNode("mult");
1650 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1651 ParseNode pn=new ParseNode("div");
1656 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1657 ParseNode pn=new ParseNode("mod");
1663 additive_expression ::=
1664 multiplicative_expression:exp {:
1666 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
1667 ParseNode pn=new ParseNode("add");
1672 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
1673 ParseNode pn=new ParseNode("sub");
1679 shift_expression ::=
1680 additive_expression:exp {:
1682 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
1683 ParseNode pn=new ParseNode("leftshift");
1688 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
1689 ParseNode pn=new ParseNode("rightshift");
1694 | shift_expression:exp1 URSHIFT additive_expression:exp2 {:
1695 ParseNode pn=new ParseNode("urightshift");
1701 relational_expression ::=
1702 shift_expression:exp {:
1704 | relational_expression:exp1 LT shift_expression:exp2 {:
1705 ParseNode pn=new ParseNode("comp_lt");
1710 | relational_expression:exp1 GT shift_expression:exp2 {:
1711 ParseNode pn=new ParseNode("comp_gt");
1716 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
1717 ParseNode pn=new ParseNode("comp_lte");
1722 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
1723 ParseNode pn=new ParseNode("comp_gte");
1728 // | relational_expression INSTANCEOF reference_type
1731 equality_expression ::=
1732 relational_expression:exp {:
1734 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
1735 ParseNode pn=new ParseNode("equal");
1740 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
1741 ParseNode pn=new ParseNode("not_equal");
1748 equality_expression:exp {:
1750 | and_expression:exp1 AND equality_expression:exp2 {:
1751 ParseNode pn=new ParseNode("bitwise_and");
1757 exclusive_or_expression ::=
1758 and_expression:expr {:
1761 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
1762 ParseNode pn=new ParseNode("bitwise_xor");
1768 inclusive_or_expression ::=
1769 exclusive_or_expression:exclor {:
1771 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
1772 ParseNode pn=new ParseNode("bitwise_or");
1778 conditional_and_expression ::=
1779 inclusive_or_expression:inclor {:
1781 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1782 ParseNode pn=new ParseNode("logical_and");
1788 conditional_or_expression ::=
1789 conditional_and_expression:condand {:
1791 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
1792 ParseNode pn=new ParseNode("logical_or");
1798 conditional_expression ::=
1799 conditional_or_expression:condor {:
1801 // | conditional_or_expression QUESTION expression
1802 // COLON conditional_expression
1804 getoffset_expression ::=
1805 GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
1806 ParseNode pn = new ParseNode("getoffset");
1808 pn.addChild("field").addChild(id);
1813 assignment_expression ::=
1814 conditional_expression:expr {:
1816 assignment:assign {:
1818 getoffset_expression:expr {:
1821 // semantic check necessary here to ensure a valid left-hand side.
1822 // allowing a parenthesized variable here on the lhs was introduced in
1823 // JLS 2; thanks to Eric Blake for pointing this out.
1824 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
1825 ParseNode pn=new ParseNode("assignment");
1826 pn.addChild("op").addChild(op);
1827 ParseNode pnargs=pn.addChild("args");
1828 pnargs.addChild(lvalue);
1829 pnargs.addChild(rvalue);
1833 assignment_operator ::=
1834 EQ {: RESULT=new ParseNode("eq"); :}
1835 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
1836 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
1837 | MODEQ {: RESULT=new ParseNode("modeq"); :}
1838 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
1839 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
1840 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
1841 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
1842 | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
1843 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
1844 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
1845 | OREQ {: RESULT=new ParseNode("oreq"); :}
1848 {: RESULT=new ParseNode("empty"); :}
1852 expression ::= assignment_expression:exp {:
1855 //constant_expression ::=