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
259 non terminal ParseNode atomic_statement;
267 TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN
271 ParseNode pn=new ParseNode("task_declaration");
272 pn.addChild("name").addChild(id);
275 pn.addChild("body").addChild(body);
279 task_parameter_list ::=
281 ParseNode pn=new ParseNode("task_parameter_list");
285 | task_parameter_list:fpl COMMA task_parameter:fp {:
292 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
293 ParseNode pn=new ParseNode("task_parameter");
296 pn.addChild("flag").addChild(exp);
299 | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
300 ParseNode pn=new ParseNode("task_parameter");
303 pn.addChild("flag").addChild(exp);
304 pn.addChild("tag").addChild(texp);
307 | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
308 ParseNode pn=new ParseNode("task_parameter");
311 pn.addChild("tag").addChild(texp);
314 | OPTIONAL task_parameter:fp {:
315 ParseNode pn=new ParseNode("task_parameter");
316 pn.addChild("optional").addChild(fp);
322 tag_expression_list ::= tag_expression:te {:
323 ParseNode pn=new ParseNode("tag_expression_list");
327 | tag_expression_list:tel COMMA tag_expression:te {:
333 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {:
334 ParseNode pn=new ParseNode("tag_expression");
335 pn.addChild("type").addChild(type);
336 pn.addChild("single").addChild(id);
341 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
342 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
343 | {: RESULT = new ParseNode("empty"); :}
346 tag_list ::= tag_change:fc {:
347 ParseNode pn=new ParseNode("tag_list");
351 | tag_list:fl COMMA tag_change:fc {:
356 tag_change ::= IDENTIFIER:id {:
357 RESULT=new ParseNode("name").addChild(id).getRoot();
359 | NOT IDENTIFIER:id {:
360 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
364 flag_andexpression:exp {:
367 | flag_expression:exp1 OROR flag_andexpression:exp2 {:
368 ParseNode pn=new ParseNode("or");
375 flag_andexpression ::=
376 flag_notexpression:exp {: RESULT=exp; :}
377 | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {:
378 ParseNode pn=new ParseNode("and");
385 flag_notexpression ::=
386 NOT flag_notexpression:exp {:
387 ParseNode pn=new ParseNode("not");
391 | LPAREN flag_expression:exp RPAREN {:
395 ParseNode pn=new ParseNode("name");
401 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
402 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
405 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
406 | {: RESULT = new ParseNode("empty"); :}
409 cons_checks ::= cons_check:cc {:
410 ParseNode pn=new ParseNode("cons_checks");
414 | cons_checks:ccs COMMA cons_check:cc {:
419 cons_check ::= IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {:
420 ParseNode pn=new ParseNode("cons_check");
421 pn.addChild("name").addChild("identifier").addChild(name);
426 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
427 | {: RESULT = new ParseNode("empty"); :}
430 flag_effects ::= flag_effect:fe {:
431 ParseNode pn=new ParseNode("flag_effects_list");
435 | flag_effects:fes COMMA flag_effect:fe {:
440 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {:
441 ParseNode pn=new ParseNode("flag_effect");
442 pn.addChild("name").addChild(id);
447 | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
448 ParseNode pn=new ParseNode("flag_effect");
449 pn.addChild("name").addChild(id);
454 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
455 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
457 {: RESULT = new ParseNode("empty"); :}
460 flag_list ::= flag_change:fc {:
461 ParseNode pn=new ParseNode("flag_list");
465 | flag_list:fl COMMA flag_change:fc {:
470 flag_change ::= IDENTIFIER:id {:
471 RESULT=new ParseNode("name").addChild(id).getRoot();
474 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
477 // 19.2) The Syntactic Grammar
478 goal ::= compilation_unit:cu
484 // 19.3) Lexical Structure.
487 literal ::= INTEGER_LITERAL:integer_lit
489 ParseNode pn=new ParseNode("literal");
490 pn.addChild("integer").setLiteral(integer_lit);
493 | FLOATING_POINT_LITERAL:float_lit
495 ParseNode pn=new ParseNode("literal");
496 pn.addChild("float").setLiteral(float_lit);
499 | BOOLEAN_LITERAL:boolean_lit
501 ParseNode pn=new ParseNode("literal");
502 pn.addChild("boolean").setLiteral(boolean_lit);
505 | CHARACTER_LITERAL:char_lit
507 ParseNode pn=new ParseNode("literal");
508 pn.addChild("char").setLiteral(char_lit);
511 | STRING_LITERAL:string_lit
513 ParseNode pn=new ParseNode("literal");
514 pn.addChild("string").setLiteral(string_lit);
519 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
523 // 19.4) Types, Values, and Variables
524 type ::= primitive_type:type {: RESULT=type; :}
525 | reference_type:type {: RESULT=type; :}
529 numeric_type:type {: RESULT=type; :}
530 | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
532 numeric_type::= integral_type:type {: RESULT=type; :}
533 | floating_point_type:type {: RESULT=type; :}
536 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
537 | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
538 | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
539 | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
540 | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
542 floating_point_type ::=
543 FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
544 | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
548 class_or_interface_type:type {: RESULT=type; :}
549 | array_type:type {: RESULT=type; :}
551 class_or_interface_type ::= name:name {:
552 RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot();
555 class_type ::= class_or_interface_type:type {: RESULT=type; :};
556 //interface_type ::= class_or_interface_type;
558 array_type ::= primitive_type:prim dims:dims {:
559 ParseNode pn=(new ParseNode("type")).addChild("array");
560 pn.addChild("basetype").addChild(prim);
561 pn.addChild("dims").setLiteral(dims);
564 | name:name dims:dims {:
565 ParseNode pn=(new ParseNode("type")).addChild("array");
566 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
567 pn.addChild("dims").setLiteral(dims);
573 name ::= simple_name:name {: RESULT=name; :}
574 | qualified_name:name {: RESULT=name; :}
576 simple_name ::= IDENTIFIER:id {:
577 RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot();
580 qualified_name ::= name:name DOT IDENTIFIER:id {:
581 ParseNode pn=new ParseNode("name");
582 pn.addChild("base").addChild(name);
583 pn.addChild("identifier").addChild(id);
590 package_declaration_opt:pdo
591 import_declarations_opt:ido
592 type_declarations_opt:tdo {:
593 ParseNode pn=new ParseNode("compilation_unit");
595 pn.addChild("packages").addChild(pdo);
596 pn.addChild("imports").addChild(ido);
600 package_declaration_opt ::= package_declaration:pdo {:
603 {: RESULT=new ParseNode("empty"); :}
606 import_declarations_opt ::= import_declarations:ido {:
609 {: RESULT=new ParseNode("empty"); :}
611 type_declarations_opt ::= type_declarations:tds {:
614 {: RESULT=new ParseNode("empty"); :}
617 import_declarations ::=
618 import_declaration:id {:
619 ParseNode pn=new ParseNode("import_decls_list");
623 | import_declarations:ids import_declaration:id {:
629 type_declarations ::=
630 type_declaration:td {:
631 ParseNode pn=new ParseNode("type_declaration_list");
635 | type_declarations:tds type_declaration:td {:
641 package_declaration ::=
642 PACKAGE name:name SEMICOLON {:
643 ParseNode pn=new ParseNode("package");
648 import_declaration ::=
649 single_type_import_declaration:sid {: RESULT=sid; :}
650 | type_import_on_demand_declaration:iod {: RESULT=iod; :}
652 single_type_import_declaration ::=
653 IMPORT name:name SEMICOLON {:
654 ParseNode pn=new ParseNode("import_single");
659 type_import_on_demand_declaration ::=
660 IMPORT name:name DOT MULT SEMICOLON {:
661 ParseNode pn=new ParseNode("import_ondemand");
672 | task_declaration:td
676 // | interface_declaration
677 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
680 // 19.7) Productions used only in the LALR(1) grammar
682 {: RESULT=new ParseNode("empty"); :}
687 modifiers ::= modifier:mo {:
688 ParseNode pn=new ParseNode("modifier_list");
692 | modifiers:mos modifier:mo {:
698 PUBLIC {: RESULT=new ParseNode("public"); :}|
699 PROTECTED {: RESULT=new ParseNode("protected"); :}|
700 PRIVATE {: RESULT=new ParseNode("private"); :}|
701 STATIC {: RESULT=new ParseNode("static"); :} |
703 FINAL {: RESULT=new ParseNode("final"); :}|
704 NATIVE {: RESULT=new ParseNode("native"); :} |
705 SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
706 ATOMIC {: RESULT=new ParseNode("atomic"); :}
709 // STRICTFP // note that semantic analysis must check that the
710 // context of the modifier allows strictfp.
715 // 19.8.1) Class Declaration:
716 class_declaration ::=
717 modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so //interfaces_opt
720 ParseNode pn=new ParseNode("class_declaration");
721 pn.addChild("modifiers").addChild(mo);
722 pn.addChild("name").addChild(id);
723 pn.addChild("super").addChild(so);
724 pn.addChild("classbody").addChild(body);
728 super ::= EXTENDS class_type:classtype {:
733 {: RESULT=new ParseNode("empty"); :}
739 //interfaces ::= IMPLEMENTS interface_type_list
744 //interface_type_list ::=
746 // | interface_type_list COMMA interface_type
749 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
752 class_body_declarations_opt ::=
753 {: RESULT=new ParseNode("empty"); :}
754 | class_body_declarations:cbd {: RESULT=cbd; :};
756 class_body_declarations ::=
757 class_body_declaration:cbd {:
758 ParseNode pn=new ParseNode("class_body_declaration_list");
762 | class_body_declarations:cbds class_body_declaration:cbd {:
768 class_body_declaration ::=
769 class_member_declaration:member {:
770 RESULT=(new ParseNode("member")).addChild(member).getRoot();
772 // | static_initializer
773 | constructor_declaration:constructor {:
774 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
777 RESULT=(new ParseNode("block")).addChild(block).getRoot();
780 class_member_declaration ::=
781 //failure aware computation
782 flag_declaration:flag {:
783 RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
786 field_declaration:field {:
787 RESULT=(new ParseNode("field")).addChild(field).getRoot();
789 | method_declaration:method {:
790 RESULT=(new ParseNode("method")).addChild(method).getRoot();
792 /* repeat the prod for 'class_declaration' here: */
793 // | modifiers_opt CLASS IDENTIFIER super_opt class_body
794 // | interface_declaration
795 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
798 //Failure aware computation
800 FLAG IDENTIFIER:id SEMICOLON {:
801 ParseNode pn=new ParseNode("flag_declaration");
802 pn.addChild("name").addChild(id);
805 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {:
806 ParseNode pn=new ParseNode("flag_declaration");
807 pn.addChild("name").addChild(id);
808 pn.addChild("external");
813 // 19.8.2) Field Declarations
814 field_declaration ::=
815 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {:
816 ParseNode pn=new ParseNode("field_declaration");
817 pn.addChild("modifier").addChild(mo);
818 pn.addChild("type").addChild(type);
819 pn.addChild("variables").addChild(var);
822 modifiers_opt:mo GLOBAL type:type variable_declarators:var SEMICOLON {:
823 ParseNode pn=new ParseNode("field_declaration");
824 pn.addChild("modifier").addChild(mo);
825 pn.addChild("type").addChild(type);
826 pn.addChild("variables").addChild(var);
827 pn.addChild("global");
832 variable_declarators ::=
833 variable_declarator:vd {:
834 ParseNode pn=new ParseNode("variable_declarators_list");
838 | variable_declarators:vds COMMA variable_declarator:vd {:
843 variable_declarator ::=
844 variable_declarator_id:id {:
845 ParseNode pn=new ParseNode("variable_declarator");
849 | variable_declarator_id:id EQ variable_initializer:init {:
850 ParseNode pn=new ParseNode("variable_declarator");
852 pn.addChild("initializer").addChild(init);
856 variable_declarator_id ::=
858 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
859 | variable_declarator_id:id LBRACK RBRACK {:
860 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
862 variable_initializer ::=
863 expression:exp {: RESULT=exp; :}
864 // | array_initializer
867 // 19.8.3) Method Declarations
868 method_declaration ::=
869 method_header:header method_body:body {:
870 ParseNode pn=new ParseNode("method_declaration");
872 pn.addChild("body").addChild(body);
877 modifiers_opt:mo type:type method_declarator:decl //throws_opt
879 ParseNode pn=new ParseNode("method_header");
880 pn.addChild("modifiers").addChild(mo);
881 pn.addChild("returntype").addChild(type);
885 | modifiers_opt:mo VOID method_declarator:decl //throws_opt
887 ParseNode pn=new ParseNode("method_header");
888 pn.addChild("modifiers").addChild(mo);
893 method_declarator ::=
894 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {:
895 ParseNode pn=new ParseNode("method_declarator");
896 pn.addChild("name").addChild(id);
897 pn.addChild("parameters").addChild(params);
900 // | method_declarator LBRACK RBRACK // deprecated
901 // be careful; the above production also allows 'void foo() []'
903 formal_parameter_list_opt ::=
904 {: RESULT=new ParseNode("empty"); :}
905 | formal_parameter_list:fpl {:
909 formal_parameter_list ::=
910 formal_parameter:fp {:
911 ParseNode pn=new ParseNode("formal_parameter_list");
915 | formal_parameter_list:fpl COMMA formal_parameter:fp {:
921 type:type variable_declarator_id:name {:
922 ParseNode pn=new ParseNode("formal_parameter");
928 TAG variable_declarator_id:name {:
929 ParseNode pn=new ParseNode("tag_parameter");
933 // | FINAL type variable_declarator_id
938 //throws ::= THROWS class_type_list
940 //class_type_list ::=
942 // | class_type_list COMMA class_type
944 method_body ::= block:block {:
947 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
950 // 19.8.4) Static Initializers
951 //static_initializer ::=
955 // 19.8.5) Constructor Declarations
956 constructor_declaration ::=
957 modifiers_opt:mo constructor_declarator:cd
959 constructor_body:body {:
960 ParseNode pn=new ParseNode("constructor_declaration");
961 pn.addChild("modifiers").addChild(mo);
963 pn.addChild("body").addChild(body);
966 modifiers_opt:mo GLOBAL constructor_declarator:cd
968 constructor_body:body {:
969 ParseNode pn=new ParseNode("constructor_declaration");
970 pn.addChild("global");
971 pn.addChild("modifiers").addChild(mo);
973 pn.addChild("body").addChild(body);
977 constructor_declarator ::=
978 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {:
979 ParseNode pn=new ParseNode("constructor_declarator");
981 pn.addChild("parameters").addChild(fplo);
986 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {:
987 ParseNode pn=new ParseNode("constructor_body");
992 LBRACE explicit_constructor_invocation:eci RBRACE {:
993 ParseNode pn=new ParseNode("constructor_body");
997 LBRACE block_statements:block RBRACE {:
998 ParseNode pn=new ParseNode("constructor_body");
1002 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1004 explicit_constructor_invocation ::=
1005 // THIS LPAREN argument_list_opt RPAREN SEMICOLON
1007 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1008 ParseNode pn=new ParseNode("superinvoke");
1012 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1013 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1018 // 19.9.1) Interface Declarations
1019 //interface_declaration ::=
1020 // modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
1023 //extends_interfaces_opt ::=
1024 // | extends_interfaces
1026 //extends_interfaces ::=
1027 // EXTENDS interface_type
1028 // | extends_interfaces COMMA interface_type
1030 //interface_body ::=
1031 // LBRACE interface_member_declarations_opt RBRACE
1033 //interface_member_declarations_opt ::=
1034 // | interface_member_declarations
1036 //interface_member_declarations ::=
1037 // interface_member_declaration
1038 // | interface_member_declarations interface_member_declaration
1040 //interface_member_declaration ::=
1041 // constant_declaration
1042 // | abstract_method_declaration
1043 // | class_declaration
1044 // | interface_declaration
1047 //constant_declaration ::=
1048 // field_declaration
1049 // // need to semantically check that modifiers of field declaration
1050 // // include only PUBLIC, STATIC, or FINAL. Other modifiers are
1053 //abstract_method_declaration ::=
1054 // method_header SEMICOLON
1059 //array_initializer ::=
1060 // LBRACE variable_initializers COMMA RBRACE
1061 // | LBRACE variable_initializers RBRACE
1062 // | LBRACE COMMA RBRACE
1065 //variable_initializers ::=
1066 // variable_initializer
1067 // | variable_initializers COMMA variable_initializer
1070 // 19.11) Blocks and Statements
1071 block ::= LBRACE block_statements_opt:bso RBRACE {:
1075 block_statements_opt ::=
1076 {: RESULT=new ParseNode("empty"); :}
1077 | block_statements:bs {:
1081 block_statements ::=
1082 block_statement:bs {:
1083 ParseNode pn=new ParseNode("block_statement_list");
1087 | block_statements:bss block_statement:bs {:
1093 tag_variable_declaration_statement:tvds {:
1096 | local_variable_declaration_statement:lvds {:
1099 | statement:statement {:
1102 // | class_declaration
1103 // | interface_declaration
1105 tag_variable_declaration_statement ::=
1106 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
1107 ParseNode pn=new ParseNode("tag_declaration");
1108 pn.addChild("single").addChild(id);
1109 pn.addChild("type").addChild(type);
1113 local_variable_declaration_statement ::=
1114 local_variable_declaration:lvd SEMICOLON {:
1118 local_variable_declaration ::=
1119 type:type variable_declarators:var {:
1120 ParseNode pn=new ParseNode("local_variable_declaration");
1125 // | FINAL type variable_declarators
1127 statement ::= statement_without_trailing_substatement:st {:
1130 // | labeled_statement:st {: RESULT=st; :}
1131 | if_then_statement:st {: RESULT=st; :}
1132 | if_then_else_statement:st {: RESULT=st; :}
1133 | while_statement:st {: RESULT=st; :}
1134 | for_statement:st {: RESULT=st; :}
1136 statement_no_short_if ::=
1137 statement_without_trailing_substatement:st {: RESULT=st; :}
1138 // | labeled_statement_no_short_if:st {: RESULT=st; :}
1139 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
1140 | while_statement_no_short_if:st {: RESULT=st; :}
1141 | for_statement_no_short_if:st {: RESULT=st; :}
1143 statement_without_trailing_substatement ::=
1144 block:st {: RESULT=st; :}
1145 | empty_statement:st {: RESULT=st; :}
1146 | expression_statement:st {: RESULT=st; :}
1147 // | switch_statement
1148 | do_statement:dos {:RESULT=dos; :}
1149 | break_statement:st {: RESULT=st; :}
1150 | continue_statement:st {: RESULT=st; :}
1151 | return_statement:st {: RESULT=st; :}
1152 | task_exitstatement:st {: RESULT=st; :}
1153 | atomic_statement:st {: RESULT=st; :}
1154 // | synchronized_statement
1155 // | throw_statement
1157 // | assert_statement
1160 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1162 //labeled_statement ::=
1163 // IDENTIFIER COLON statement
1165 //labeled_statement_no_short_if ::=
1166 // IDENTIFIER COLON statement_no_short_if
1168 expression_statement ::=
1169 statement_expression:se SEMICOLON {:
1170 ParseNode pn=new ParseNode("expression");
1174 statement_expression ::=
1175 assignment:st {: RESULT=st; :}
1176 | preincrement_expression:st {: RESULT=st; :}
1177 | predecrement_expression:st {: RESULT=st; :}
1178 | postincrement_expression:st {: RESULT=st; :}
1179 | postdecrement_expression:st {: RESULT=st; :}
1180 | method_invocation:st {: RESULT=st; :}
1181 | class_instance_creation_expression:st {: RESULT=st; :}
1183 if_then_statement ::=
1184 IF LPAREN expression:exp RPAREN statement:st {:
1185 ParseNode pn=new ParseNode("ifstatement");
1186 pn.addChild("condition").addChild(exp);
1187 pn.addChild("statement").addChild(st);
1191 if_then_else_statement ::=
1192 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1193 ELSE statement:else_st {:
1194 ParseNode pn=new ParseNode("ifstatement");
1195 pn.addChild("condition").addChild(exp);
1196 pn.addChild("statement").addChild(st);
1197 pn.addChild("else_statement").addChild(else_st);
1201 if_then_else_statement_no_short_if ::=
1202 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1203 ELSE statement_no_short_if: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 //switch_statement ::=
1212 // SWITCH LPAREN expression RPAREN switch_block
1215 // LBRACE switch_block_statement_groups switch_labels RBRACE
1216 // | LBRACE switch_block_statement_groups RBRACE
1217 // | LBRACE switch_labels RBRACE
1220 //switch_block_statement_groups ::=
1221 // switch_block_statement_group
1222 // | switch_block_statement_groups switch_block_statement_group
1224 //switch_block_statement_group ::=
1225 // switch_labels block_statements
1229 // | switch_labels switch_label
1232 // CASE constant_expression COLON
1237 WHILE LPAREN expression:exp RPAREN statement:st {:
1238 ParseNode pn=new ParseNode("whilestatement");
1239 pn.addChild("condition").addChild(exp);
1240 pn.addChild("statement").addChild(st);
1244 while_statement_no_short_if ::=
1245 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1246 ParseNode pn=new ParseNode("whilestatement");
1247 pn.addChild("condition").addChild(exp);
1248 pn.addChild("statement").addChild(st);
1253 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1254 ParseNode pn=new ParseNode("dowhilestatement");
1255 pn.addChild("condition").addChild(exp);
1256 pn.addChild("statement").addChild(st);
1261 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1262 for_update_opt:update RPAREN statement:st {:
1263 ParseNode pn=new ParseNode("forstatement");
1264 pn.addChild("initializer").addChild(init);
1265 pn.addChild("condition").addChild(exp);
1266 pn.addChild("update").addChild(update);
1267 pn.addChild("statement").addChild(st);
1271 for_statement_no_short_if ::=
1272 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1273 for_update_opt:update RPAREN statement_no_short_if:st {:
1274 ParseNode pn=new ParseNode("forstatement");
1275 pn.addChild("initializer").addChild(init);
1276 pn.addChild("condition").addChild(exp);
1277 pn.addChild("update").addChild(update);
1278 pn.addChild("statement").addChild(st);
1283 {: RESULT=new ParseNode("empty"); :}
1284 | for_init:init {: RESULT=init; :}
1286 for_init ::= statement_expression_list:list {: RESULT=list; :}
1287 | local_variable_declaration:decl {: RESULT=decl; :}
1290 {: RESULT=new ParseNode("empty"); :}
1291 | for_update:update {: RESULT=update; :}
1293 for_update ::= statement_expression_list:list {: RESULT=list; :}
1295 statement_expression_list ::=
1296 statement_expression:expr {:
1297 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1299 | statement_expression_list:list COMMA statement_expression:expr {:
1300 list.addChild(expr);
1305 //identifier_opt ::=
1312 SEMICOLON {: RESULT=new ParseNode("break"); :}
1315 continue_statement ::=
1319 {: RESULT=new ParseNode("continue"); :}
1321 return_statement ::=
1322 RETURN expression_opt:exp SEMICOLON {:
1323 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1325 //throw_statement ::=
1326 // THROW expression SEMICOLON
1328 //synchronized_statement ::=
1329 // SYNCHRONIZED LPAREN expression RPAREN block
1331 atomic_statement ::=
1333 RESULT=(new ParseNode("atomic")).addChild(blk).getRoot();
1337 // TRY block catches
1338 // | TRY block catches_opt finally
1343 //catches ::= catch_clause
1344 // | catches catch_clause
1347 // CATCH LPAREN formal_parameter RPAREN block
1349 //finally ::= FINALLY block
1351 //assert_statement ::=
1352 // ASSERT expression SEMICOLON
1353 // | ASSERT expression COLON expression SEMICOLON
1356 // 19.12) Expressions
1357 primary ::= primary_no_new_array:st {:
1359 // | array_creation_init:st {:
1362 | array_creation_uninit:st {:
1366 primary_no_new_array ::=
1367 literal:lit {: RESULT=lit; :}
1368 | THIS {: RESULT=new ParseNode("this"); :}
1369 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1370 | class_instance_creation_expression:exp {: RESULT=exp; :}
1371 | field_access:exp {: RESULT=exp; :}
1372 | method_invocation:exp {: RESULT=exp; :}
1373 | array_access:exp {: RESULT=exp; :}
1374 | ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {:
1375 ParseNode pn=new ParseNode("isavailable");
1379 // | primitive_type DOT CLASS
1381 // | array_type DOT CLASS
1385 class_instance_creation_expression ::=
1386 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1387 ParseNode pn=new ParseNode("createobject");
1394 | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1395 ParseNode pn=new ParseNode("createobject");
1399 pn.addChild("global");
1402 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
1403 ParseNode pn=new ParseNode("createobject");
1409 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
1410 ParseNode pn=new ParseNode("createobject");
1418 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1419 // | primary DOT NEW IDENTIFIER
1420 // LPAREN argument_list_opt RPAREN {:
1423 // | primary DOT NEW IDENTIFIER
1424 // LPAREN argument_list_opt RPAREN class_body
1425 // | name DOT NEW IDENTIFIER
1426 // LPAREN argument_list_opt RPAREN
1427 // | name DOT NEW IDENTIFIER
1428 // LPAREN argument_list_opt RPAREN class_body
1430 cons_argument_list_opt ::=
1431 {: RESULT=new ParseNode("empty"); :}
1432 | cons_argument_list:args {: RESULT=args; :}
1435 cons_argument_list ::=
1436 IDENTIFIER:id COLON expression:exp {:
1437 ParseNode pn=new ParseNode("cons_argument_list");
1438 ParseNode pnarg=pn.addChild("binding");
1439 pnarg.addChild("var").addChild(id);
1440 pnarg.addChild("exp").addChild(exp);
1443 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1444 ParseNode pnarg=new ParseNode("binding");
1445 pnarg.addChild("var").addChild(id);
1446 pnarg.addChild("exp").addChild(exp);
1447 list.addChild(pnarg);
1452 argument_list_opt ::=
1453 {: RESULT=new ParseNode("empty"); :}
1454 | argument_list:args {: RESULT=args; :}
1459 ParseNode pn=new ParseNode("argument_list");
1463 | argument_list:list COMMA expression:exp {:
1468 array_creation_uninit ::=
1469 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1470 ParseNode pn=new ParseNode("createarray");
1472 pn.addChild(dimexpr);
1473 pn.addChild("dims_opt").setLiteral(dims);
1476 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1477 ParseNode pn=new ParseNode("createarray");
1479 pn.addChild(dimexpr);
1480 pn.addChild("dims_opt").setLiteral(dims);
1483 | GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1484 ParseNode pn=new ParseNode("createarray");
1486 pn.addChild(dimexpr);
1487 pn.addChild("dims_opt").setLiteral(dims);
1488 pn.addChild("global");
1491 | GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1492 ParseNode pn=new ParseNode("createarray");
1494 pn.addChild(dimexpr);
1495 pn.addChild("dims_opt").setLiteral(dims);
1496 pn.addChild("global");
1500 //array_creation_init ::=
1501 // NEW primitive_type dims array_initializer
1502 // | NEW class_or_interface_type dims array_initializer
1504 dim_exprs ::= dim_expr:exp {:
1505 ParseNode pn=new ParseNode("dim_exprs");
1508 | dim_exprs:base dim_expr:exp {:
1513 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1515 dims_opt ::= {: RESULT=new Integer(0); :}
1516 | dims:dims {: RESULT = dims; :}
1519 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1520 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1524 primary:base DOT IDENTIFIER:id {:
1525 ParseNode pn=new ParseNode("fieldaccess");
1526 pn.addChild("base").addChild(base);
1527 pn.addChild("field").addChild(id);
1530 // | SUPER DOT IDENTIFIER
1531 // | name DOT SUPER DOT IDENTIFIER
1533 method_invocation ::=
1534 name:name LPAREN argument_list_opt:args RPAREN {:
1535 ParseNode pn=new ParseNode("methodinvoke1");
1540 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1541 ParseNode pn=new ParseNode("methodinvoke2");
1542 pn.addChild("base").addChild(base);
1543 pn.addChild("id").addChild(name);
1547 | SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {:
1548 ParseNode name=new ParseNode("name");
1549 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
1550 name.addChild("identifier").addChild(id);
1551 ParseNode pn=new ParseNode("methodinvoke1");
1556 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1559 name:name LBRACK expression:exp RBRACK {:
1560 ParseNode pn=new ParseNode("arrayaccess");
1561 pn.addChild("base").addChild(name);
1562 pn.addChild("index").addChild(exp);
1565 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1566 ParseNode pn=new ParseNode("arrayaccess");
1567 pn.addChild("base").addChild(base);
1568 pn.addChild("index").addChild(exp);
1571 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1572 // ParseNode pn=new ParseNode("arrayaccess");
1573 // pn.addChild("init").addChild(init);
1574 // pn.addChild("index").addChild(exp);
1578 postfix_expression ::=
1581 | name:exp {: RESULT=exp; :}
1582 | postincrement_expression:exp {: RESULT=exp; :}
1583 | postdecrement_expression:exp {: RESULT=exp; :}
1585 postincrement_expression ::=
1586 postfix_expression:exp PLUSPLUS
1587 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1589 postdecrement_expression ::=
1590 postfix_expression:exp MINUSMINUS
1591 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1593 unary_expression ::=
1594 preincrement_expression:exp {: RESULT=exp; :}
1595 | predecrement_expression:exp {: RESULT=exp; :}
1596 | PLUS unary_expression:exp
1597 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1598 | MINUS unary_expression:exp
1599 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1600 | unary_expression_not_plus_minus:exp {:
1603 preincrement_expression ::=
1604 PLUSPLUS unary_expression:exp
1605 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1607 predecrement_expression ::=
1608 MINUSMINUS unary_expression:exp
1609 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1611 unary_expression_not_plus_minus ::=
1612 postfix_expression:exp {:
1614 | COMP unary_expression:exp
1615 {: RESULT=(new ParseNode("comp")).addChild(exp).getRoot(); :}
1616 | NOT unary_expression:exp
1617 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1618 | cast_expression:exp {: RESULT=exp; :}
1621 LPAREN primitive_type:type
1623 RPAREN unary_expression:exp {:
1624 ParseNode pn=new ParseNode("cast1");
1625 pn.addChild("type").addChild(type);
1626 pn.addChild("exp").addChild(exp);
1629 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
1630 ParseNode pn=new ParseNode("cast2");
1631 pn.addChild("type").addChild(type);
1632 pn.addChild("exp").addChild(exp);
1636 // | LPAREN name dims RPAREN unary_expression_not_plus_minus
1638 multiplicative_expression ::=
1639 unary_expression:exp {:
1641 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
1642 ParseNode pn=new ParseNode("mult");
1647 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1648 ParseNode pn=new ParseNode("div");
1653 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1654 ParseNode pn=new ParseNode("mod");
1660 additive_expression ::=
1661 multiplicative_expression:exp {:
1663 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
1664 ParseNode pn=new ParseNode("add");
1669 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
1670 ParseNode pn=new ParseNode("sub");
1676 shift_expression ::=
1677 additive_expression:exp {:
1679 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
1680 ParseNode pn=new ParseNode("leftshift");
1685 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
1686 ParseNode pn=new ParseNode("rightshift");
1691 | shift_expression:exp1 URSHIFT additive_expression:exp2 {:
1692 ParseNode pn=new ParseNode("urightshift");
1698 relational_expression ::=
1699 shift_expression:exp {:
1701 | relational_expression:exp1 LT shift_expression:exp2 {:
1702 ParseNode pn=new ParseNode("comp_lt");
1707 | relational_expression:exp1 GT shift_expression:exp2 {:
1708 ParseNode pn=new ParseNode("comp_gt");
1713 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
1714 ParseNode pn=new ParseNode("comp_lte");
1719 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
1720 ParseNode pn=new ParseNode("comp_gte");
1725 // | relational_expression INSTANCEOF reference_type
1728 equality_expression ::=
1729 relational_expression:exp {:
1731 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
1732 ParseNode pn=new ParseNode("equal");
1737 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
1738 ParseNode pn=new ParseNode("not_equal");
1745 equality_expression:exp {:
1747 | and_expression:exp1 AND equality_expression:exp2 {:
1748 ParseNode pn=new ParseNode("bitwise_and");
1754 exclusive_or_expression ::=
1755 and_expression:expr {:
1758 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
1759 ParseNode pn=new ParseNode("bitwise_xor");
1765 inclusive_or_expression ::=
1766 exclusive_or_expression:exclor {:
1768 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
1769 ParseNode pn=new ParseNode("bitwise_or");
1775 conditional_and_expression ::=
1776 inclusive_or_expression:inclor {:
1778 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1779 ParseNode pn=new ParseNode("logical_and");
1785 conditional_or_expression ::=
1786 conditional_and_expression:condand {:
1788 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
1789 ParseNode pn=new ParseNode("logical_or");
1795 conditional_expression ::=
1796 conditional_or_expression:condor {:
1798 // | conditional_or_expression QUESTION expression
1799 // COLON conditional_expression
1801 assignment_expression ::=
1802 conditional_expression:expr {:
1804 assignment:assign {:
1807 // semantic check necessary here to ensure a valid left-hand side.
1808 // allowing a parenthesized variable here on the lhs was introduced in
1809 // JLS 2; thanks to Eric Blake for pointing this out.
1810 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
1811 ParseNode pn=new ParseNode("assignment");
1812 pn.addChild("op").addChild(op);
1813 ParseNode pnargs=pn.addChild("args");
1814 pnargs.addChild(lvalue);
1815 pnargs.addChild(rvalue);
1819 assignment_operator ::=
1820 EQ {: RESULT=new ParseNode("eq"); :}
1821 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
1822 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
1823 | MODEQ {: RESULT=new ParseNode("modeq"); :}
1824 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
1825 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
1826 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
1827 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
1828 | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
1829 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
1830 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
1831 | OREQ {: RESULT=new ParseNode("oreq"); :}
1834 {: RESULT=new ParseNode("empty"); :}
1838 expression ::= assignment_expression:exp {:
1841 //constant_expression ::=