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 // LBRACE explicit_constructor_invocation RBRACE |
988 LBRACE block_statements:block RBRACE {:
989 ParseNode pn=new ParseNode("constructor_body");
993 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
995 //explicit_constructor_invocation ::=
996 // THIS LPAREN argument_list_opt RPAREN SEMICOLON
997 // | SUPER LPAREN argument_list_opt RPAREN SEMICOLON
998 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
999 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1004 // 19.9.1) Interface Declarations
1005 //interface_declaration ::=
1006 // modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
1009 //extends_interfaces_opt ::=
1010 // | extends_interfaces
1012 //extends_interfaces ::=
1013 // EXTENDS interface_type
1014 // | extends_interfaces COMMA interface_type
1016 //interface_body ::=
1017 // LBRACE interface_member_declarations_opt RBRACE
1019 //interface_member_declarations_opt ::=
1020 // | interface_member_declarations
1022 //interface_member_declarations ::=
1023 // interface_member_declaration
1024 // | interface_member_declarations interface_member_declaration
1026 //interface_member_declaration ::=
1027 // constant_declaration
1028 // | abstract_method_declaration
1029 // | class_declaration
1030 // | interface_declaration
1033 //constant_declaration ::=
1034 // field_declaration
1035 // // need to semantically check that modifiers of field declaration
1036 // // include only PUBLIC, STATIC, or FINAL. Other modifiers are
1039 //abstract_method_declaration ::=
1040 // method_header SEMICOLON
1045 //array_initializer ::=
1046 // LBRACE variable_initializers COMMA RBRACE
1047 // | LBRACE variable_initializers RBRACE
1048 // | LBRACE COMMA RBRACE
1051 //variable_initializers ::=
1052 // variable_initializer
1053 // | variable_initializers COMMA variable_initializer
1056 // 19.11) Blocks and Statements
1057 block ::= LBRACE block_statements_opt:bso RBRACE {:
1061 block_statements_opt ::=
1062 {: RESULT=new ParseNode("empty"); :}
1063 | block_statements:bs {:
1067 block_statements ::=
1068 block_statement:bs {:
1069 ParseNode pn=new ParseNode("block_statement_list");
1073 | block_statements:bss block_statement:bs {:
1079 tag_variable_declaration_statement:tvds {:
1082 | local_variable_declaration_statement:lvds {:
1085 | statement:statement {:
1088 // | class_declaration
1089 // | interface_declaration
1091 tag_variable_declaration_statement ::=
1092 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
1093 ParseNode pn=new ParseNode("tag_declaration");
1094 pn.addChild("single").addChild(id);
1095 pn.addChild("type").addChild(type);
1099 local_variable_declaration_statement ::=
1100 local_variable_declaration:lvd SEMICOLON {:
1104 local_variable_declaration ::=
1105 type:type variable_declarators:var {:
1106 ParseNode pn=new ParseNode("local_variable_declaration");
1111 // | FINAL type variable_declarators
1113 statement ::= statement_without_trailing_substatement:st {:
1116 // | labeled_statement:st {: RESULT=st; :}
1117 | if_then_statement:st {: RESULT=st; :}
1118 | if_then_else_statement:st {: RESULT=st; :}
1119 | while_statement:st {: RESULT=st; :}
1120 | for_statement:st {: RESULT=st; :}
1122 statement_no_short_if ::=
1123 statement_without_trailing_substatement:st {: RESULT=st; :}
1124 // | labeled_statement_no_short_if:st {: RESULT=st; :}
1125 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
1126 | while_statement_no_short_if:st {: RESULT=st; :}
1127 | for_statement_no_short_if:st {: RESULT=st; :}
1129 statement_without_trailing_substatement ::=
1130 block:st {: RESULT=st; :}
1131 | empty_statement:st {: RESULT=st; :}
1132 | expression_statement:st {: RESULT=st; :}
1133 // | switch_statement
1134 | do_statement:dos {:RESULT=dos; :}
1135 | break_statement:st {: RESULT=st; :}
1136 | continue_statement:st {: RESULT=st; :}
1137 | return_statement:st {: RESULT=st; :}
1138 | task_exitstatement:st {: RESULT=st; :}
1139 | atomic_statement:st {: RESULT=st; :}
1140 // | synchronized_statement
1141 // | throw_statement
1143 // | assert_statement
1146 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1148 //labeled_statement ::=
1149 // IDENTIFIER COLON statement
1151 //labeled_statement_no_short_if ::=
1152 // IDENTIFIER COLON statement_no_short_if
1154 expression_statement ::=
1155 statement_expression:se SEMICOLON {:
1156 ParseNode pn=new ParseNode("expression");
1160 statement_expression ::=
1161 assignment:st {: RESULT=st; :}
1162 | preincrement_expression:st {: RESULT=st; :}
1163 | predecrement_expression:st {: RESULT=st; :}
1164 | postincrement_expression:st {: RESULT=st; :}
1165 | postdecrement_expression:st {: RESULT=st; :}
1166 | method_invocation:st {: RESULT=st; :}
1167 | class_instance_creation_expression:st {: RESULT=st; :}
1169 if_then_statement ::=
1170 IF LPAREN expression:exp RPAREN statement:st {:
1171 ParseNode pn=new ParseNode("ifstatement");
1172 pn.addChild("condition").addChild(exp);
1173 pn.addChild("statement").addChild(st);
1177 if_then_else_statement ::=
1178 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1179 ELSE statement:else_st {:
1180 ParseNode pn=new ParseNode("ifstatement");
1181 pn.addChild("condition").addChild(exp);
1182 pn.addChild("statement").addChild(st);
1183 pn.addChild("else_statement").addChild(else_st);
1187 if_then_else_statement_no_short_if ::=
1188 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1189 ELSE statement_no_short_if:else_st {:
1190 ParseNode pn=new ParseNode("ifstatement");
1191 pn.addChild("condition").addChild(exp);
1192 pn.addChild("statement").addChild(st);
1193 pn.addChild("else_statement").addChild(else_st);
1197 //switch_statement ::=
1198 // SWITCH LPAREN expression RPAREN switch_block
1201 // LBRACE switch_block_statement_groups switch_labels RBRACE
1202 // | LBRACE switch_block_statement_groups RBRACE
1203 // | LBRACE switch_labels RBRACE
1206 //switch_block_statement_groups ::=
1207 // switch_block_statement_group
1208 // | switch_block_statement_groups switch_block_statement_group
1210 //switch_block_statement_group ::=
1211 // switch_labels block_statements
1215 // | switch_labels switch_label
1218 // CASE constant_expression COLON
1223 WHILE LPAREN expression:exp RPAREN statement:st {:
1224 ParseNode pn=new ParseNode("whilestatement");
1225 pn.addChild("condition").addChild(exp);
1226 pn.addChild("statement").addChild(st);
1230 while_statement_no_short_if ::=
1231 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1232 ParseNode pn=new ParseNode("whilestatement");
1233 pn.addChild("condition").addChild(exp);
1234 pn.addChild("statement").addChild(st);
1239 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1240 ParseNode pn=new ParseNode("dowhilestatement");
1241 pn.addChild("condition").addChild(exp);
1242 pn.addChild("statement").addChild(st);
1247 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1248 for_update_opt:update RPAREN statement:st {:
1249 ParseNode pn=new ParseNode("forstatement");
1250 pn.addChild("initializer").addChild(init);
1251 pn.addChild("condition").addChild(exp);
1252 pn.addChild("update").addChild(update);
1253 pn.addChild("statement").addChild(st);
1257 for_statement_no_short_if ::=
1258 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1259 for_update_opt:update RPAREN statement_no_short_if:st {:
1260 ParseNode pn=new ParseNode("forstatement");
1261 pn.addChild("initializer").addChild(init);
1262 pn.addChild("condition").addChild(exp);
1263 pn.addChild("update").addChild(update);
1264 pn.addChild("statement").addChild(st);
1269 {: RESULT=new ParseNode("empty"); :}
1270 | for_init:init {: RESULT=init; :}
1272 for_init ::= statement_expression_list:list {: RESULT=list; :}
1273 | local_variable_declaration:decl {: RESULT=decl; :}
1276 {: RESULT=new ParseNode("empty"); :}
1277 | for_update:update {: RESULT=update; :}
1279 for_update ::= statement_expression_list:list {: RESULT=list; :}
1281 statement_expression_list ::=
1282 statement_expression:expr {:
1283 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1285 | statement_expression_list:list COMMA statement_expression:expr {:
1286 list.addChild(expr);
1291 //identifier_opt ::=
1298 SEMICOLON {: RESULT=new ParseNode("break"); :}
1301 continue_statement ::=
1305 {: RESULT=new ParseNode("continue"); :}
1307 return_statement ::=
1308 RETURN expression_opt:exp SEMICOLON {:
1309 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1311 //throw_statement ::=
1312 // THROW expression SEMICOLON
1314 //synchronized_statement ::=
1315 // SYNCHRONIZED LPAREN expression RPAREN block
1317 atomic_statement ::=
1319 RESULT=(new ParseNode("atomic")).addChild(blk).getRoot();
1323 // TRY block catches
1324 // | TRY block catches_opt finally
1329 //catches ::= catch_clause
1330 // | catches catch_clause
1333 // CATCH LPAREN formal_parameter RPAREN block
1335 //finally ::= FINALLY block
1337 //assert_statement ::=
1338 // ASSERT expression SEMICOLON
1339 // | ASSERT expression COLON expression SEMICOLON
1342 // 19.12) Expressions
1343 primary ::= primary_no_new_array:st {:
1345 // | array_creation_init:st {:
1348 | array_creation_uninit:st {:
1352 primary_no_new_array ::=
1353 literal:lit {: RESULT=lit; :}
1354 | THIS {: RESULT=new ParseNode("this"); :}
1355 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1356 | class_instance_creation_expression:exp {: RESULT=exp; :}
1357 | field_access:exp {: RESULT=exp; :}
1358 | method_invocation:exp {: RESULT=exp; :}
1359 | array_access:exp {: RESULT=exp; :}
1360 | ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {:
1361 ParseNode pn=new ParseNode("isavailable");
1365 // | primitive_type DOT CLASS
1367 // | array_type DOT CLASS
1371 class_instance_creation_expression ::=
1372 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1373 ParseNode pn=new ParseNode("createobject");
1380 | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1381 ParseNode pn=new ParseNode("createobject");
1385 pn.addChild("global");
1388 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
1389 ParseNode pn=new ParseNode("createobject");
1395 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
1396 ParseNode pn=new ParseNode("createobject");
1404 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1405 // | primary DOT NEW IDENTIFIER
1406 // LPAREN argument_list_opt RPAREN {:
1409 // | primary DOT NEW IDENTIFIER
1410 // LPAREN argument_list_opt RPAREN class_body
1411 // | name DOT NEW IDENTIFIER
1412 // LPAREN argument_list_opt RPAREN
1413 // | name DOT NEW IDENTIFIER
1414 // LPAREN argument_list_opt RPAREN class_body
1416 cons_argument_list_opt ::=
1417 {: RESULT=new ParseNode("empty"); :}
1418 | cons_argument_list:args {: RESULT=args; :}
1421 cons_argument_list ::=
1422 IDENTIFIER:id COLON expression:exp {:
1423 ParseNode pn=new ParseNode("cons_argument_list");
1424 ParseNode pnarg=pn.addChild("binding");
1425 pnarg.addChild("var").addChild(id);
1426 pnarg.addChild("exp").addChild(exp);
1429 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1430 ParseNode pnarg=new ParseNode("binding");
1431 pnarg.addChild("var").addChild(id);
1432 pnarg.addChild("exp").addChild(exp);
1433 list.addChild(pnarg);
1438 argument_list_opt ::=
1439 {: RESULT=new ParseNode("empty"); :}
1440 | argument_list:args {: RESULT=args; :}
1445 ParseNode pn=new ParseNode("argument_list");
1449 | argument_list:list COMMA expression:exp {:
1454 array_creation_uninit ::=
1455 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1456 ParseNode pn=new ParseNode("createarray");
1458 pn.addChild(dimexpr);
1459 pn.addChild("dims_opt").setLiteral(dims);
1462 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1463 ParseNode pn=new ParseNode("createarray");
1465 pn.addChild(dimexpr);
1466 pn.addChild("dims_opt").setLiteral(dims);
1469 | NEW GLOBAL 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);
1474 pn.addChild("global");
1477 | NEW GLOBAL class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1478 ParseNode pn=new ParseNode("createarray");
1480 pn.addChild(dimexpr);
1481 pn.addChild("dims_opt").setLiteral(dims);
1482 pn.addChild("global");
1486 //array_creation_init ::=
1487 // NEW primitive_type dims array_initializer
1488 // | NEW class_or_interface_type dims array_initializer
1490 dim_exprs ::= dim_expr:exp {:
1491 ParseNode pn=new ParseNode("dim_exprs");
1494 | dim_exprs:base dim_expr:exp {:
1499 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1501 dims_opt ::= {: RESULT=new Integer(0); :}
1502 | dims:dims {: RESULT = dims; :}
1505 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1506 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1510 primary:base DOT IDENTIFIER:id {:
1511 ParseNode pn=new ParseNode("fieldaccess");
1512 pn.addChild("base").addChild(base);
1513 pn.addChild("field").addChild(id);
1516 // | SUPER DOT IDENTIFIER
1517 // | name DOT SUPER DOT IDENTIFIER
1519 method_invocation ::=
1520 name:name LPAREN argument_list_opt:args RPAREN {:
1521 ParseNode pn=new ParseNode("methodinvoke1");
1526 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1527 ParseNode pn=new ParseNode("methodinvoke2");
1528 pn.addChild("base").addChild(base);
1529 pn.addChild("id").addChild(name);
1533 // | SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1534 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1537 name:name LBRACK expression:exp RBRACK {:
1538 ParseNode pn=new ParseNode("arrayaccess");
1539 pn.addChild("base").addChild(name);
1540 pn.addChild("index").addChild(exp);
1543 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1544 ParseNode pn=new ParseNode("arrayaccess");
1545 pn.addChild("base").addChild(base);
1546 pn.addChild("index").addChild(exp);
1549 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1550 // ParseNode pn=new ParseNode("arrayaccess");
1551 // pn.addChild("init").addChild(init);
1552 // pn.addChild("index").addChild(exp);
1556 postfix_expression ::=
1559 | name:exp {: RESULT=exp; :}
1560 | postincrement_expression:exp {: RESULT=exp; :}
1561 | postdecrement_expression:exp {: RESULT=exp; :}
1563 postincrement_expression ::=
1564 postfix_expression:exp PLUSPLUS
1565 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1567 postdecrement_expression ::=
1568 postfix_expression:exp MINUSMINUS
1569 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1571 unary_expression ::=
1572 preincrement_expression:exp {: RESULT=exp; :}
1573 | predecrement_expression:exp {: RESULT=exp; :}
1574 | PLUS unary_expression:exp
1575 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1576 | MINUS unary_expression:exp
1577 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1578 | unary_expression_not_plus_minus:exp {:
1581 preincrement_expression ::=
1582 PLUSPLUS unary_expression:exp
1583 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1585 predecrement_expression ::=
1586 MINUSMINUS unary_expression:exp
1587 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1589 unary_expression_not_plus_minus ::=
1590 postfix_expression:exp {:
1592 // | COMP unary_expression
1593 | NOT unary_expression:exp
1594 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1595 | cast_expression:exp {: RESULT=exp; :}
1598 LPAREN primitive_type:type
1600 RPAREN unary_expression:exp {:
1601 ParseNode pn=new ParseNode("cast1");
1602 pn.addChild("type").addChild(type);
1603 pn.addChild("exp").addChild(exp);
1606 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
1607 ParseNode pn=new ParseNode("cast2");
1608 pn.addChild("type").addChild(type);
1609 pn.addChild("exp").addChild(exp);
1613 // | LPAREN name dims RPAREN unary_expression_not_plus_minus
1615 multiplicative_expression ::=
1616 unary_expression:exp {:
1618 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
1619 ParseNode pn=new ParseNode("mult");
1624 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1625 ParseNode pn=new ParseNode("div");
1630 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1631 ParseNode pn=new ParseNode("mod");
1637 additive_expression ::=
1638 multiplicative_expression:exp {:
1640 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
1641 ParseNode pn=new ParseNode("add");
1646 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
1647 ParseNode pn=new ParseNode("sub");
1653 shift_expression ::=
1654 additive_expression:exp {:
1656 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
1657 ParseNode pn=new ParseNode("leftshift");
1662 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
1663 ParseNode pn=new ParseNode("rightshift");
1668 // | shift_expression URSHIFT additive_expression
1670 relational_expression ::=
1671 shift_expression:exp {:
1673 | relational_expression:exp1 LT shift_expression:exp2 {:
1674 ParseNode pn=new ParseNode("comp_lt");
1679 | relational_expression:exp1 GT shift_expression:exp2 {:
1680 ParseNode pn=new ParseNode("comp_gt");
1685 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
1686 ParseNode pn=new ParseNode("comp_lte");
1691 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
1692 ParseNode pn=new ParseNode("comp_gte");
1697 // | relational_expression INSTANCEOF reference_type
1700 equality_expression ::=
1701 relational_expression:exp {:
1703 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
1704 ParseNode pn=new ParseNode("equal");
1709 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
1710 ParseNode pn=new ParseNode("not_equal");
1717 equality_expression:exp {:
1719 | and_expression:exp1 AND equality_expression:exp2 {:
1720 ParseNode pn=new ParseNode("bitwise_and");
1726 exclusive_or_expression ::=
1727 and_expression:expr {:
1730 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
1731 ParseNode pn=new ParseNode("bitwise_xor");
1737 inclusive_or_expression ::=
1738 exclusive_or_expression:exclor {:
1740 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
1741 ParseNode pn=new ParseNode("bitwise_or");
1747 conditional_and_expression ::=
1748 inclusive_or_expression:inclor {:
1750 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1751 ParseNode pn=new ParseNode("logical_and");
1757 conditional_or_expression ::=
1758 conditional_and_expression:condand {:
1760 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
1761 ParseNode pn=new ParseNode("logical_or");
1767 conditional_expression ::=
1768 conditional_or_expression:condor {:
1770 // | conditional_or_expression QUESTION expression
1771 // COLON conditional_expression
1773 assignment_expression ::=
1774 conditional_expression:expr {:
1776 assignment:assign {:
1779 // semantic check necessary here to ensure a valid left-hand side.
1780 // allowing a parenthesized variable here on the lhs was introduced in
1781 // JLS 2; thanks to Eric Blake for pointing this out.
1782 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
1783 ParseNode pn=new ParseNode("assignment");
1784 pn.addChild("op").addChild(op);
1785 ParseNode pnargs=pn.addChild("args");
1786 pnargs.addChild(lvalue);
1787 pnargs.addChild(rvalue);
1791 assignment_operator ::=
1792 EQ {: RESULT=new ParseNode("eq"); :}
1793 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
1794 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
1795 | MODEQ {: RESULT=new ParseNode("modeq"); :}
1796 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
1797 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
1798 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
1799 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
1800 // | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
1801 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
1802 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
1803 | OREQ {: RESULT=new ParseNode("oreq"); :}
1806 {: RESULT=new ParseNode("empty"); :}
1810 expression ::= assignment_expression:exp {:
1813 //constant_expression ::=