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