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