first step to reduce the size of grammar as we have an issue of Java Bytecode 64K...
[IRC.git] / Robust / src / Parse / java14.cup
1 package Parse;
2
3 import java_cup.runtime.*;
4 import Lex.Lexer;
5 import IR.Tree.*;
6
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.
11  */
12
13 /*
14 JDK 1.4 Features added:
15   assertion statement.
16   statement_without_trailing_substatement ::= ...
17      |          assert_statement ;
18   assert_statement ::=
19                 ASSERT expression SEMICOLON
20         |       ASSERT expression COLON expression SEMICOLON
21         ;
22 */
23 parser code  {: 
24   Lexer lexer;
25
26   public Parser(Lexer l) {
27     this();
28     lexer=l;
29   }
30
31   public void syntax_error(java_cup.runtime.Symbol current) {
32     report_error("Syntax error (" + current.sym + ")", current);
33   }
34   public void report_error(String message, java_cup.runtime.Symbol info) {
35     lexer.errorMsg(message, info);
36   }
37   public int n(){
38          return lexer.line_num;
39   }
40 :};
41
42 scan with {: return lexer.nextToken(); :};
43
44 terminal BOOLEAN; // primitive_type
45 terminal BYTE, SHORT, INT, LONG, CHAR; // integral_type
46 terminal FLOAT, DOUBLE; // floating_point_type
47 terminal LBRACK, RBRACK; // array_type
48 terminal java.lang.String IDENTIFIER; // name
49 terminal DOT; // qualified_name
50 terminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;
51 terminal PACKAGE; // package_declaration
52 terminal IMPORT; // import_declaration
53 terminal PUBLIC, PROTECTED, PRIVATE; // modifier
54 terminal STATIC; // modifier
55 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
56 terminal CLASS; // class_declaration
57 terminal EXTENDS; // super
58 terminal IMPLEMENTS; // interfaces
59 terminal VOID; // method_header
60 terminal THROWS; // throws
61 terminal THIS, SUPER; // explicit_constructor_invocation
62 terminal INTERFACE; // interface_declaration
63 terminal IF, ELSE; // if_then_statement, if_then_else_statement
64 terminal SWITCH; // switch_statement
65 terminal CASE, DEFAULT; // switch_label
66 terminal DO, WHILE; // while_statement, do_statement
67 terminal FOR; // for_statement
68 terminal BREAK; // break_statement
69 terminal CONTINUE; // continue_statement
70 terminal RETURN; // return_statement
71 terminal THROW; // throw_statement
72 terminal TRY; // try_statement
73 terminal CATCH; // catch_clause
74 terminal FINALLY; // finally
75 terminal NEW; // class_instance_creation_expression
76 terminal NEWFLAG; // class_instance_creation_expression
77 terminal PLUSPLUS; // postincrement_expression
78 terminal MINUSMINUS; // postdecrement_expression
79 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
80 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
81 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
82 terminal EQEQ, NOTEQ; // equality_expression
83 terminal AND; // and_expression
84 terminal XOR; // exclusive_or_expression
85 terminal OR;  // inclusive_or_expression
86 terminal ANDAND; // conditional_and_expression
87 terminal OROR; // conditional_or_expression
88 terminal QUESTION; // conditional_expression
89 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
90 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
91 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
92 terminal AT;           // support annotations
93 terminal LOCDEF;          // declaration of location hierarchy
94
95 terminal java.lang.Number INTEGER_LITERAL;
96 terminal java.lang.Number FLOATING_POINT_LITERAL;
97 terminal java.lang.Boolean BOOLEAN_LITERAL;
98 terminal java.lang.Character CHARACTER_LITERAL;
99 terminal java.lang.String STRING_LITERAL;
100 terminal NULL_LITERAL;
101
102 // Reserved but unused:
103 terminal CONST, GOTO;
104 // strictfp keyword, new in Java 1.2
105 terminal STRICTFP;
106 // assert keyword, new in Java 1.4
107 terminal ASSERT; // assert_statement
108 // lexer compatibility with Java 1.5
109 terminal ELLIPSIS;
110 terminal ENUM;
111
112 // added for disjoint reachability analysis
113 terminal GENREACH;
114
115
116 // 19.2) The Syntactic Grammar
117 non terminal ParseNode goal;
118 // 19.3) Lexical Structure
119 non terminal ParseNode literal;
120 // 19.4) Types, Values, and Variables
121 non terminal ParseNode type, primitive_type, numeric_type;
122 non terminal ParseNode integral_type, floating_point_type;
123 non terminal ParseNode reference_type;
124 non terminal ParseNode class_or_interface_type;
125 non terminal ParseNode class_type;
126 non terminal ParseNode interface_type;
127 non terminal ParseNode array_type;
128 // 19.5) Names
129 non terminal ParseNode name, simple_name, qualified_name;
130 // 19.6) Packages
131 non terminal ParseNode compilation_unit;
132 non terminal ParseNode package_declaration_opt, package_declaration;
133 non terminal ParseNode import_declarations_opt, import_declarations;
134 non terminal ParseNode type_declarations_opt, type_declarations;
135 non terminal ParseNode import_declaration;
136 non terminal ParseNode single_type_import_declaration;
137 non terminal ParseNode type_import_on_demand_declaration;
138 non terminal ParseNode type_declaration;
139 // 19.7) Productions used only in the LALR(1) grammar
140 non terminal ParseNode modifiers_opt, modifiers, modifiers_at, modifier;
141 non terminal ParseNode mixed_modifiers, mixed_modifiers_at;
142 // 19.8.1) Class Declaration
143 non terminal ParseNode class_declaration, super, super_opt;
144 non terminal ParseNode interfaces, interfaces_opt, interface_type_list;
145 non terminal ParseNode class_body;
146 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
147 non terminal ParseNode class_body_declaration, class_member_declaration;
148 // 19.8.2) Field Declarations
149 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
150 non terminal ParseNode variable_declarator_id;
151 non terminal ParseNode variable_initializer;
152 // 19.8.3) Method Declarations
153 non terminal ParseNode method_declaration, method_header, method_declarator;
154 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
155 non terminal ParseNode formal_parameter;
156 non terminal ParseNode throws_opt;
157 non terminal ParseNode throws;
158 non terminal ParseNode class_type_list;
159 non terminal ParseNode method_body;
160 // 19.8.4) Static Initializers
161 non terminal ParseNode static_initializer;
162 // 19.8.5) Constructor Declarations
163 non terminal ParseNode constructor_declaration, constructor_declarator;
164 non terminal ParseNode constructor_body;
165 non terminal ParseNode explicit_constructor_invocation;
166 // 19.8.6) Location Hierarchy Declarations
167 non terminal ParseNode location_order_declaration, location_order_list, location_order;
168 // 19.9.1) Interface Declarations
169 non terminal ParseNode interface_declaration;
170 non terminal normal_interface_declaration, annotation_type_declaration;
171 non terminal ParseNode extends_interfaces_opt, extends_interfaces;
172 non terminal ParseNode interface_body;
173 non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
174 non terminal ParseNode interface_member_declaration, constant_declaration;
175 non terminal ParseNode abstract_method_declaration;
176 // 19.10) Arrays
177 non terminal ParseNode array_initializer;
178 non terminal ParseNode variable_initializers;
179 // 19.11) Blocks and Statements
180 non terminal ParseNode block;
181 non terminal ParseNode block_statements_opt, block_statements, block_statement;
182 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
183 non terminal ParseNode statement, statement_no_short_if;
184 non terminal ParseNode statement_without_trailing_substatement;
185 non terminal ParseNode empty_statement;
186 non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
187 non terminal ParseNode expression_statement, statement_expression;
188 non terminal ParseNode if_then_statement;
189 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
190 non terminal ParseNode switch_statement, switch_block;
191 non terminal ParseNode switch_block_statement_groups;
192 non terminal ParseNode switch_block_statement_group;
193 non terminal ParseNode switch_labels, switch_label;
194 non terminal ParseNode while_statement, while_statement_no_short_if;
195 non terminal ParseNode do_statement;
196 non terminal ParseNode for_statement, for_statement_no_short_if;
197 non terminal ParseNode for_init_opt, for_init;
198 non terminal ParseNode for_update_opt, for_update;
199 non terminal ParseNode statement_expression_list;
200 non terminal ParseNode identifier_opt;
201 non terminal ParseNode break_statement, continue_statement;
202 non terminal ParseNode return_statement;
203 non terminal ParseNode throw_statement;
204 non terminal ParseNode synchronized_statement;
205 non terminal ParseNode try_statement;
206 non terminal ParseNode catches_opt;
207 non terminal ParseNode catches, catch_clause;
208 non terminal ParseNode finally;
209 //non terminal ParseNode assert_statement;
210 non terminal ParseNode genreach_statement;
211 // 19.12) Expressions
212 non terminal ParseNode primary, primary_no_new_array;
213 non terminal ParseNode class_instance_creation_expression;
214 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
215 non terminal ParseNode argument_list_opt, argument_list;
216 non terminal ParseNode array_creation_init;
217 non terminal ParseNode array_creation_uninit;
218 non terminal ParseNode dim_exprs, dim_expr;
219 non terminal Integer dims_opt, dims;
220 non terminal ParseNode field_access, method_invocation;
221 non terminal ParseNode array_access;
222 non terminal ParseNode postfix_expression;
223 non terminal ParseNode postincrement_expression, postdecrement_expression;
224 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
225 non terminal ParseNode preincrement_expression, predecrement_expression;
226 non terminal ParseNode cast_expression;
227 non terminal ParseNode multiplicative_expression, additive_expression;
228 non terminal ParseNode shift_expression, relational_expression, equality_expression;
229 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
230 non terminal ParseNode conditional_and_expression, conditional_or_expression;
231 non terminal ParseNode conditional_expression;
232 non terminal ParseNode assignment_expression;
233 non terminal ParseNode assignment;
234 non terminal ParseNode assignment_operator;
235 non terminal ParseNode expression_opt, expression;
236 non terminal ParseNode constant_expression;
237 //failure aware computation keywords
238 terminal FLAG;
239 terminal OPTIONAL;
240 terminal ISAVAILABLE;
241 terminal EXTERNAL;
242 terminal TAG;
243 terminal TASK;
244 terminal TASKEXIT;
245 non terminal ParseNode flag_declaration;
246 non terminal ParseNode task_declaration;
247 non terminal ParseNode task_parameter_list;
248 non terminal ParseNode task_parameter;
249 non terminal ParseNode flag_expression;
250 non terminal ParseNode flag_andexpression;
251 non terminal ParseNode flag_notexpression;
252 non terminal ParseNode task_exitstatement;
253 non terminal ParseNode flag_effects_opt;
254 non terminal ParseNode flag_effects;
255 non terminal ParseNode flag_effect;
256 non terminal ParseNode flag_list;
257 non terminal ParseNode flag_list_opt;
258 non terminal ParseNode flag_change;
259
260 non terminal ParseNode cons_checks_opt;
261 non terminal ParseNode cons_checks;
262 non terminal ParseNode cons_check;
263
264 non terminal ParseNode tag_variable_declaration_statement;
265 non terminal ParseNode tag_expression_list;
266 non terminal ParseNode tag_expression;
267 non terminal ParseNode tag_list;
268 non terminal ParseNode tag_list_opt;
269 non terminal ParseNode tag_change;
270
271 //distributed transaction keywords
272 terminal ATOMIC;
273 terminal GLOBAL;
274 terminal SCRATCH;
275 terminal GETOFFSET;
276 non terminal ParseNode atomic_statement;
277 non terminal ParseNode getoffset_expression;
278
279 //disjointness for Java
280 terminal DISJOINT;
281
282 //coarse-grain parallelization
283 terminal SESE;
284 terminal RBLOCK;
285 non terminal ParseNode sese_statement;
286
287 // mgc
288 // JSR-201) Enum Declaration
289 non terminal ParseNode enum_declaration;
290 non terminal ParseNode enum_body, enum_constants_opt, enum_constants, enum_constant;
291 //non terminal ParseNode enum_arguments_opt, enum_body_declarations_opt;
292
293 // annotation expressions
294 non terminal ParseNode annotations_opt, annotations, annotations_at, annotation, annotation_body;
295 non terminal ParseNode normal_annotation_body, marker_annotation_body;
296 non terminal ParseNode single_element_annotation_body;
297 non terminal ParseNode annotation_type_body, annotation_type_element_declarations;
298 non terminal ParseNode annotation_type_element_declarations_opt;
299 non terminal ParseNode annotation_type_element_declaration, default_value_opt, default_value;
300 non terminal ParseNode element_value_pairs_opt, element_value_pairs, element_value_pair;
301 non terminal ParseNode element_values_opt, element_values, element_value, element_value_array_initializer;
302
303 start with goal;
304
305
306 // Task declarations
307 task_declaration ::= 
308         TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN 
309         flag_effects_opt:feo
310         method_body:body 
311         {: 
312         ParseNode pn=new ParseNode("task_declaration",parser.n());
313         pn.addChild("name").addChild(id);
314         pn.addChild(tpl);
315         pn.addChild(feo);
316         pn.addChild("body").addChild(body);     
317         RESULT=pn;
318         :};
319
320 task_parameter_list ::=
321                 task_parameter:fp {: 
322                 ParseNode pn=new ParseNode("task_parameter_list",parser.n());
323                 pn.addChild(fp);
324                 RESULT=pn;
325         :}
326         |       task_parameter_list:fpl COMMA task_parameter:fp {: 
327                 fpl.addChild(fp);
328                 RESULT=fpl;
329         :}
330         ;
331
332 task_parameter ::=
333                 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
334                 ParseNode pn=new ParseNode("task_parameter",parser.n());
335                 pn.addChild(type);
336                 pn.addChild(name);
337                 pn.addChild("flag").addChild(exp);
338                 RESULT=pn;
339         :} 
340         | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
341                 ParseNode pn=new ParseNode("task_parameter",parser.n());
342                 pn.addChild(type);
343                 pn.addChild(name);
344                 pn.addChild("flag").addChild(exp);
345                 pn.addChild("tag").addChild(texp);
346                 RESULT=pn;
347         :}
348         | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
349                 ParseNode pn=new ParseNode("task_parameter",parser.n());
350                 pn.addChild(type);
351                 pn.addChild(name);
352                 pn.addChild("tag").addChild(texp);
353                 RESULT=pn;
354         :}
355         | OPTIONAL task_parameter:fp {:
356                 ParseNode pn=new ParseNode("task_parameter",parser.n());
357                 pn.addChild("optional").addChild(fp);
358                 RESULT=pn;
359         :}              
360         
361         ;
362
363 tag_expression_list ::= tag_expression:te {: 
364         ParseNode pn=new ParseNode("tag_expression_list",parser.n());
365         pn.addChild(te);
366         RESULT=pn;
367         :}
368         | tag_expression_list:tel COMMA tag_expression:te {: 
369         tel.addChild(te);
370         RESULT=tel;
371         :}
372         ;
373
374 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {: 
375                 ParseNode pn=new ParseNode("tag_expression",parser.n());
376                 pn.addChild("type").addChild(type);
377                 pn.addChild("single").addChild(id);
378                 RESULT=pn;
379         :}
380         ;
381
382 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
383         | LBRACE RBRACE {: RESULT = new ParseNode("empty",parser.n()); :}       
384         | {: RESULT = new ParseNode("empty",parser.n()); :}
385         ;
386
387 tag_list ::= tag_change:fc {: 
388                 ParseNode pn=new ParseNode("tag_list",parser.n());
389                 pn.addChild(fc);
390                 RESULT=pn;
391         :}
392         | tag_list:fl COMMA tag_change:fc {: 
393                 fl.addChild(fc);
394                 RESULT=fl;
395         :};
396
397 tag_change ::= IDENTIFIER:id {: 
398                 RESULT=new ParseNode("name",parser.n()).addChild(id).getRoot();
399         :}
400         | NOT IDENTIFIER:id {: 
401                 RESULT=new ParseNode("not",parser.n()).addChild("name").addChild(id).getRoot();
402         :};
403
404 flag_expression ::= 
405         flag_andexpression:exp {: 
406                 RESULT=exp;
407         :}
408         | flag_expression:exp1 OROR flag_andexpression:exp2 {: 
409                 ParseNode pn=new ParseNode("or",parser.n());
410                 pn.addChild(exp1);
411                 pn.addChild(exp2);
412                 RESULT=pn;
413         :}
414         ;
415
416 flag_andexpression ::= 
417         flag_notexpression:exp {: RESULT=exp; :}
418         | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {: 
419                 ParseNode pn=new ParseNode("and",parser.n());
420                 pn.addChild(exp1);
421                 pn.addChild(exp2);
422                 RESULT=pn;
423         :}
424         ;
425
426 flag_notexpression ::=
427         NOT flag_notexpression:exp {: 
428                 ParseNode pn=new ParseNode("not",parser.n());
429                 pn.addChild(exp);
430                 RESULT=pn;
431         :}
432         | LPAREN flag_expression:exp RPAREN {: 
433                 RESULT=exp;
434         :}
435         | IDENTIFIER:id {:
436                 ParseNode pn=new ParseNode("name",parser.n());
437                 pn.addChild(id);
438                 RESULT=pn;
439         :}
440         ;
441
442 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {: 
443                 RESULT=(new ParseNode("taskexit",parser.n())).addChild(opt).getRoot().addChild(cco).getRoot();
444         :};
445
446 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
447         | {: RESULT = new ParseNode("empty",parser.n()); :}
448         ;
449
450 cons_checks ::= cons_check:cc {: 
451                 ParseNode pn=new ParseNode("cons_checks",parser.n());
452                 pn.addChild(cc);
453                 RESULT=pn;
454         :}
455         |       cons_checks:ccs COMMA cons_check:cc {: 
456                 ccs.addChild(cc);
457                 RESULT=ccs;
458         :};
459
460 cons_check ::=  IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {: 
461                 ParseNode pn=new ParseNode("cons_check",parser.n());
462                 pn.addChild("name").addChild("identifier").addChild(name);
463                 pn.addChild(args);
464                 RESULT=pn;
465         :};
466
467 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
468         | {: RESULT = new ParseNode("empty",parser.n()); :}
469         ;
470
471 flag_effects ::= flag_effect:fe {: 
472                 ParseNode pn=new ParseNode("flag_effects_list",parser.n());
473                 pn.addChild(fe);
474                 RESULT=pn;
475         :}
476         |       flag_effects:fes COMMA flag_effect:fe {: 
477                 fes.addChild(fe);
478                 RESULT=fes;
479         :};
480
481 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {: 
482                 ParseNode pn=new ParseNode("flag_effect",parser.n());
483                 pn.addChild("name").addChild(id);
484                 pn.addChild(fl);
485                 pn.addChild(tlo);
486                 RESULT=pn;
487         :}
488         | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {: 
489                 ParseNode pn=new ParseNode("flag_effect",parser.n());
490                 pn.addChild("name").addChild(id);
491                 pn.addChild(tl);
492                 RESULT=pn;
493         :};
494
495 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
496         | LBRACE RBRACE {: RESULT = new ParseNode("empty",parser.n()); :}       
497         | 
498         {: RESULT = new ParseNode("empty",parser.n()); :}
499         ;
500
501 flag_list ::= flag_change:fc {: 
502                 ParseNode pn=new ParseNode("flag_list",parser.n());
503                 pn.addChild(fc);
504                 RESULT=pn;
505         :}
506         |       flag_list:fl COMMA flag_change:fc {: 
507                 fl.addChild(fc);
508                 RESULT=fl;
509         :};
510
511 flag_change ::= IDENTIFIER:id {: 
512                 RESULT=new ParseNode("name",parser.n()).addChild(id).getRoot();
513         :} |
514         NOT IDENTIFIER:id {: 
515                 RESULT=new ParseNode("not",parser.n()).addChild("name").addChild(id).getRoot();
516         :};
517
518 // 19.2) The Syntactic Grammar
519 goal ::=        compilation_unit:cu
520         {:
521         RESULT = cu;
522         :}
523         ;
524
525 // 19.3) Lexical Structure.
526
527
528 literal ::=     INTEGER_LITERAL:integer_lit
529         {:
530                 ParseNode pn=new ParseNode("literal",parser.n());
531                 pn.addChild("integer").setLiteral(integer_lit);
532                 RESULT=pn;
533         :}
534         |       FLOATING_POINT_LITERAL:float_lit
535         {:
536                 ParseNode pn=new ParseNode("literal",parser.n());
537                 pn.addChild("float").setLiteral(float_lit);
538                 RESULT=pn;
539         :}
540         |       BOOLEAN_LITERAL:boolean_lit
541         {:
542                 ParseNode pn=new ParseNode("literal",parser.n());
543                 pn.addChild("boolean").setLiteral(boolean_lit);
544                 RESULT=pn;
545         :}
546         |       CHARACTER_LITERAL:char_lit
547         {:
548                 ParseNode pn=new ParseNode("literal",parser.n());
549                 pn.addChild("char").setLiteral(char_lit);
550                 RESULT=pn;
551         :}
552         |       STRING_LITERAL:string_lit
553         {:
554                 ParseNode pn=new ParseNode("literal",parser.n());
555                 pn.addChild("string").setLiteral(string_lit);
556                 RESULT=pn;
557         :}
558         |       NULL_LITERAL 
559         {:
560                 RESULT=(new ParseNode("literal",parser.n())).addChild("null").getRoot();
561         :}
562         ;
563
564 // 19.4) Types, Values, and Variables
565 type    ::=     primitive_type:type {: RESULT=type; :}
566         |       reference_type:type {: RESULT=type; :}
567         ;
568
569 primitive_type ::=
570                 numeric_type:type {: RESULT=type; :}
571         |       BOOLEAN {: RESULT=(new ParseNode("type",parser.n())).addChild("boolean").getRoot(); :}
572         ;
573 numeric_type::= integral_type:type {: RESULT=type; :}
574         |       floating_point_type:type {: RESULT=type; :}
575         ;
576 integral_type ::= 
577                 BYTE {: RESULT=(new ParseNode("type",parser.n())).addChild("byte").getRoot(); :}
578         |       SHORT  {: RESULT=(new ParseNode("type",parser.n())).addChild("short").getRoot(); :}
579         |       INT  {: RESULT=(new ParseNode("type",parser.n())).addChild("int").getRoot(); :}
580         |       LONG  {: RESULT=(new ParseNode("type",parser.n())).addChild("long").getRoot(); :}
581         |       CHAR  {: RESULT=(new ParseNode("type",parser.n())).addChild("char").getRoot(); :}
582         ;
583 floating_point_type ::= 
584                 FLOAT  {: RESULT=(new ParseNode("type",parser.n())).addChild("float").getRoot(); :}
585         |       DOUBLE  {: RESULT=(new ParseNode("type",parser.n())).addChild("double").getRoot(); :}
586         ;
587
588 reference_type ::=
589                 class_or_interface_type:type {: RESULT=type; :}
590         |       array_type:type {: RESULT=type; :}
591         ;
592 class_or_interface_type ::= name:name {: 
593         RESULT=(new ParseNode("type",parser.n())).addChild("class").addChild(name).getRoot(); 
594         :};
595
596 class_type ::=  class_or_interface_type:type {: RESULT=type; :};
597 interface_type ::= class_or_interface_type:type {: RESULT=type; :};
598
599 array_type ::=  primitive_type:prim dims:dims {: 
600                 ParseNode pn=(new ParseNode("type",parser.n())).addChild("array");
601                 pn.addChild("basetype").addChild(prim);
602                 pn.addChild("dims").setLiteral(dims);
603                 RESULT=pn.getRoot();
604         :}
605         |       name:name dims:dims {: 
606                 ParseNode pn=(new ParseNode("type",parser.n())).addChild("array");
607                 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
608                 pn.addChild("dims").setLiteral(dims);
609                 RESULT=pn.getRoot();
610         :}
611         ;
612
613 // 19.5) Names
614 name    ::=     simple_name:name {: RESULT=name; :}
615         |       qualified_name:name {: RESULT=name; :}
616         ;
617 simple_name ::= IDENTIFIER:id {: 
618         RESULT=(new ParseNode("name",parser.n())).addChild("identifier").addChild(id).getRoot(); 
619         :}
620         ;
621 qualified_name ::= name:name DOT IDENTIFIER:id {: 
622         ParseNode pn=new ParseNode("name",parser.n());
623         pn.addChild("base").addChild(name);
624         pn.addChild("identifier").addChild(id);
625         RESULT=pn;
626         :}
627         ;
628
629 // 19.6) Packages
630 compilation_unit ::=
631                 package_declaration_opt:pdo
632                 import_declarations_opt:ido
633                 type_declarations_opt:tdo {: 
634                 ParseNode pn=new ParseNode("compilation_unit",parser.n());
635                 pn.addChild(tdo);
636                 pn.addChild("packages").addChild(pdo);
637                 pn.addChild("imports").addChild(ido);
638                 RESULT=pn;
639                 :}
640                 ;
641 package_declaration_opt ::= package_declaration:pdo {:
642                 RESULT=pdo;
643         :} |
644         {: RESULT=new ParseNode("empty",parser.n()); :}
645 ;
646
647 import_declarations_opt ::= import_declarations:ido {: 
648                 RESULT=ido;
649         :} | 
650         {: RESULT=new ParseNode("empty",parser.n()); :}
651 ;
652 type_declarations_opt   ::= type_declarations:tds {:
653                 RESULT=tds;
654                 :}   | 
655         {: RESULT=new ParseNode("empty",parser.n()); :}
656         ;
657
658 import_declarations ::=
659                import_declaration:id {: 
660                 ParseNode pn=new ParseNode("import_decls_list",parser.n());
661                 pn.addChild(id);
662                 RESULT=pn;
663         :}
664        |       import_declarations:ids import_declaration:id {: 
665                 ids.addChild(id);
666                 RESULT=ids;
667         :}
668        ;
669
670 type_declarations ::= 
671                 type_declaration:td {:
672                 ParseNode pn=new ParseNode("type_declaration_list",parser.n());
673                 pn.addChild(td);
674                 RESULT=pn;
675                 :}
676         |       type_declarations:tds type_declaration:td {:
677                 tds.addChild(td);
678                 RESULT=tds;
679                 :}
680         ;
681
682 package_declaration ::=
683                 PACKAGE name:name SEMICOLON {: 
684         ParseNode pn=new ParseNode("package",parser.n());
685         pn.addChild(name);
686         RESULT=pn;
687         :}
688        ;
689 import_declaration ::=
690                single_type_import_declaration:sid {: RESULT=sid; :}
691        |       type_import_on_demand_declaration:iod {: RESULT=iod; :}
692        ;
693 single_type_import_declaration ::=
694                IMPORT name:name SEMICOLON {: 
695         ParseNode pn=new ParseNode("import_single",parser.n());
696         pn.addChild(name);
697         RESULT=pn;
698 :}
699        ;
700 type_import_on_demand_declaration ::=
701                IMPORT name:name DOT MULT SEMICOLON {:
702         ParseNode pn=new ParseNode("import_ondemand",parser.n());
703         pn.addChild(name);
704         RESULT=pn;
705         :}       
706         ;
707
708 type_declaration ::=
709                 class_declaration:cd 
710                 {:
711                         RESULT=cd;
712                 :}
713         |       enum_declaration:ed
714             {:
715                 RESULT=ed;
716             :}
717         |       task_declaration:td 
718                 {:
719                         RESULT=td;
720                 :}
721     |   interface_declaration:in
722         {:
723                         RESULT=in;
724                 :}
725         |       SEMICOLON {: RESULT=new ParseNode("empty",parser.n()); :}
726         ;
727
728 // 19.7) Productions used only in the LALR(1) grammar
729 modifiers_opt::=
730         {: RESULT=new ParseNode("empty",parser.n()); :}
731         |       modifiers:mo {: 
732                 RESULT=mo;
733         :}
734         ;
735 modifiers_at ::=
736                 mixed_modifiers_at
737         |       annotations_at
738         ;
739 modifiers ::=   mixed_modifiers : mmo {:
740                 RESULT=mmo; 
741         :}
742         |       annotations : an {:
743                 ParseNode pn=new ParseNode("modifier_list",parser.n());
744                 pn.addChild(an);
745                 RESULT=pn;
746         :}
747         ;
748 mixed_modifiers_at ::=
749                 mixed_modifiers : mmos AT {:
750                 RESULT=mmos;
751         :}
752         ;
753 mixed_modifiers ::=
754                 modifier : mo {:
755                 ParseNode pn=new ParseNode("modifier_list",parser.n());
756                 pn.addChild(mo);
757                 RESULT=pn;
758         :}
759         |       annotations:as modifier:mo {:
760                 ParseNode pn=new ParseNode("modifier_list",parser.n());
761                 pn.addChild(mo);
762                 pn.addChild(as);
763                 RESULT=pn;
764         :}
765         |       mixed_modifiers : mmos modifier : mo {:
766                 mmos.addChild(mo);
767                 RESULT=mmos;
768         :}
769         |       mixed_modifiers_at:mma annotation_body:ab {:
770                 mma.addChild("annotation_list",parser.n()).addChild(ab); 
771                 RESULT=mma;             
772         :}
773         ;
774 modifier ::=    
775         PUBLIC {: RESULT=new ParseNode("public",parser.n()); :}|
776         PROTECTED {: RESULT=new ParseNode("protected",parser.n()); :}|
777         PRIVATE {: RESULT=new ParseNode("private",parser.n()); :}|
778         STATIC {: RESULT=new ParseNode("static",parser.n()); :} |
779         ABSTRACT {: RESULT=new ParseNode("abstract",parser.n()); :}  |
780         FINAL {: RESULT=new ParseNode("final",parser.n()); :}|
781         NATIVE {: RESULT=new ParseNode("native",parser.n()); :} |
782         SYNCHRONIZED {: RESULT=new ParseNode("synchronized",parser.n()); :} |
783         ATOMIC {: RESULT=new ParseNode("atomic",parser.n()); :} |
784         VOLATILE {: RESULT=new ParseNode("volatile",parser.n()); :} |
785         TRANSIENT {: RESULT=new ParseNode("transient",parser.n()); :} 
786
787 //      STRICTFP // note that semantic analysis must check that the
788                          // context of the modifier allows strictfp.
789         ;
790 //annotations_opt ::=
791 //      {: RESULT=new ParseNode("empty",parser.n()); :}
792 //      |       annotations:an {: 
793 //              RESULT=an;
794 //      :}
795 //      ;
796 annotations ::= 
797                 AT annotation_body:ab {:
798                 ParseNode pn=new ParseNode("annotation_list",parser.n());
799                 pn.addChild(ab);
800                 RESULT=pn;
801         :}
802         |       annotations_at:aat annotation_body:ab {:
803                 aat.addChild(ab);
804                 RESULT=aat;
805         :}
806         ;
807 annotations_at ::=
808                annotations:as AT {:
809                RESULT=as;
810         :}
811         ;
812 annotation ::=
813                AT annotation_body:ab {:
814                RESULT=ab;
815         :}
816         ;
817 annotation_body ::=
818                 normal_annotation_body:nab {:
819                 ParseNode pn=new ParseNode("annotation_body",parser.n());
820                 pn.addChild(nab);
821                 RESULT = pn;
822         :}
823         |       marker_annotation_body:mab {:
824                 ParseNode pn=new ParseNode("annotation_body",parser.n());
825                 pn.addChild(mab);
826                 RESULT = pn;
827         :}
828         |       single_element_annotation_body:seab {:
829                 ParseNode pn=new ParseNode("annotation_body",parser.n());
830                 pn.addChild(seab);
831                 RESULT = pn;
832         :}
833         ;
834 normal_annotation_body ::=
835                 IDENTIFIER LPAREN element_value_pairs_opt RPAREN
836         ;
837 marker_annotation_body ::=
838                 IDENTIFIER:id
839         {:
840         ParseNode pn=new ParseNode("marker_annotation",parser.n());
841         pn.addChild("name").addChild(id);
842         RESULT=pn;
843         :}
844         ;
845 single_element_annotation_body ::=
846                 IDENTIFIER:id LPAREN STRING_LITERAL:ev RPAREN {:
847                 ParseNode pn=new ParseNode("single_annotation",parser.n());
848                 pn.addChild("name").addChild(id);
849                 pn.addChild("element_value").addChild(ev);
850                 RESULT=pn;
851         :}
852         ;
853 element_value_pairs_opt ::=
854         |       element_value_pairs
855         ;               
856 element_value_pairs ::=
857                 element_value_pair
858         |       element_value_pairs COMMA element_value_pair
859         ;
860 element_value_pair ::=
861                 IDENTIFIER EQ element_value
862         ;
863 element_value ::=
864                 annotation:an {:
865                 RESULT=an;
866         :}  
867         |       element_value_array_initializer:evai {: 
868                 RESULT=evai;
869         :}
870         |       conditional_expression:ce {:
871                 RESULT=ce;
872         :}
873         ;
874 element_value_array_initializer ::=
875                 LBRACE element_values_opt RBRACE
876         ;
877 element_values_opt ::=
878         |       element_values
879         ;
880 element_values ::=
881                 element_value
882         |       element_values COMMA element_value
883         ;
884 // 19.8) Classes
885
886 // 19.8.1) Class Declaration:
887 class_declaration ::= 
888         modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo 
889         class_body:body 
890         {:
891         ParseNode pn=new ParseNode("class_declaration",parser.n());
892         pn.addChild("modifiers").addChild(mo);
893         pn.addChild("name").addChild(id);
894         pn.addChild("super").addChild(so);
895         pn.addChild("superIF").addChild(ifo);
896         pn.addChild("classbody").addChild(body);
897         RESULT=pn;
898         :}
899         ;
900 super ::=       EXTENDS class_type:classtype {: 
901                 RESULT=classtype;
902         :}
903         ;
904 super_opt ::=   
905         {: RESULT=new ParseNode("empty",parser.n()); :}
906         |       super:su {: 
907                 RESULT=su;
908         :}
909         ;
910
911 interfaces ::= IMPLEMENTS interface_type_list:iftl {: RESULT=iftl; :}
912        ;
913 interfaces_opt ::=
914        {: RESULT=new ParseNode("empty",parser.n()); :}
915        |       interfaces:ifs {: RESULT=ifs; :}
916        ;
917 interface_type_list ::=
918                interface_type:ift {: 
919                         ParseNode pn=new ParseNode("interface_type_list",parser.n());
920                         pn.addChild(ift);
921                         RESULT=pn;
922                 :}
923        |       interface_type_list:iftl COMMA interface_type:ift {: 
924                         iftl.addChild(ift);
925                         RESULT=iftl;
926                 :}
927        ;
928
929 class_body ::=  LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
930         ;
931
932 class_body_declarations_opt ::= 
933         {: RESULT=new ParseNode("empty",parser.n()); :}
934         |       class_body_declarations:cbd {: RESULT=cbd; :};
935
936 class_body_declarations ::= 
937                 class_body_declaration:cbd {: 
938                         ParseNode pn=new ParseNode("class_body_declaration_list",parser.n());
939                         pn.addChild(cbd);
940                         RESULT=pn;
941                 :}
942         |       class_body_declarations:cbds class_body_declaration:cbd {: 
943                         cbds.addChild(cbd);
944                         RESULT=cbds;
945                 :}
946         ;
947
948 class_body_declaration ::=
949                 class_member_declaration:member {: 
950                 RESULT=(new ParseNode("member",parser.n())).addChild(member).getRoot();
951         :}
952         |       static_initializer:block{:
953                 RESULT=(new ParseNode("static_block",parser.n())).addChild(block).getRoot();
954         :}
955         |       constructor_declaration:constructor {: 
956                 RESULT=(new ParseNode("constructor",parser.n())).addChild(constructor).getRoot();
957         :}
958         |       block:block {:
959                 RESULT=(new ParseNode("block",parser.n())).addChild(block).getRoot();
960         :}
961         |       location_order_declaration:lod {:
962                 RESULT=(new ParseNode("location_order_declaration",parser.n())).addChild(lod).getRoot();
963         :}
964         ;
965 class_member_declaration ::=
966         //failure aware computation
967         flag_declaration:flag {: 
968         RESULT=(new ParseNode("flag",parser.n())).addChild(flag).getRoot(); 
969         :}      
970         |
971         field_declaration:field {: 
972         RESULT=(new ParseNode("field",parser.n())).addChild(field).getRoot(); 
973         :}
974         |       method_declaration:method {:
975         RESULT=(new ParseNode("method",parser.n())).addChild(method).getRoot(); 
976         :}
977         /* repeat the prod for 'class_declaration' here: */
978         |       modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo class_body:body
979         {:
980         ParseNode pn=new ParseNode("inner_class_declaration",parser.n());
981         pn.addChild("modifiers").addChild(mo);
982         pn.addChild("name").addChild(id);
983         pn.addChild("super").addChild(so);
984         pn.addChild("superIF").addChild(ifo);
985         pn.addChild("classbody").addChild(body);
986         RESULT=pn;
987         :}
988         |       enum_declaration:ed
989         {:
990         RESULT=ed; 
991         :}
992 //    |       interface_declaration:interfaced {: 
993 //      RESULT=(new ParseNode("interface",parser.n())).addChild(interfaced).getRoot(); 
994 //      :}
995         |       SEMICOLON       {: RESULT=new ParseNode("empty",parser.n()); :}
996         ;
997         
998 // mgc
999 // JSR-201) Enum Declaration
1000 enum_declaration ::=
1001                 modifiers_opt:mo ENUM IDENTIFIER:id /*interfaces_opt:io*/ enum_body:body
1002                 {:
1003                         ParseNode pn=new ParseNode("enum_declaration",parser.n());
1004                         pn.addChild("modifiers").addChild(mo);
1005                         pn.addChild("name").addChild(id);
1006                         //pn.addChild("superIF").addChild(ifo);
1007                         pn.addChild("enumbody").addChild(body);
1008                         RESULT=pn;
1009                 :}
1010         ;
1011 enum_body ::=
1012                 LBRACE enum_constants_opt:eco /*enum_body_declarations_opt:ebdo*/ RBRACE
1013                 {: RESULT=eco; :}
1014         ;
1015 enum_constants_opt ::=
1016   {: RESULT=new ParseNode("empty",parser.n()); :}
1017         |       enum_constants:ecs
1018         {: RESULT=ecs; :}
1019         ;
1020 enum_constants ::=
1021                 enum_constant:ec {: 
1022                 ParseNode pn=new ParseNode("enum_constants_list",parser.n());
1023                 pn.addChild(ec);
1024                 RESULT=pn;
1025         :}
1026         |       enum_constants:ecs COMMA enum_constant:ec {:
1027             ecs.addChild(ec);
1028             RESULT=ecs;
1029         :}
1030         ;
1031 enum_constant ::=
1032                 IDENTIFIER:id /*enum_arguments_opt*/
1033                 {: 
1034                     ParseNode pn=new ParseNode("enum_constant",parser.n());
1035                     pn.addChild("name").addChild(id);
1036                     RESULT=pn; 
1037                 :}
1038 //      |       IDENTIFIER enum_arguments_opt class_body
1039         ;
1040 //enum_arguments_opt ::=
1041 //      |       LPAREN argument_list_opt RPAREN
1042 //      ;
1043 //enum_body_declarations_opt ::=
1044 //      |       SEMICOLON class_body_declarations_opt:cbdo
1045 //      ;
1046
1047 //Failure aware computation
1048 flag_declaration ::= 
1049                 FLAG IDENTIFIER:id SEMICOLON {: 
1050                 ParseNode pn=new ParseNode("flag_declaration",parser.n());
1051                 pn.addChild("name").addChild(id);
1052                 RESULT=pn;
1053         :}      |
1054                 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {: 
1055                 ParseNode pn=new ParseNode("flag_declaration",parser.n());
1056                 pn.addChild("name").addChild(id);
1057                 pn.addChild("external");
1058                 RESULT=pn;
1059         :}
1060         ;
1061
1062 // 19.8.2) Field Declarations
1063 field_declaration ::= 
1064                 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {: 
1065                 ParseNode pn=new ParseNode("field_declaration",parser.n());
1066                 pn.addChild("modifier").addChild(mo);
1067                 pn.addChild("type").addChild(type);
1068                 pn.addChild("variables").addChild(var);
1069                 RESULT=pn;
1070         :} |
1071                 modifiers_opt:mo GLOBAL type:type variable_declarators:var SEMICOLON {: 
1072                 ParseNode pn=new ParseNode("field_declaration",parser.n());
1073                 pn.addChild("modifier").addChild(mo);
1074                 pn.addChild("type").addChild(type);
1075                 pn.addChild("variables").addChild(var);
1076                 pn.addChild("global");
1077                 RESULT=pn;
1078         :}
1079         ;
1080
1081 variable_declarators ::=
1082                 variable_declarator:vd {: 
1083                 ParseNode pn=new ParseNode("variable_declarators_list",parser.n());
1084                 pn.addChild(vd);
1085                 RESULT=pn;
1086         :}
1087         |       variable_declarators:vds COMMA variable_declarator:vd {:
1088                 vds.addChild(vd);
1089                 RESULT=vds;
1090         :}
1091         ;
1092 variable_declarator ::=
1093                 variable_declarator_id:id {:
1094                 ParseNode pn=new ParseNode("variable_declarator",parser.n());
1095                 pn.addChild(id);
1096                 RESULT=pn;
1097         :}
1098         |       variable_declarator_id:id EQ variable_initializer:init {: 
1099                 ParseNode pn=new ParseNode("variable_declarator",parser.n());
1100                 pn.addChild(id);
1101                 pn.addChild("initializer").addChild(init);
1102                 RESULT=pn;
1103         :}
1104         ;
1105 variable_declarator_id ::=
1106                 IDENTIFIER:id {: 
1107                 RESULT=(new ParseNode("single",parser.n())).addChild(id).getRoot();:}
1108         |       variable_declarator_id:id LBRACK RBRACK {:
1109                 RESULT=(new ParseNode("array",parser.n())).addChild(id).getRoot();:}
1110         ;
1111 variable_initializer ::=
1112                 expression:exp {: RESULT=exp; :}
1113         |       array_initializer:ai {: RESULT=(new ParseNode("array_initializer",parser.n())).addChild(ai).getRoot(); :}
1114         ;
1115
1116 // 19.8.3) Method Declarations
1117 method_declaration ::=
1118                 method_header:header method_body:body {:
1119                 ParseNode pn=new ParseNode("method_declaration",parser.n());
1120                 pn.addChild(header);
1121                 pn.addChild("body").addChild(body);
1122                 RESULT=pn;
1123         :}
1124         ;
1125 method_header ::=
1126                 modifiers_opt:mo type:type method_declarator:decl throws_opt:to 
1127         {:
1128                 ParseNode pn=new ParseNode("method_header",parser.n());
1129                 pn.addChild("modifiers").addChild(mo);
1130                 pn.addChild("returntype").addChild(type);
1131                 pn.addChild("throws").addChild(to);
1132                 pn.addChild(decl);
1133                 RESULT=pn;
1134         :}
1135         |       modifiers_opt:mo VOID method_declarator:decl throws_opt:to
1136         {:
1137                 ParseNode pn=new ParseNode("method_header",parser.n());
1138                 pn.addChild("modifiers").addChild(mo);
1139                 pn.addChild("throws").addChild(to);
1140                 pn.addChild(decl);
1141                 RESULT=pn;
1142         :}
1143         ;
1144 method_declarator ::=
1145                 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {: 
1146                 ParseNode pn=new ParseNode("method_declarator",parser.n());
1147                 pn.addChild("name").addChild(id);
1148                 pn.addChild("parameters").addChild(params);
1149                 RESULT=pn;
1150         :}
1151 //      |       method_declarator LBRACK RBRACK // deprecated
1152 // be careful; the above production also allows 'void foo() []'
1153         ;
1154 formal_parameter_list_opt ::=
1155         {: RESULT=new ParseNode("empty",parser.n()); :}
1156         |       formal_parameter_list:fpl {: 
1157                 RESULT=fpl;
1158         :}
1159         ;
1160 formal_parameter_list ::=
1161                 formal_parameter:fp {: 
1162                 ParseNode pn=new ParseNode("formal_parameter_list",parser.n());
1163                 pn.addChild(fp);
1164                 RESULT=pn;
1165         :}
1166         |       formal_parameter_list:fpl COMMA formal_parameter:fp {: 
1167                 fpl.addChild(fp);
1168                 RESULT=fpl;
1169         :}
1170         ;
1171 formal_parameter ::=
1172                 type:type variable_declarator_id:name {:
1173                 ParseNode pn=new ParseNode("formal_parameter",parser.n());
1174                 pn.addChild(type);
1175                 pn.addChild(name);
1176                 RESULT=pn;
1177         :}
1178         |
1179                 TAG variable_declarator_id:name {:
1180                 ParseNode pn=new ParseNode("tag_parameter",parser.n());
1181                 pn.addChild(name);
1182                 RESULT=pn;
1183         :}
1184         |       FINAL type:type variable_declarator_id:name {:
1185                 ParseNode pn=new ParseNode("formal_parameter",parser.n());
1186                 pn.addChild(type);
1187                 pn.addChild(name);
1188                 RESULT=pn;
1189         :}
1190         |       annotation:an type:type variable_declarator_id:name {:
1191                 ParseNode pn=new ParseNode("annotation_parameter",parser.n());
1192                 pn.addChild(type);
1193                 pn.addChild(name);
1194                 pn.addChild(an);
1195                 RESULT=pn;
1196         :}
1197         ;
1198 throws_opt ::=  
1199         {: RESULT=new ParseNode("empty",parser.n()); :}
1200         |       throws:trs
1201             {: RESULT=trs; :}
1202         ;
1203 throws ::=      THROWS class_type_list:ctl
1204         {: RESULT=(new ParseNode("throw_list",parser.n())).addChild(ctl).getRoot(); :}
1205         ;
1206 class_type_list ::=
1207                 class_type:ct
1208                 {: 
1209                 ParseNode pn=new ParseNode("class_type_list",parser.n());
1210                 pn.addChild(ct);
1211                 RESULT=pn; 
1212                 :}
1213         |       class_type_list:ctl COMMA class_type:ct
1214             {: 
1215             ctl.addChild(ct);
1216             RESULT=ctl; 
1217             :}
1218         ;
1219 method_body ::= block:block {: 
1220                 RESULT=block;
1221         :}
1222         |       SEMICOLON       {: RESULT=new ParseNode("empty",parser.n()); :}
1223         ;
1224
1225 // 19.8.4) Static Initializers
1226 static_initializer ::=
1227                 STATIC block:body {:
1228                 ParseNode pn=new ParseNode("static_block_declaration",parser.n());
1229                 pn.addChild("body").addChild(body);
1230                 RESULT=pn;
1231         :}
1232         ;
1233
1234 // 19.8.5) Constructor Declarations
1235 constructor_declaration ::=
1236                 modifiers_opt:mo constructor_declarator:cd throws_opt:to 
1237                         constructor_body:body   {:
1238                 ParseNode pn=new ParseNode("constructor_declaration",parser.n());
1239                 pn.addChild("modifiers").addChild(mo);
1240                 pn.addChild("throws").addChild(to);
1241                 pn.addChild(cd);
1242                 pn.addChild("body").addChild(body);
1243                 RESULT=pn;
1244         :} |
1245                 modifiers_opt:mo GLOBAL constructor_declarator:cd throws_opt:to 
1246                         constructor_body:body   {:
1247                 ParseNode pn=new ParseNode("constructor_declaration",parser.n());
1248                 pn.addChild("global");
1249                 pn.addChild("modifiers").addChild(mo);
1250                 pn.addChild("throws").addChild(to);
1251                 pn.addChild(cd);
1252                 pn.addChild("body").addChild(body);
1253                 RESULT=pn;
1254         :}
1255 ;
1256
1257 constructor_declarator ::=
1258                 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {: 
1259                 ParseNode pn=new ParseNode("constructor_declarator",parser.n());
1260                 pn.addChild(name);
1261                 pn.addChild("parameters").addChild(fplo);
1262                 RESULT=pn;
1263         :}
1264         ;
1265 constructor_body ::=
1266                 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {: 
1267                         ParseNode pn=new ParseNode("constructor_body",parser.n());
1268                         pn.addChild(eci);
1269                         pn.addChild(bs);
1270                         RESULT=pn;
1271         :} |
1272                 LBRACE explicit_constructor_invocation:eci RBRACE {: 
1273                         ParseNode pn=new ParseNode("constructor_body",parser.n());
1274                         pn.addChild(eci);
1275                         RESULT=pn;
1276         :} |
1277                 LBRACE block_statements:block RBRACE {: 
1278                 ParseNode pn=new ParseNode("constructor_body",parser.n());
1279                 pn.addChild(block);
1280                 RESULT=pn;
1281         :}
1282         |       LBRACE RBRACE {: RESULT=new ParseNode("empty",parser.n()); :}
1283         ;
1284 explicit_constructor_invocation ::=
1285         THIS LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1286              ParseNode pn=new ParseNode("explconstrinv",parser.n());
1287              pn.addChild(alo);
1288              RESULT=pn;
1289         :}
1290         |       
1291 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {: 
1292         ParseNode pn=new ParseNode("superinvoke",parser.n());
1293         pn.addChild(alo);
1294         RESULT=pn;
1295 :}
1296 //      |       primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1297 //      |       primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1298         ;
1299
1300 // 19.8.6) Location Hierarchy Declarations
1301 location_order_declaration ::= LOCDEF LBRACE location_order_list:lol RBRACE {:
1302                 RESULT=lol;                        
1303         :}
1304         ;
1305 location_order_list ::= 
1306                 location_order:lo {:
1307                 ParseNode pn=new ParseNode("location_order_list",parser.n());
1308                 pn.addChild(lo);
1309                 RESULT=pn;
1310         :}
1311         |       location_order_list:lol COMMA location_order:lo {:
1312                 lol.addChild(lo);
1313                 RESULT=lol;
1314         :}
1315         ;
1316 location_order ::= 
1317                 IDENTIFIER:loc1 LT IDENTIFIER:loc2{:
1318                 ParseNode pn=new ParseNode("location_order",parser.n());
1319                 pn.addChild(loc1);
1320                 pn.addChild(loc2);
1321                 RESULT=pn;         
1322         :}
1323         |       IDENTIFIER:loc MULT{:
1324                 ParseNode pn=new ParseNode("location_property",parser.n());             
1325                 pn.addChild(loc);
1326                 RESULT=pn;
1327         :}
1328         ;
1329
1330 // 19.9) Interfaces
1331
1332 // 19.9.1) Interface Declarations
1333 interface_declaration ::=
1334                modifiers_opt:mo INTERFACE IDENTIFIER:id extends_interfaces_opt:io
1335                        interface_body:body
1336        {:
1337         ParseNode pn=new ParseNode("interface_declaration",parser.n());
1338         pn.addChild("modifiers").addChild(mo);
1339         pn.addChild("name").addChild(id);
1340         pn.addChild("superIF").addChild(io);
1341         pn.addChild("interfacebody").addChild(body);
1342         RESULT=pn;
1343         :}
1344        | annotation_type_declaration
1345        ;
1346 extends_interfaces_opt ::=
1347        {: RESULT=new ParseNode("empty",parser.n()); :}
1348        |       extends_interfaces:eifs {: RESULT=eifs; :}
1349        ;
1350 extends_interfaces ::=
1351                EXTENDS interface_type:ift 
1352                {: 
1353                ParseNode pn=new ParseNode("extend_interface_list",parser.n());
1354                pn.addChild(ift);
1355                RESULT=pn; 
1356                :}
1357      |       extends_interfaces:eifs COMMA interface_type:ift
1358              {:
1359              eifs.addChild(ift);
1360              RESULT=eifs;
1361              :}
1362        ;
1363 interface_body ::=
1364                LBRACE interface_member_declarations_opt:imdo RBRACE
1365                {: RESULT=imdo; :}
1366        ;
1367 interface_member_declarations_opt ::=
1368        {: RESULT=new ParseNode("empty",parser.n()); :}
1369        |       interface_member_declarations:imd {: RESULT=imd; :}
1370        ;
1371 interface_member_declarations ::=
1372                interface_member_declaration:imd {: 
1373                         ParseNode pn=new ParseNode("interface_member_declaration_list",parser.n());
1374                         pn.addChild(imd);
1375                         RESULT=pn;
1376                 :}
1377        |       interface_member_declarations:imds interface_member_declaration:imd {: 
1378                         imds.addChild(imd);
1379                         RESULT=imds;
1380                 :}
1381        ;
1382 interface_member_declaration ::=
1383                constant_declaration:constant {: 
1384                 RESULT=(new ParseNode("constant",parser.n())).addChild(constant).getRoot();
1385         :}
1386        |       abstract_method_declaration:method {:
1387         RESULT=(new ParseNode("method",parser.n())).addChild(method).getRoot(); 
1388         :}
1389            |    enum_declaration:ed {:
1390            RESULT=(new ParseNode("enum_declaration",parser.n())).addChild(ed).getRoot();
1391            :}
1392 //       |       class_declaration:class 
1393 //       |       interface_declaration:interface 
1394        |       SEMICOLON {: 
1395        RESULT=new ParseNode("empty",parser.n()); 
1396        :}
1397        ;
1398 constant_declaration ::=
1399                field_declaration:fd {: RESULT=fd; :}
1400        // need to semantically check that modifiers of field declaration
1401        // include only PUBLIC, STATIC, or FINAL.  Other modifiers are
1402        // disallowed.
1403        ;
1404 abstract_method_declaration ::=
1405                method_header:header SEMICOLON {:
1406                 ParseNode pn=new ParseNode("method_declaration",parser.n());
1407                 pn.addChild("header").addChild(header);
1408                 pn.addChild("body").addChild(new ParseNode("empty",parser.n()));
1409                 RESULT=pn;
1410         :}
1411        ;
1412 /*
1413 annotation_type_declaration ::=
1414                 AT INTERFACE IDENTIFIER annotation_type_body
1415         |       modifiers_at INTERFACE IDENTIFIER annotation_type_body
1416         ;
1417 annotation_type_body ::=
1418                 LBRACE annotation_type_element_declarations_opt RBRACE
1419         ;
1420 annotation_type_element_declarations_opt ::=
1421         |       annotation_type_element_declarations
1422         ;
1423 annotation_type_element_declarations ::=
1424                 annotation_type_element_declaration
1425         |       annotation_type_element_declarations annotation_type_element_declaration
1426         ;
1427 annotation_type_element_declaration ::=
1428                 constant_declaration
1429         |       modifiers_opt type IDENTIFIER LPAREN RPAREN default_value_opt SEMICOLON
1430         |       class_declaration 
1431         |       enum_declaration 
1432         |       interface_declaration 
1433         |       SEMICOLON
1434         ;
1435 */
1436 // 19.10) Arrays
1437 array_initializer ::=
1438                 LBRACE variable_initializers:var_init_list COMMA RBRACE {:
1439                        RESULT=var_init_list;
1440                 :}
1441         |       LBRACE variable_initializers:var_init_list RBRACE {:
1442                        RESULT=var_init_list;
1443                 :}
1444         |       LBRACE COMMA RBRACE {:
1445                        RESULT=new ParseNode("empty",parser.n());                       
1446                 :}
1447         |       LBRACE RBRACE {:
1448                        RESULT=new ParseNode("empty",parser.n());
1449                 :}
1450         ;
1451 variable_initializers ::=
1452                 variable_initializer:var_init {:
1453                        ParseNode pn=new ParseNode("var_init_list",parser.n());
1454                        pn.addChild(var_init);
1455                        RESULT=pn;
1456                 :}
1457         |       variable_initializers:var_init_list COMMA variable_initializer:var_init {:
1458                        var_init_list.addChild(var_init);
1459                        RESULT=var_init_list;
1460                 :}
1461         ;
1462
1463 // 19.11) Blocks and Statements
1464 block ::=       LBRACE block_statements_opt:bso RBRACE {: 
1465         RESULT=bso;
1466         :}
1467         ;
1468 block_statements_opt ::=
1469         {: RESULT=new ParseNode("empty",parser.n()); :}
1470         |       block_statements:bs {: 
1471         RESULT=bs;
1472         :}
1473         ;
1474 block_statements ::=
1475                 block_statement:bs {:
1476         ParseNode pn=new ParseNode("block_statement_list",parser.n());
1477         pn.addChild(bs);
1478         RESULT=pn;
1479         :}
1480         |       block_statements:bss block_statement:bs {: 
1481         bss.addChild(bs);
1482         RESULT=bss;
1483         :}
1484         ;
1485 block_statement ::=
1486         tag_variable_declaration_statement:tvds {:
1487                 RESULT=tvds;
1488         :}              
1489         |       local_variable_declaration_statement:lvds {: 
1490                 RESULT=lvds;
1491         :}
1492         |       statement:statement {: 
1493                 RESULT=statement;
1494         :}
1495 //      |       enum_declaration:ed {:
1496 //              RESULT=ed;
1497 //      :}
1498 //      |       class_declaration
1499 //      |       interface_declaration
1500         ;
1501 tag_variable_declaration_statement ::=
1502                 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {: 
1503                 ParseNode pn=new ParseNode("tag_declaration",parser.n());
1504                 pn.addChild("single").addChild(id);
1505                 pn.addChild("type").addChild(type);
1506                 RESULT=pn;
1507         :}
1508         ;
1509 local_variable_declaration_statement ::=
1510                 local_variable_declaration:lvd SEMICOLON {: 
1511                 RESULT=lvd;
1512         :}
1513         ;
1514 local_variable_declaration ::=
1515                 type:type variable_declarators:var {: 
1516                 ParseNode pn=new ParseNode("local_variable_declaration",parser.n());
1517                 pn.addChild(type);
1518                 pn.addChild(var);
1519                 RESULT=pn;
1520         :}
1521 //      |       FINAL type:type variable_declarators:var {: 
1522          /* CAUTION:  only FINAL and annotations are legal modifiers here */
1523         |       modifiers:mo type:type variable_declarators:var {:
1524                 ParseNode pn=new ParseNode("local_variable_declaration",parser.n());
1525                 pn.addChild(type);
1526                 pn.addChild(var);
1527                 pn.addChild("modifiers").addChild(mo);
1528                 RESULT=pn;
1529         :}
1530         ;
1531 statement ::=   statement_without_trailing_substatement:st {: 
1532                 RESULT=st;
1533         :}
1534         |       labeled_statement:st {: RESULT=st; :}
1535         |       if_then_statement:st {: RESULT=st; :}
1536         |       if_then_else_statement:st {: RESULT=st; :}
1537         |       while_statement:st {: RESULT=st; :}
1538         |       for_statement:st {: RESULT=st; :}
1539         ;
1540 statement_no_short_if ::=
1541                 statement_without_trailing_substatement:st {: RESULT=st; :}
1542         |       labeled_statement_no_short_if:st {: RESULT=st; :}
1543         |       if_then_else_statement_no_short_if:st {: RESULT=st; :}
1544         |       while_statement_no_short_if:st {: RESULT=st; :}
1545         |       for_statement_no_short_if:st {: RESULT=st; :}
1546         ;
1547 statement_without_trailing_substatement ::=
1548                 block:st {: RESULT=st; :}
1549         |       empty_statement:st {: RESULT=st; :}
1550         |       expression_statement:st {: RESULT=st; :}
1551         |       switch_statement:st {: RESULT=st; :}
1552         |       do_statement:dos {:RESULT=dos; :}
1553         |       break_statement:st {: RESULT=st; :}
1554         |       continue_statement:st {: RESULT=st; :}
1555         |       return_statement:st {: RESULT=st; :}
1556         |       task_exitstatement:st {: RESULT=st; :}
1557         |       atomic_statement:st {: RESULT=st; :}
1558         |       sese_statement:st {: RESULT=st; :}
1559         |       synchronized_statement:st {: RESULT=st; :}
1560         |       genreach_statement:st {: RESULT=st; :}
1561         |       throw_statement:st {: RESULT=st; :}
1562         |       try_statement:st {: RESULT=st; :}
1563 //      |       assert_statement
1564         ;
1565 empty_statement ::=
1566                 SEMICOLON {: RESULT=new ParseNode("nop",parser.n()); :}
1567         ;
1568 labeled_statement ::=
1569                 IDENTIFIER:id COLON statement:st {:
1570                 ParseNode pn=new ParseNode("labeledstatement",parser.n());
1571                 pn.addChild("name").addChild(id);
1572                 pn.addChild("statement").addChild(st);
1573                 RESULT=pn;                              
1574                 :}
1575         ;
1576 labeled_statement_no_short_if ::=
1577                 IDENTIFIER:id COLON statement_no_short_if:st {:
1578                 ParseNode pn=new ParseNode("labeledstatement",parser.n());
1579                 pn.addChild("name").addChild(id);
1580                 pn.addChild("statement").addChild(st);
1581                 RESULT=pn;                              
1582                 :}
1583         ;
1584 expression_statement ::=
1585                 statement_expression:se SEMICOLON {: 
1586                 ParseNode pn=new ParseNode("expression",parser.n());
1587                 pn.addChild(se);
1588                 RESULT=pn; :}
1589         ;
1590 statement_expression ::=
1591                 assignment:st {: RESULT=st; :}
1592         |       preincrement_expression:st {: RESULT=st; :}
1593         |       predecrement_expression:st {: RESULT=st; :}
1594         |       postincrement_expression:st {: RESULT=st; :}
1595         |       postdecrement_expression:st {: RESULT=st; :}
1596         |       method_invocation:st {: RESULT=st; :}
1597         |       class_instance_creation_expression:st {: RESULT=st; :}
1598         ;
1599 if_then_statement ::=
1600                 IF LPAREN expression:exp RPAREN statement:st {: 
1601                 ParseNode pn=new ParseNode("ifstatement",parser.n());
1602                 pn.addChild("condition").addChild(exp);
1603                 pn.addChild("statement").addChild(st);
1604                 RESULT=pn;
1605         :}
1606         ;
1607 if_then_else_statement ::=
1608                 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1609                         ELSE statement:else_st {:
1610                 ParseNode pn=new ParseNode("ifstatement",parser.n());
1611                 pn.addChild("condition").addChild(exp);
1612                 pn.addChild("statement").addChild(st);
1613                 pn.addChild("else_statement").addChild(else_st);
1614                 RESULT=pn;
1615         :}
1616         ;
1617 if_then_else_statement_no_short_if ::=
1618                 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1619                         ELSE statement_no_short_if:else_st {:
1620                 ParseNode pn=new ParseNode("ifstatement",parser.n());
1621                 pn.addChild("condition").addChild(exp);
1622                 pn.addChild("statement").addChild(st);
1623                 pn.addChild("else_statement").addChild(else_st);
1624                 RESULT=pn;
1625         :}
1626         ;
1627 switch_statement ::=
1628                 SWITCH LPAREN expression:exp RPAREN switch_block:body
1629                 {:
1630                     ParseNode pn=new ParseNode("switch_statement",parser.n());
1631                     pn.addChild("condition").addChild(exp);
1632                     pn.addChild("statement").addChild(body);
1633                     RESULT=pn;
1634                 :}
1635         ;
1636 switch_block ::=
1637                 LBRACE switch_block_statement_groups:sbsg switch_labels:sl RBRACE
1638                 {: 
1639                     ParseNode pn = new ParseNode("switch_block",parser.n());
1640                     pn.addChild("switch_labels").addChild(sl);
1641                     pn.addChild("switch_statements").addChild(new ParseNode("empty",parser.n()));
1642                     sbsg.addChild(pn);
1643                     RESULT=sbsg; 
1644                 :}
1645         |       LBRACE switch_block_statement_groups:sbsg RBRACE
1646             {: 
1647                     RESULT=sbsg; 
1648                 :}
1649         |       LBRACE switch_labels:sl RBRACE 
1650             {: 
1651                 ParseNode pnb = new ParseNode("switch_block_list",parser.n());
1652                     ParseNode pn = new ParseNode("switch_block",parser.n());
1653                     pn.addChild("switch_labels").addChild(sl);
1654                     pn.addChild("switch_statements").addChild(new ParseNode("empty",parser.n()));
1655                     pnb.addChild(pn);
1656                     RESULT=pnb; 
1657                 :}
1658         |       LBRACE RBRACE {: RESULT=new ParseNode("empty",parser.n()); :}
1659         ;
1660 switch_block_statement_groups ::=
1661                 switch_block_statement_group:sbsg
1662                 {: 
1663                     ParseNode pn = new ParseNode("switch_block_list",parser.n());
1664                     pn.addChild(sbsg);
1665                     RESULT=pn;
1666                 :}
1667         |       switch_block_statement_groups:sbsgs switch_block_statement_group:sbsg
1668             {:
1669                 sbsgs.addChild(sbsg);
1670                 RESULT=sbsgs;
1671             :}
1672         ;
1673 switch_block_statement_group ::=
1674                 switch_labels:sls block_statements:body
1675                 {: 
1676                     ParseNode pn=new ParseNode("switch_block",parser.n());
1677                     pn.addChild("switch_labels").addChild(sls);
1678                     pn.addChild("switch_statements").addChild(body);
1679                     RESULT=pn; 
1680                 :}
1681         ;
1682 switch_labels ::=
1683                 switch_label:sl
1684                 {: 
1685                     ParseNode pn=new ParseNode("switch_label_list",parser.n());
1686                     pn.addChild(sl);
1687                     RESULT=pn; 
1688                 :}
1689         |       switch_labels:sls switch_label:sl
1690             {: 
1691                     sls.addChild(sl); 
1692                     RESULT=sls;
1693                 :}
1694         ;
1695 switch_label ::=
1696                 CASE constant_expression:ce COLON
1697                 {: 
1698                     ParseNode pn=new ParseNode("switch_label",parser.n());
1699                     pn.addChild(ce);
1700                     RESULT=pn;
1701                 :}
1702         |       DEFAULT COLON
1703             {: 
1704                     RESULT=new ParseNode("default_switch_label",parser.n()); 
1705                 :}
1706         ;
1707
1708 while_statement ::=
1709                 WHILE LPAREN expression:exp RPAREN statement:st {: 
1710                 ParseNode pn=new ParseNode("whilestatement",parser.n());
1711                 pn.addChild("condition").addChild(exp);
1712                 pn.addChild("statement").addChild(st);
1713                 RESULT=pn;
1714         :}
1715         ;
1716 while_statement_no_short_if ::=
1717                 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1718                 ParseNode pn=new ParseNode("whilestatement",parser.n());
1719                 pn.addChild("condition").addChild(exp);
1720                 pn.addChild("statement").addChild(st);
1721                 RESULT=pn;
1722                 :}
1723         ;
1724 do_statement ::=
1725                 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {: 
1726                 ParseNode pn=new ParseNode("dowhilestatement",parser.n());
1727                 pn.addChild("condition").addChild(exp);
1728                 pn.addChild("statement").addChild(st);
1729                 RESULT=pn;
1730         :}
1731         ;
1732 for_statement ::=
1733                 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1734                         for_update_opt:update RPAREN statement:st {: 
1735                 ParseNode pn=new ParseNode("forstatement",parser.n());
1736                 pn.addChild("initializer").addChild(init);
1737                 pn.addChild("condition").addChild(exp);
1738                 pn.addChild("update").addChild(update);
1739                 pn.addChild("statement").addChild(st);
1740                 RESULT=pn;
1741                 :}
1742         ;
1743 for_statement_no_short_if ::=
1744                 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1745                         for_update_opt:update RPAREN statement_no_short_if:st {:
1746                 ParseNode pn=new ParseNode("forstatement",parser.n());
1747                 pn.addChild("initializer").addChild(init);
1748                 pn.addChild("condition").addChild(exp);
1749                 pn.addChild("update").addChild(update);
1750                 pn.addChild("statement").addChild(st);
1751                 RESULT=pn;
1752                 :}
1753         ;
1754 for_init_opt ::=
1755         {: RESULT=new ParseNode("empty",parser.n()); :}
1756         |       for_init:init {: RESULT=init; :}
1757         ;
1758 for_init ::=    statement_expression_list:list {: RESULT=list; :}
1759         |       local_variable_declaration:decl {: RESULT=decl; :}
1760         ;
1761 for_update_opt ::=
1762         {: RESULT=new ParseNode("empty",parser.n()); :}
1763         |       for_update:update {: RESULT=update; :}
1764         ;
1765 for_update ::=  statement_expression_list:list {: RESULT=list; :}
1766         ;
1767 statement_expression_list ::=
1768                 statement_expression:expr {: 
1769                 RESULT=(new ParseNode("statement_expression_list",parser.n())).addChild(expr).getRoot();
1770         :}
1771         |       statement_expression_list:list COMMA statement_expression:expr {: 
1772                 list.addChild(expr);
1773                 RESULT=list;
1774         :}
1775         ;
1776
1777 identifier_opt ::= {: RESULT=new ParseNode("identifier_opt",parser.n());
1778         :} 
1779         |       IDENTIFIER:id {:
1780                 ParseNode pn=new ParseNode("identifier_opt",parser.n());
1781                 pn.addChild("name").addChild(id);
1782                 RESULT=pn;
1783         :}
1784         ;
1785
1786 break_statement ::=
1787                 BREAK identifier_opt:id SEMICOLON {: 
1788                 ParseNode pn=new ParseNode("break",parser.n());                 
1789                 pn.addChild(id);
1790                 RESULT=pn;
1791         :}
1792         ;
1793
1794 continue_statement ::=
1795                 CONTINUE  
1796 //identifier_opt 
1797 SEMICOLON
1798 {: RESULT=new ParseNode("continue",parser.n()); :}
1799         ;
1800 return_statement ::=
1801                 RETURN expression_opt:exp SEMICOLON {: 
1802         RESULT=(new ParseNode("return",parser.n())).addChild(exp).getRoot(); :}
1803         ;
1804 throw_statement ::=
1805                 THROW expression:exp SEMICOLON {:
1806                 RESULT=(new ParseNode("throwstatement",parser.n())).addChild(exp).getRoot();
1807                 :}
1808         ;
1809 synchronized_statement ::=
1810                 SYNCHRONIZED LPAREN expression:e RPAREN block:b {: 
1811                 ParseNode pn=new ParseNode("synchronized",parser.n());
1812                 pn.addChild("expr").addChild(e);
1813                 pn.addChild("block").addChild(b);
1814                 RESULT=pn;
1815                 :}
1816         ;
1817 atomic_statement ::=
1818                 ATOMIC block:blk {: 
1819         RESULT=(new ParseNode("atomic",parser.n())).addChild(blk).getRoot();
1820         :}
1821         ;
1822 sese_statement ::=
1823                SESE block:blk {: 
1824                ParseNode pn = new ParseNode("sese",parser.n());
1825                pn.addChild("body").addChild(blk);
1826                RESULT=pn;
1827         :}
1828         |      SESE variable_declarator_id:id block:blk {: 
1829                ParseNode pn = new ParseNode("sese",parser.n());
1830                pn.addChild("body").addChild(blk);
1831                pn.addChild("identifier").addChild(id);
1832                RESULT=pn;
1833         :}
1834         |      RBLOCK block:blk {: 
1835                ParseNode pn = new ParseNode("sese",parser.n());
1836                pn.addChild("body").addChild(blk);
1837                RESULT=pn;
1838         :}
1839         |      RBLOCK variable_declarator_id:id block:blk {: 
1840                ParseNode pn = new ParseNode("sese",parser.n());
1841                pn.addChild("body").addChild(blk);
1842                pn.addChild("identifier").addChild(id);
1843                RESULT=pn;
1844         :}
1845         ;
1846 try_statement ::=
1847                 TRY block:bk catches:ca
1848                 {: 
1849                 ParseNode pn=new ParseNode("trycatchstatement",parser.n());
1850                 pn.addChild("tryblock").addChild(bk); 
1851                 pn.addChild("catchblock").addChild(ca);
1852                 RESULT=pn;
1853                 :}
1854         |       TRY block:bk catches_opt:ca finally:fi
1855             {: 
1856                 ParseNode pn=new ParseNode("trycatchstatement",parser.n());
1857                 pn.addChild("tryblock").addChild(bk); 
1858                 pn.addChild("catchblock").addChild(ca);
1859                 pn.addChild("finallyblock").addChild(fi);
1860                 RESULT=pn;
1861                 :}
1862         ;
1863 catches_opt ::=
1864     {: RESULT=new ParseNode("empty",parser.n()); :}
1865         |       catches:ca
1866         {: RESULT=ca; :}
1867         ;
1868 catches ::=     catch_clause:ca
1869         {:
1870         ParseNode pn=new ParseNode("catchlist",parser.n());
1871         pn.addChild(ca);
1872         RESULT=pn;
1873         :}
1874         |       catches:cas catch_clause:ca 
1875             {:
1876             cas.addChild(ca);
1877             RESULT=cas;
1878             :}
1879         ;
1880 catch_clause ::=
1881                 CATCH LPAREN formal_parameter:fp RPAREN block:bk
1882                 {:
1883                 ParseNode pn=new ParseNode("catchclause",parser.n());
1884                 pn.addChild("parameter").addChild(fp);
1885                 pn.addChild("block").addChild(bk);
1886                 RESULT=pn;
1887                 :}
1888         ;
1889 finally ::=     FINALLY block:bk
1890     {:
1891     RESULT=bk;
1892     :}
1893         ;
1894 //assert_statement ::=
1895 //              ASSERT expression SEMICOLON
1896 //      |       ASSERT expression COLON expression SEMICOLON
1897 //      ;
1898
1899 // 19.12) Expressions
1900 primary ::=     primary_no_new_array:st {: 
1901                 RESULT=st; :}
1902         |       array_creation_init:st {: 
1903                 RESULT=st;
1904         :}
1905         |       array_creation_uninit:st {:
1906                 RESULT=st;
1907         :}
1908         ;
1909 primary_no_new_array ::=
1910                 literal:lit {: RESULT=lit; :}
1911         |       THIS {: RESULT=new ParseNode("this",parser.n()); :}
1912         |       LPAREN expression:exp RPAREN {: RESULT=exp; :}
1913         |       class_instance_creation_expression:exp {: RESULT=exp; :}
1914         |       field_access:exp {: RESULT=exp; :}
1915         |       method_invocation:exp {: RESULT=exp; :}
1916         |       array_access:exp {: RESULT=exp; :}
1917         |       ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {: 
1918                 ParseNode pn=new ParseNode("isavailable",parser.n());
1919                 pn.addChild(id);
1920                 RESULT=pn;
1921         :}
1922 //      |       primitive_type:pt DOT CLASS {:
1923 //          ParseNode pn=new ParseNode("class_type",parser.n());
1924 //          pn.addChild(pt);
1925 //          RESULT=pn;
1926 //      :}
1927 //      |       VOID DOT CLASS
1928 //      |       array_type:at DOT CLASS {:
1929 //          ParseNode pn=new ParseNode("class_type",parser.n());
1930 //          pn.addChild(at);
1931 //          RESULT=pn;
1932 //      :}
1933         |       name:name DOT CLASS {:
1934             ParseNode pn=new ParseNode("class_type",parser.n());
1935             pn.addChild("type").addChild("class").addChild(name);
1936             RESULT=pn;
1937         :}
1938 //      |       name DOT THIS
1939         ;
1940 class_instance_creation_expression ::=
1941         NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {: 
1942                 ParseNode pn=new ParseNode("createobject",parser.n());
1943                 pn.addChild(type);
1944                 pn.addChild(args);
1945                 pn.addChild(feo);
1946                 RESULT=pn;
1947         :} |
1948         NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: 
1949                 ParseNode pn=new ParseNode("createobject",parser.n());
1950                 pn.addChild(type);
1951                 pn.addChild(args);
1952                 RESULT=pn;
1953         :} 
1954         //Global object
1955         | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: 
1956                 ParseNode pn=new ParseNode("createobject",parser.n());
1957                 pn.addChild(type);
1958                 pn.addChild(args);
1959                 pn.addChild("global");
1960                 RESULT=pn;
1961         :}
1962         | SCRATCH NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {: 
1963                 ParseNode pn=new ParseNode("createobject",parser.n());
1964                 pn.addChild(type);
1965                 pn.addChild(args);
1966                 pn.addChild("scratch");
1967                 RESULT=pn;
1968         :}
1969         // Objects we want to track in disjointness analysis
1970         | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: 
1971                 ParseNode pn=new ParseNode("createobject",parser.n());
1972                 pn.addChild(type);
1973                 pn.addChild(args);
1974                 pn.addChild("disjoint").addChild(id);
1975                 RESULT=pn;
1976         :}
1977         | NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {: 
1978                 ParseNode pn=new ParseNode("createobject",parser.n());
1979                 pn.addChild(type);
1980                 pn.addChild(args);
1981                 pn.addChild(tl);
1982                 RESULT=pn;
1983         :}
1984         | NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {: 
1985                 ParseNode pn=new ParseNode("createobject",parser.n());
1986                 pn.addChild(type);
1987                 pn.addChild(args);
1988                 pn.addChild(fl);
1989                 pn.addChild(tl);
1990                 RESULT=pn;
1991         :}
1992         |       NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN class_body:body {: 
1993                 ParseNode pn=new ParseNode("createobjectcls",parser.n());             
1994                 pn.addChild(type);
1995                 pn.addChild(args);
1996                 pn.addChild("decl").addChild("classbody").addChild(body);
1997                 RESULT=pn;
1998         :}
1999 //      |       primary DOT NEW IDENTIFIER
2000 //                      LPAREN argument_list_opt RPAREN {: 
2001 //              
2002 //      :}
2003 //      |       primary DOT NEW IDENTIFIER
2004 //                      LPAREN argument_list_opt RPAREN class_body
2005 //      |       name DOT NEW IDENTIFIER
2006 //                      LPAREN argument_list_opt RPAREN
2007 //      |       name DOT NEW IDENTIFIER
2008 //                      LPAREN argument_list_opt RPAREN class_body
2009         ;
2010 cons_argument_list_opt ::=
2011         {: RESULT=new ParseNode("empty",parser.n()); :}
2012         |       cons_argument_list:args {: RESULT=args; :}
2013         ;
2014
2015 cons_argument_list ::=
2016                 IDENTIFIER:id COLON expression:exp {:
2017                 ParseNode pn=new ParseNode("cons_argument_list",parser.n());
2018                 ParseNode pnarg=pn.addChild("binding");
2019                 pnarg.addChild("var").addChild(id);
2020                 pnarg.addChild("exp").addChild(exp);
2021                 RESULT=pn;
2022         :}
2023         |       argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
2024                 ParseNode pnarg=new ParseNode("binding",parser.n());
2025                 pnarg.addChild("var").addChild(id);
2026                 pnarg.addChild("exp").addChild(exp);
2027                 list.addChild(pnarg);
2028                 RESULT=list;
2029         :}
2030         ;
2031
2032 argument_list_opt ::=
2033         {: RESULT=new ParseNode("empty",parser.n()); :}
2034         |       argument_list:args {: RESULT=args; :}
2035         ;
2036
2037 argument_list ::=
2038                 expression:exp {:
2039                 ParseNode pn=new ParseNode("argument_list",parser.n());
2040                 pn.addChild(exp);
2041                 RESULT=pn;
2042         :}
2043         |       argument_list:list COMMA expression:exp {:
2044                 list.addChild(exp);
2045                 RESULT=list;
2046         :}
2047         ;
2048 array_creation_uninit ::=
2049                 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
2050                 ParseNode pn=new ParseNode("createarray",parser.n());
2051                 pn.addChild(type);
2052                 pn.addChild(dimexpr);
2053                 pn.addChild("dims_opt").setLiteral(dims);
2054                 RESULT=pn;
2055                 :}
2056         |       NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
2057                 ParseNode pn=new ParseNode("createarray",parser.n());
2058                 pn.addChild(type);
2059                 pn.addChild(dimexpr);
2060                 pn.addChild("dims_opt").setLiteral(dims);
2061                 RESULT=pn;
2062         :}
2063         |       GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
2064                 ParseNode pn=new ParseNode("createarray",parser.n());
2065                 pn.addChild(type);
2066                 pn.addChild(dimexpr);
2067                 pn.addChild("dims_opt").setLiteral(dims);
2068                 pn.addChild("global");
2069                 RESULT=pn;
2070                 :}
2071         |       SCRATCH NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
2072                 ParseNode pn=new ParseNode("createarray",parser.n());
2073                 pn.addChild(type);
2074                 pn.addChild(dimexpr);
2075                 pn.addChild("dims_opt").setLiteral(dims);
2076                 pn.addChild("scratch");
2077                 RESULT=pn;
2078                 :}
2079         |       DISJOINT IDENTIFIER:id NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
2080                 ParseNode pn=new ParseNode("createarray",parser.n());
2081                 pn.addChild(type);
2082                 pn.addChild(dimexpr);
2083                 pn.addChild("dims_opt").setLiteral(dims);
2084                 pn.addChild("disjoint").addChild(id);
2085                 RESULT=pn;
2086                 :}
2087         |       GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
2088                 ParseNode pn=new ParseNode("createarray",parser.n());
2089                 pn.addChild(type);
2090                 pn.addChild(dimexpr);
2091                 pn.addChild("dims_opt").setLiteral(dims);
2092                 pn.addChild("global");
2093                 RESULT=pn;
2094                 :}
2095         |       SCRATCH NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
2096                 ParseNode pn=new ParseNode("createarray",parser.n());
2097                 pn.addChild(type);
2098                 pn.addChild(dimexpr);
2099                 pn.addChild("dims_opt").setLiteral(dims);
2100                 pn.addChild("scratch");
2101                 RESULT=pn;
2102                 :}
2103         |       DISJOINT IDENTIFIER:id NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
2104                 ParseNode pn=new ParseNode("createarray",parser.n());
2105                 pn.addChild(type);
2106                 pn.addChild(dimexpr);
2107                 pn.addChild("dims_opt").setLiteral(dims);
2108                 pn.addChild("disjoint").addChild(id);           
2109                 RESULT=pn;
2110                 :}
2111         ;
2112 array_creation_init ::=
2113                 NEW primitive_type:type dims:dims array_initializer:ai {: 
2114                 ParseNode pn=new ParseNode("createarray2",parser.n());
2115                 pn.addChild(type);
2116                 pn.addChild("dims_opt").setLiteral(dims);
2117                 pn.addChild("initializer").addChild(ai);
2118                 RESULT=pn;
2119                 :}
2120         |       NEW class_or_interface_type:type dims:dims array_initializer:ai {: 
2121                 ParseNode pn=new ParseNode("createarray2",parser.n());
2122                 pn.addChild(type);
2123                 pn.addChild("dims_opt").setLiteral(dims);
2124                 pn.addChild("initializer").addChild(ai);
2125                 RESULT=pn;
2126                 :}
2127         ;
2128 dim_exprs ::=   dim_expr:exp {: 
2129                 ParseNode pn=new ParseNode("dim_exprs",parser.n());
2130                 pn.addChild(exp);
2131                 RESULT=pn; :}
2132         |       dim_exprs:base dim_expr:exp {: 
2133                 base.addChild(exp);
2134                 RESULT=base;
2135         :}
2136         ;
2137 dim_expr ::=    LBRACK expression:exp RBRACK {: RESULT=exp; :}
2138         ;
2139 dims_opt ::= {: RESULT=new Integer(0); :}
2140         |       dims:dims {: RESULT = dims; :}
2141         ;
2142
2143 dims ::=        LBRACK RBRACK {: RESULT=new Integer(1); :}
2144         |       dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
2145         ;
2146
2147 field_access ::=
2148                 primary:base DOT IDENTIFIER:id {: 
2149                 ParseNode pn=new ParseNode("fieldaccess",parser.n());
2150                 pn.addChild("base").addChild(base);
2151                 pn.addChild("field").addChild(id);
2152                 RESULT=pn;
2153     :}
2154 //      |       SUPER DOT IDENTIFIER
2155 //      |       name DOT SUPER DOT IDENTIFIER
2156         ;
2157 method_invocation ::=
2158                 name:name LPAREN argument_list_opt:args RPAREN {: 
2159                 ParseNode pn=new ParseNode("methodinvoke1",parser.n());
2160                 pn.addChild(name);
2161                 pn.addChild(args);
2162                 RESULT=pn;
2163         :}
2164         |       primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {: 
2165                 ParseNode pn=new ParseNode("methodinvoke2",parser.n());
2166                 pn.addChild("base").addChild(base);
2167                 pn.addChild("id").addChild(name);
2168                 pn.addChild(args);
2169                 RESULT=pn;
2170         :}
2171         |       SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {: 
2172                 ParseNode name=new ParseNode("name",parser.n());
2173                 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
2174                 name.addChild("identifier").addChild(id);
2175                 ParseNode pn=new ParseNode("methodinvoke1",parser.n());
2176                 pn.addChild(name);
2177                 pn.addChild(args);
2178                 RESULT=pn;
2179         :}
2180 //      |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
2181         ;
2182 array_access ::=
2183                 name:name LBRACK expression:exp RBRACK {: 
2184                 ParseNode pn=new ParseNode("arrayaccess",parser.n());
2185                 pn.addChild("base").addChild(name);
2186                 pn.addChild("index").addChild(exp);
2187                 RESULT=pn;
2188         :}
2189         |       primary_no_new_array:base LBRACK expression:exp RBRACK {: 
2190                 ParseNode pn=new ParseNode("arrayaccess",parser.n());
2191                 pn.addChild("base").addChild(base);
2192                 pn.addChild("index").addChild(exp);
2193                 RESULT=pn;
2194         :}
2195 //      |       array_creation_init:init LBRACK expression:exp RBRACK {: 
2196 //              ParseNode pn=new ParseNode("arrayaccess",parser.n());
2197 //              pn.addChild("init").addChild(init);
2198 //              pn.addChild("index").addChild(exp);
2199 //              RESULT=pn;
2200 //      :}
2201         ;
2202
2203 postfix_expression ::=
2204                 primary:exp {: 
2205         RESULT=exp; :}
2206         |       name:exp {: RESULT=exp; :}
2207         |       postincrement_expression:exp {: RESULT=exp; :}
2208         |       postdecrement_expression:exp {: RESULT=exp; :}
2209         ;
2210 postincrement_expression ::=
2211                 postfix_expression:exp PLUSPLUS 
2212                 {: RESULT=(new ParseNode("postinc",parser.n())).addChild(exp).getRoot(); :}
2213         ;
2214 postdecrement_expression ::=
2215                 postfix_expression:exp MINUSMINUS
2216                 {: RESULT=(new ParseNode("postdec",parser.n())).addChild(exp).getRoot(); :}
2217         ;
2218 unary_expression ::=
2219                 preincrement_expression:exp {: RESULT=exp; :}
2220         |       predecrement_expression:exp {: RESULT=exp; :}
2221         |       PLUS unary_expression:exp 
2222         {: RESULT=(new ParseNode("unaryplus",parser.n())).addChild(exp).getRoot(); :}
2223         |       MINUS unary_expression:exp
2224         {: RESULT=(new ParseNode("unaryminus",parser.n())).addChild(exp).getRoot(); :}
2225         |       unary_expression_not_plus_minus:exp {: 
2226                         RESULT=exp; :}
2227         ;
2228 preincrement_expression ::=
2229                 PLUSPLUS unary_expression:exp
2230                 {: RESULT=(new ParseNode("preinc",parser.n())).addChild(exp).getRoot(); :}
2231         ;
2232 predecrement_expression ::=
2233                 MINUSMINUS unary_expression:exp
2234                 {: RESULT=(new ParseNode("predec",parser.n())).addChild(exp).getRoot(); :}
2235         ;
2236 unary_expression_not_plus_minus ::=
2237                 postfix_expression:exp {: 
2238                 RESULT=exp; :}
2239         |       COMP unary_expression:exp
2240                 {: RESULT=(new ParseNode("comp",parser.n())).addChild(exp).getRoot(); :}
2241         |       NOT unary_expression:exp 
2242                 {: RESULT=(new ParseNode("not",parser.n())).addChild(exp).getRoot(); :}
2243         |       cast_expression:exp {: RESULT=exp; :}
2244         ;
2245 cast_expression ::=
2246                 LPAREN primitive_type:type dims_opt:dims
2247                 RPAREN unary_expression:exp {: 
2248                 ParseNode pn=new ParseNode("cast1",parser.n());
2249 if (dims.intValue()==0)
2250                 pn.addChild("type").addChild(type);
2251 else {
2252                 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
2253                 arrayt.addChild("basetype").addChild(type);
2254                 arrayt.addChild("dims").setLiteral(dims);
2255 }
2256                 pn.addChild("exp").addChild(exp);
2257                 RESULT=pn;
2258         :}
2259         |       LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {: 
2260                 ParseNode pn=new ParseNode("cast2",parser.n());
2261                 pn.addChild("type").addChild(type);
2262                 pn.addChild("exp").addChild(exp);
2263                 RESULT=pn;
2264
2265         :}
2266         |       LPAREN name:name dims:dims RPAREN unary_expression_not_plus_minus:exp {: 
2267                 ParseNode pn=new ParseNode("cast1",parser.n());
2268 if (dims.intValue()==0)
2269                 pn.addChild("type").addChild("class").addChild(name);
2270 else {
2271                 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
2272                 arrayt.addChild("basetype").addChild("type").addChild("class").addChild(name);
2273                 arrayt.addChild("dims").setLiteral(dims);
2274 }
2275                 pn.addChild("exp").addChild(exp);
2276                 RESULT=pn;
2277
2278         :}
2279         ;
2280 multiplicative_expression ::=
2281                 unary_expression:exp {: 
2282                         RESULT=exp; :}
2283         |       multiplicative_expression:exp1 MULT unary_expression:exp2 {: 
2284                 ParseNode pn=new ParseNode("mult",parser.n());
2285                 pn.addChild(exp1);
2286                 pn.addChild(exp2);
2287                 RESULT=pn;
2288         :}
2289         |       multiplicative_expression:exp1 DIV unary_expression:exp2 {:
2290                 ParseNode pn=new ParseNode("div",parser.n());
2291                 pn.addChild(exp1);
2292                 pn.addChild(exp2);
2293                 RESULT=pn;
2294         :}
2295         |       multiplicative_expression:exp1 MOD unary_expression:exp2 {:
2296                 ParseNode pn=new ParseNode("mod",parser.n());
2297                 pn.addChild(exp1);
2298                 pn.addChild(exp2);
2299                 RESULT=pn;
2300         :}
2301         ;
2302 additive_expression ::=
2303                 multiplicative_expression:exp {: 
2304                         RESULT=exp; :}
2305         |       additive_expression:exp1 PLUS multiplicative_expression:exp2 {: 
2306                 ParseNode pn=new ParseNode("add",parser.n());
2307                 pn.addChild(exp1);
2308                 pn.addChild(exp2);
2309                 RESULT=pn;
2310         :}
2311         |       additive_expression:exp1 MINUS multiplicative_expression:exp2 {: 
2312                 ParseNode pn=new ParseNode("sub",parser.n());
2313                 pn.addChild(exp1);
2314                 pn.addChild(exp2);
2315                 RESULT=pn;
2316         :}
2317         ;
2318 shift_expression ::=
2319                 additive_expression:exp {: 
2320                         RESULT=exp; :}
2321         |       shift_expression:exp1 LSHIFT additive_expression:exp2 {: 
2322                 ParseNode pn=new ParseNode("leftshift",parser.n());
2323                 pn.addChild(exp1);
2324                 pn.addChild(exp2);
2325                 RESULT=pn;
2326         :}
2327         |       shift_expression:exp1 RSHIFT additive_expression:exp2 {: 
2328                 ParseNode pn=new ParseNode("rightshift",parser.n());
2329                 pn.addChild(exp1);
2330                 pn.addChild(exp2);
2331                 RESULT=pn;
2332         :}
2333         |       shift_expression:exp1 URSHIFT additive_expression:exp2 {:
2334                 ParseNode pn=new ParseNode("urightshift",parser.n());
2335                 pn.addChild(exp1);      
2336                 pn.addChild(exp2);      
2337                 RESULT=pn;
2338         :}
2339         ;
2340 relational_expression ::=
2341                 shift_expression:exp {: 
2342                         RESULT=exp; :}
2343         |       relational_expression:exp1 LT shift_expression:exp2 {:
2344                 ParseNode pn=new ParseNode("comp_lt",parser.n());
2345                 pn.addChild(exp1);
2346                 pn.addChild(exp2);
2347                 RESULT=pn;
2348         :}
2349         |       relational_expression:exp1 GT shift_expression:exp2 {:
2350                 ParseNode pn=new ParseNode("comp_gt",parser.n());
2351                 pn.addChild(exp1);
2352                 pn.addChild(exp2);
2353                 RESULT=pn;
2354         :}
2355         |       relational_expression:exp1 LTEQ shift_expression:exp2 {:
2356                 ParseNode pn=new ParseNode("comp_lte",parser.n());
2357                 pn.addChild(exp1);
2358                 pn.addChild(exp2);
2359                 RESULT=pn;
2360         :}
2361         |       relational_expression:exp1 GTEQ shift_expression:exp2 {:
2362                 ParseNode pn=new ParseNode("comp_gte",parser.n());
2363                 pn.addChild(exp1);
2364                 pn.addChild(exp2);
2365                 RESULT=pn;
2366         :}
2367         |       relational_expression:exp INSTANCEOF reference_type:type {: 
2368                 ParseNode pn=new ParseNode("instanceof",parser.n());
2369                 pn.addChild("exp").addChild(exp);
2370                 pn.addChild(type);
2371                 RESULT=pn;
2372         :}
2373         ;
2374
2375 equality_expression ::=
2376                 relational_expression:exp {: 
2377                         RESULT=exp; :}
2378         |       equality_expression:exp1 EQEQ relational_expression:exp2 {: 
2379                 ParseNode pn=new ParseNode("equal",parser.n());
2380                 pn.addChild(exp1);
2381                 pn.addChild(exp2);
2382                 RESULT=pn;
2383         :}
2384         |       equality_expression:exp1 NOTEQ relational_expression:exp2 {: 
2385                 ParseNode pn=new ParseNode("not_equal",parser.n());
2386                 pn.addChild(exp1);
2387                 pn.addChild(exp2);
2388                 RESULT=pn;
2389         :}
2390         ;
2391 and_expression ::=
2392                 equality_expression:exp {: 
2393                 RESULT=exp; :}
2394         |       and_expression:exp1 AND equality_expression:exp2 {: 
2395                 ParseNode pn=new ParseNode("bitwise_and",parser.n());
2396                 pn.addChild(exp1);
2397                 pn.addChild(exp2);
2398                 RESULT=pn;
2399         :}
2400         ;
2401 exclusive_or_expression ::=
2402                 and_expression:expr {: 
2403                         RESULT=expr;
2404                 :}
2405         |       exclusive_or_expression:exp1 XOR and_expression:exp2 {: 
2406                 ParseNode pn=new ParseNode("bitwise_xor",parser.n());
2407                 pn.addChild(exp1);
2408                 pn.addChild(exp2);
2409                 RESULT=pn;
2410 :}
2411         ;
2412 inclusive_or_expression ::=
2413                 exclusive_or_expression:exclor {: 
2414                         RESULT=exclor; :}
2415         |       inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {: 
2416                 ParseNode pn=new ParseNode("bitwise_or",parser.n());
2417                 pn.addChild(exp1);
2418                 pn.addChild(exp2);
2419                 RESULT=pn;
2420         :}
2421         ;
2422 conditional_and_expression ::=
2423                 inclusive_or_expression:inclor {: 
2424                         RESULT=inclor; :}
2425         |       conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
2426                 ParseNode pn=new ParseNode("logical_and",parser.n());
2427                 pn.addChild(exp1);
2428                 pn.addChild(exp2);
2429                 RESULT=pn;
2430         :}
2431         ;
2432 conditional_or_expression ::=
2433                 conditional_and_expression:condand {: 
2434                         RESULT=condand; :}
2435         |       conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {: 
2436                 ParseNode pn=new ParseNode("logical_or",parser.n());
2437                 pn.addChild(exp1);
2438                 pn.addChild(exp2);
2439                 RESULT=pn;
2440         :}
2441         ;
2442 conditional_expression ::=
2443                 conditional_or_expression:condor {: 
2444                         RESULT=condor; :}
2445         |       conditional_or_expression:condor QUESTION expression:exptrue
2446                         COLON conditional_expression:expfalse {: 
2447                         ParseNode pn=new ParseNode("tert",parser.n());
2448                         pn.addChild("cond").addChild(condor);
2449                         pn.addChild("trueexpr").addChild(exptrue);
2450                         pn.addChild("falseexpr").addChild(expfalse);
2451                         RESULT=pn;
2452                         :}
2453         ;
2454 getoffset_expression ::=
2455         GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
2456         ParseNode pn = new ParseNode("getoffset",parser.n());
2457         pn.addChild(type);
2458         pn.addChild("field").addChild(id);
2459         RESULT = pn;
2460       :}
2461    ;
2462  
2463 assignment_expression ::=
2464                 conditional_expression:expr {: 
2465                         RESULT=expr; :} |
2466                 assignment:assign {: 
2467                         RESULT=assign; :}             |
2468         getoffset_expression:expr {:
2469             RESULT=expr; :}
2470         ;
2471 // semantic check necessary here to ensure a valid left-hand side.
2472 // allowing a parenthesized variable here on the lhs was introduced in
2473 // JLS 2; thanks to Eric Blake for pointing this out.
2474 assignment ::=  postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
2475                 ParseNode pn=new ParseNode("assignment",parser.n());
2476                 pn.addChild("op").addChild(op);
2477                 ParseNode pnargs=pn.addChild("args");
2478                 pnargs.addChild(lvalue);
2479                 pnargs.addChild(rvalue);
2480                 RESULT=pn;
2481          :}
2482         ;
2483 assignment_operator ::=
2484                 EQ {: RESULT=new ParseNode("eq",parser.n()); :}
2485         |       MULTEQ {: RESULT=new ParseNode("multeq",parser.n()); :}
2486         |       DIVEQ {: RESULT=new ParseNode("diveq",parser.n()); :}
2487         |       MODEQ {: RESULT=new ParseNode("modeq",parser.n()); :}
2488         |       PLUSEQ {: RESULT=new ParseNode("pluseq",parser.n()); :}
2489         |       MINUSEQ {: RESULT=new ParseNode("minuseq",parser.n()); :}
2490         |       LSHIFTEQ {: RESULT=new ParseNode("lshifteq",parser.n()); :}
2491         |       RSHIFTEQ {: RESULT=new ParseNode("rshifteq",parser.n()); :}
2492         |       URSHIFTEQ {: RESULT=new ParseNode("urshifteq",parser.n()); :}
2493         |       ANDEQ {: RESULT=new ParseNode("andeq",parser.n()); :}
2494         |       XOREQ {: RESULT=new ParseNode("xoreq",parser.n()); :}
2495         |       OREQ {: RESULT=new ParseNode("oreq",parser.n()); :}
2496         ;
2497 expression_opt ::=
2498         {:      RESULT=new ParseNode("empty",parser.n()); :}
2499         |       expression:exp {: 
2500                 RESULT=exp; :}
2501         ;
2502 expression ::=  assignment_expression:exp {: 
2503                 RESULT=exp; :}
2504         ;
2505 // note that this constraint must be enforced during semantic checking
2506 // 'constant_expression' should include enumerated constants.
2507 constant_expression ::=
2508                 expression:exp 
2509                 {:
2510                     ParseNode pn = new ParseNode("constant_expression",parser.n());
2511                     pn.addChild(exp);
2512                     RESULT=pn;
2513                 :}
2514         ;
2515
2516
2517 genreach_statement ::=
2518                 GENREACH IDENTIFIER:graphName SEMICOLON {: 
2519                 ParseNode pn=new ParseNode("genreach",parser.n());
2520                 pn.addChild("graphName").addChild(graphName);
2521                 RESULT=pn; :}
2522         ;