Changes for William's Analysis
[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
107 // 19.2) The Syntactic Grammar
108 non terminal ParseNode goal;
109 // 19.3) Lexical Structure
110 non terminal ParseNode literal;
111 // 19.4) Types, Values, and Variables
112 non terminal ParseNode type, primitive_type, numeric_type;
113 non terminal ParseNode integral_type, floating_point_type;
114 non terminal ParseNode reference_type;
115 non terminal ParseNode class_or_interface_type;
116 non terminal ParseNode class_type;
117 //non terminal ParseNode interface_type;
118 non terminal ParseNode array_type;
119 // 19.5) Names
120 non terminal ParseNode name, simple_name, qualified_name;
121 // 19.6) Packages
122 non terminal ParseNode compilation_unit;
123 non terminal ParseNode package_declaration_opt, package_declaration;
124 non terminal ParseNode import_declarations_opt, import_declarations;
125 non terminal ParseNode type_declarations_opt, type_declarations;
126 non terminal ParseNode import_declaration;
127 non terminal ParseNode single_type_import_declaration;
128 non terminal ParseNode type_import_on_demand_declaration;
129 non terminal ParseNode type_declaration;
130 // 19.7) Productions used only in the LALR(1) grammar
131 non terminal ParseNode modifiers_opt, modifiers, modifier;
132 // 19.8.1) Class Declaration
133 non terminal ParseNode class_declaration, super, super_opt;
134 //non terminal interfaces, interfaces_opt, interface_type_list;
135 non terminal ParseNode class_body;
136 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
137 non terminal ParseNode class_body_declaration, class_member_declaration;
138 // 19.8.2) Field Declarations
139 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
140 non terminal ParseNode variable_declarator_id;
141 non terminal ParseNode variable_initializer;
142 // 19.8.3) Method Declarations
143 non terminal ParseNode method_declaration, method_header, method_declarator;
144 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
145 non terminal ParseNode formal_parameter;
146 //non terminal ParseNode throws_opt;
147 //non terminal ParseNode throws;
148 //non terminal ParseNode class_type_list;
149 non terminal ParseNode method_body;
150 // 19.8.4) Static Initializers
151 //non terminal ParseNode static_initializer;
152 // 19.8.5) Constructor Declarations
153 non terminal ParseNode constructor_declaration, constructor_declarator;
154 non terminal ParseNode constructor_body;
155 //non terminal ParseNode explicit_constructor_invocation;
156 // 19.9.1) Interface Declarations
157 //non terminal ParseNode interface_declaration;
158 //non terminal ParseNode extends_interfaces_opt, extends_interfaces;
159 //non terminal ParseNode interface_body;
160 //non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
161 //non terminal ParseNode interface_member_declaration, constant_declaration;
162 //non terminal ParseNode abstract_method_declaration;
163 // 19.10) Arrays
164 //non terminal ParseNode array_initializer;
165 //non terminal ParseNode variable_initializers;
166 // 19.11) Blocks and Statements
167 non terminal ParseNode block;
168 non terminal ParseNode block_statements_opt, block_statements, block_statement;
169 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
170 non terminal ParseNode statement, statement_no_short_if;
171 non terminal ParseNode statement_without_trailing_substatement;
172 non terminal ParseNode empty_statement;
173 //non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
174 non terminal ParseNode expression_statement, statement_expression;
175 non terminal ParseNode if_then_statement;
176 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
177 //non terminal ParseNode switch_statement, switch_block;
178 //non terminal ParseNode switch_block_statement_groups;
179 //non terminal ParseNode switch_block_statement_group;
180 //non terminal ParseNode switch_labels, switch_label;
181 non terminal ParseNode while_statement, while_statement_no_short_if;
182 non terminal ParseNode do_statement;
183 non terminal ParseNode for_statement, for_statement_no_short_if;
184 non terminal ParseNode for_init_opt, for_init;
185 non terminal ParseNode for_update_opt, for_update;
186 non terminal ParseNode statement_expression_list;
187 //non terminal ParseNode identifier_opt;
188 non terminal ParseNode break_statement, continue_statement;
189 non terminal ParseNode return_statement;
190 //non terminal ParseNode throw_statement;
191 //non terminal ParseNode synchronized_statement, try_statement;
192 //non terminal ParseNode catches_opt;
193 //non terminal ParseNode catches, catch_clause;
194 //non terminal ParseNode finally;
195 //non terminal ParseNode assert_statement;
196 // 19.12) Expressions
197 non terminal ParseNode primary, primary_no_new_array;
198 non terminal ParseNode class_instance_creation_expression;
199 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
200 non terminal ParseNode argument_list_opt, argument_list;
201 //non terminal ParseNode array_creation_init;
202 non terminal ParseNode array_creation_uninit;
203 non terminal ParseNode dim_exprs, dim_expr;
204 non terminal Integer dims_opt, dims;
205 non terminal ParseNode field_access, method_invocation;
206 non terminal ParseNode array_access;
207 non terminal ParseNode postfix_expression;
208 non terminal ParseNode postincrement_expression, postdecrement_expression;
209 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
210 non terminal ParseNode preincrement_expression, predecrement_expression;
211 non terminal ParseNode cast_expression;
212 non terminal ParseNode multiplicative_expression, additive_expression;
213 non terminal ParseNode shift_expression, relational_expression, equality_expression;
214 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
215 non terminal ParseNode conditional_and_expression, conditional_or_expression;
216 non terminal ParseNode conditional_expression;
217 non terminal ParseNode assignment_expression;
218 non terminal ParseNode assignment;
219 non terminal ParseNode assignment_operator;
220 non terminal ParseNode expression_opt, expression;
221 //non terminal ParseNode constant_expression;
222 //failure aware computation keywords
223 terminal FLAG;
224 terminal OPTIONAL;
225 terminal EXTERNAL;
226 terminal TAG;
227 terminal TASK;
228 terminal TASKEXIT;
229 non terminal ParseNode flag_declaration;
230 non terminal ParseNode task_declaration;
231 non terminal ParseNode task_parameter_list;
232 non terminal ParseNode task_parameter;
233 non terminal ParseNode flag_expression;
234 non terminal ParseNode flag_andexpression;
235 non terminal ParseNode flag_notexpression;
236 non terminal ParseNode task_exitstatement;
237 non terminal ParseNode flag_effects_opt;
238 non terminal ParseNode flag_effects;
239 non terminal ParseNode flag_effect;
240 non terminal ParseNode flag_list;
241 non terminal ParseNode flag_list_opt;
242 non terminal ParseNode flag_change;
243
244 non terminal ParseNode cons_checks_opt;
245 non terminal ParseNode cons_checks;
246 non terminal ParseNode cons_check;
247
248 non terminal ParseNode tag_variable_declaration_statement;
249 non terminal ParseNode tag_expression_list;
250 non terminal ParseNode tag_expression;
251 non terminal ParseNode tag_list;
252 non terminal ParseNode tag_list_opt;
253 non terminal ParseNode tag_change;
254
255 start with goal;
256
257
258 // Task declarations
259 task_declaration ::= 
260         TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN 
261         flag_effects_opt:feo
262         method_body:body 
263         {: 
264         ParseNode pn=new ParseNode("task_declaration");
265         pn.addChild("name").addChild(id);
266         pn.addChild(tpl);
267         pn.addChild(feo);
268         pn.addChild("body").addChild(body);     
269         RESULT=pn;
270         :};
271
272 task_parameter_list ::=
273                 task_parameter:fp {: 
274                 ParseNode pn=new ParseNode("task_parameter_list");
275                 pn.addChild(fp);
276                 RESULT=pn;
277         :}
278         |       task_parameter_list:fpl COMMA task_parameter:fp {: 
279                 fpl.addChild(fp);
280                 RESULT=fpl;
281         :}
282         ;
283
284 task_parameter ::=
285                 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
286                 ParseNode pn=new ParseNode("task_parameter");
287                 pn.addChild(type);
288                 pn.addChild(name);
289                 pn.addChild("flag").addChild(exp);
290                 RESULT=pn;
291         :} 
292         | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
293                 ParseNode pn=new ParseNode("task_parameter");
294                 pn.addChild(type);
295                 pn.addChild(name);
296                 pn.addChild("flag").addChild(exp);
297                 pn.addChild("tag").addChild(texp);
298                 RESULT=pn;
299         :}
300         | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
301                 ParseNode pn=new ParseNode("task_parameter");
302                 pn.addChild(type);
303                 pn.addChild(name);
304                 pn.addChild("tag").addChild(texp);
305                 RESULT=pn;
306         :}
307         | OPTIONAL task_parameter:fp {:
308                 ParseNode pn=new ParseNode("task_parameter");
309                 pn.addChild("optional").addChild(fp);
310                 RESULT=pn;
311         :}              
312         
313         ;
314
315 tag_expression_list ::= tag_expression:te {: 
316         ParseNode pn=new ParseNode("tag_expression_list");
317         pn.addChild(te);
318         RESULT=pn;
319         :}
320         | tag_expression_list:tel COMMA tag_expression:te {: 
321         tel.addChild(te);
322         RESULT=tel;
323         :}
324         ;
325
326 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {: 
327                 ParseNode pn=new ParseNode("tag_expression");
328                 pn.addChild("type").addChild(type);
329                 pn.addChild("single").addChild(id);
330                 RESULT=pn;
331         :}
332         ;
333
334 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
335         | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}  
336         | {: RESULT = new ParseNode("empty"); :}
337         ;
338
339 tag_list ::= tag_change:fc {: 
340                 ParseNode pn=new ParseNode("tag_list");
341                 pn.addChild(fc);
342                 RESULT=pn;
343         :}
344         | tag_list:fl COMMA tag_change:fc {: 
345                 fl.addChild(fc);
346                 RESULT=fl;
347         :};
348
349 tag_change ::= IDENTIFIER:id {: 
350                 RESULT=new ParseNode("name").addChild(id).getRoot();
351         :}
352         | NOT IDENTIFIER:id {: 
353                 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
354         :};
355
356 flag_expression ::= 
357         flag_andexpression:exp {: 
358                 RESULT=exp;
359         :}
360         | flag_expression:exp1 OROR flag_andexpression:exp2 {: 
361                 ParseNode pn=new ParseNode("or");
362                 pn.addChild(exp1);
363                 pn.addChild(exp2);
364                 RESULT=pn;
365         :}
366         ;
367
368 flag_andexpression ::= 
369         flag_notexpression:exp {: RESULT=exp; :}
370         | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {: 
371                 ParseNode pn=new ParseNode("and");
372                 pn.addChild(exp1);
373                 pn.addChild(exp2);
374                 RESULT=pn;
375         :}
376         ;
377
378 flag_notexpression ::=
379         NOT flag_notexpression:exp {: 
380                 ParseNode pn=new ParseNode("not");
381                 pn.addChild(exp);
382                 RESULT=pn;
383         :}
384         | LPAREN flag_expression:exp RPAREN {: 
385                 RESULT=exp;
386         :}
387         | IDENTIFIER:id {:
388                 ParseNode pn=new ParseNode("name");
389                 pn.addChild(id);
390                 RESULT=pn;
391         :}
392         ;
393
394 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {: 
395                 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
396         :};
397
398 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
399         | {: RESULT = new ParseNode("empty"); :}
400         ;
401
402 cons_checks ::= cons_check:cc {: 
403                 ParseNode pn=new ParseNode("cons_checks");
404                 pn.addChild(cc);
405                 RESULT=pn;
406         :}
407         |       cons_checks:ccs COMMA cons_check:cc {: 
408                 ccs.addChild(cc);
409                 RESULT=ccs;
410         :};
411
412 cons_check ::=  IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {: 
413                 ParseNode pn=new ParseNode("cons_check");
414                 pn.addChild("name").addChild("identifier").addChild(name);
415                 pn.addChild(args);
416                 RESULT=pn;
417         :};
418
419 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
420         | {: RESULT = new ParseNode("empty"); :}
421         ;
422
423 flag_effects ::= flag_effect:fe {: 
424                 ParseNode pn=new ParseNode("flag_effects_list");
425                 pn.addChild(fe);
426                 RESULT=pn;
427         :}
428         |       flag_effects:fes COMMA flag_effect:fe {: 
429                 fes.addChild(fe);
430                 RESULT=fes;
431         :};
432
433 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {: 
434                 ParseNode pn=new ParseNode("flag_effect");
435                 pn.addChild("name").addChild(id);
436                 pn.addChild(fl);
437                 pn.addChild(tlo);
438                 RESULT=pn;
439         :}
440         | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {: 
441                 ParseNode pn=new ParseNode("flag_effect");
442                 pn.addChild("name").addChild(id);
443                 pn.addChild(tl);
444                 RESULT=pn;
445         :};
446
447 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
448         | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}  
449         | 
450         {: RESULT = new ParseNode("empty"); :}
451         ;
452
453 flag_list ::= flag_change:fc {: 
454                 ParseNode pn=new ParseNode("flag_list");
455                 pn.addChild(fc);
456                 RESULT=pn;
457         :}
458         |       flag_list:fl COMMA flag_change:fc {: 
459                 fl.addChild(fc);
460                 RESULT=fl;
461         :};
462
463 flag_change ::= IDENTIFIER:id {: 
464                 RESULT=new ParseNode("name").addChild(id).getRoot();
465         :} |
466         NOT IDENTIFIER:id {: 
467                 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
468         :};
469
470 // 19.2) The Syntactic Grammar
471 goal ::=        compilation_unit:cu
472         {:
473         RESULT = cu;
474         :}
475         ;
476
477 // 19.3) Lexical Structure.
478
479
480 literal ::=     INTEGER_LITERAL:integer_lit
481         {:
482                 ParseNode pn=new ParseNode("literal");
483                 pn.addChild("integer").setLiteral(integer_lit);
484                 RESULT=pn;
485         :}
486         |       FLOATING_POINT_LITERAL:float_lit
487         {:
488                 ParseNode pn=new ParseNode("literal");
489                 pn.addChild("float").setLiteral(float_lit);
490                 RESULT=pn;
491         :}
492         |       BOOLEAN_LITERAL:boolean_lit
493         {:
494                 ParseNode pn=new ParseNode("literal");
495                 pn.addChild("boolean").setLiteral(boolean_lit);
496                 RESULT=pn;
497         :}
498         |       CHARACTER_LITERAL:char_lit
499         {:
500                 ParseNode pn=new ParseNode("literal");
501                 pn.addChild("char").setLiteral(char_lit);
502                 RESULT=pn;
503         :}
504         |       STRING_LITERAL:string_lit
505         {:
506                 ParseNode pn=new ParseNode("literal");
507                 pn.addChild("string").setLiteral(string_lit);
508                 RESULT=pn;
509         :}
510         |       NULL_LITERAL 
511         {:
512                 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
513         :}
514         ;
515
516 // 19.4) Types, Values, and Variables
517 type    ::=     primitive_type:type {: RESULT=type; :}
518         |       reference_type:type {: RESULT=type; :}
519         ;
520
521 primitive_type ::=
522                 numeric_type:type {: RESULT=type; :}
523         |       BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
524         ;
525 numeric_type::= integral_type:type {: RESULT=type; :}
526         |       floating_point_type:type {: RESULT=type; :}
527         ;
528 integral_type ::= 
529                 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
530         |       SHORT  {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
531         |       INT  {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
532         |       LONG  {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
533         |       CHAR  {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
534         ;
535 floating_point_type ::= 
536                 FLOAT  {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
537         |       DOUBLE  {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
538         ;
539
540 reference_type ::=
541                 class_or_interface_type:type {: RESULT=type; :}
542         |       array_type:type {: RESULT=type; :}
543         ;
544 class_or_interface_type ::= name:name {: 
545         RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot(); 
546         :};
547
548 class_type ::=  class_or_interface_type:type {: RESULT=type; :};
549 //interface_type ::= class_or_interface_type;
550
551 array_type ::=  primitive_type:prim dims:dims {: 
552                 ParseNode pn=(new ParseNode("type")).addChild("array");
553                 pn.addChild("basetype").addChild(prim);
554                 pn.addChild("dims").setLiteral(dims);
555                 RESULT=pn.getRoot();
556         :}
557         |       name:name dims:dims {: 
558                 ParseNode pn=(new ParseNode("type")).addChild("array");
559                 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
560                 pn.addChild("dims").setLiteral(dims);
561                 RESULT=pn.getRoot();
562         :}
563         ;
564
565 // 19.5) Names
566 name    ::=     simple_name:name {: RESULT=name; :}
567         |       qualified_name:name {: RESULT=name; :}
568         ;
569 simple_name ::= IDENTIFIER:id {: 
570         RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot(); 
571         :}
572         ;
573 qualified_name ::= name:name DOT IDENTIFIER:id {: 
574         ParseNode pn=new ParseNode("name");
575         pn.addChild("base").addChild(name);
576         pn.addChild("identifier").addChild(id);
577         RESULT=pn;
578         :}
579         ;
580
581 // 19.6) Packages
582 compilation_unit ::=
583                 package_declaration_opt:pdo
584                 import_declarations_opt:ido
585                 type_declarations_opt:tdo {: 
586                 ParseNode pn=new ParseNode("compilation_unit");
587                 pn.addChild(tdo);
588                 pn.addChild("packages").addChild(pdo);
589                 pn.addChild("imports").addChild(ido);
590                 RESULT=pn;
591                 :}
592                 ;
593 package_declaration_opt ::= package_declaration:pdo {:
594                 RESULT=pdo;
595         :} |
596         {: RESULT=new ParseNode("empty"); :}
597 ;
598
599 import_declarations_opt ::= import_declarations:ido {: 
600                 RESULT=ido;
601         :} | 
602         {: RESULT=new ParseNode("empty"); :}
603 ;
604 type_declarations_opt   ::= type_declarations:tds {:
605                 RESULT=tds;
606                 :}   | 
607         {: RESULT=new ParseNode("empty"); :}
608         ;
609
610 import_declarations ::=
611                import_declaration:id {: 
612                 ParseNode pn=new ParseNode("import_decls_list");
613                 pn.addChild(id);
614                 RESULT=pn;
615         :}
616        |       import_declarations:ids import_declaration:id {: 
617                 ids.addChild(id);
618                 RESULT=ids;
619         :}
620        ;
621
622 type_declarations ::= 
623                 type_declaration:td {:
624                 ParseNode pn=new ParseNode("type_declaration_list");
625                 pn.addChild(td);
626                 RESULT=pn;
627                 :}
628         |       type_declarations:tds type_declaration:td {:
629                 tds.addChild(td);
630                 RESULT=tds;
631                 :}
632         ;
633
634 package_declaration ::=
635                PACKAGE name:name SEMICOLON {: 
636         ParseNode pn=new ParseNode("package");
637         pn.addChild(name);
638         RESULT=pn;
639         :}
640        ;
641 import_declaration ::=
642                single_type_import_declaration:sid {: RESULT=sid; :}
643        |       type_import_on_demand_declaration:iod {: RESULT=iod; :}
644        ;
645 single_type_import_declaration ::=
646                IMPORT name:name SEMICOLON {: 
647         ParseNode pn=new ParseNode("import_single");
648         pn.addChild(name);
649         RESULT=pn;
650 :}
651        ;
652 type_import_on_demand_declaration ::=
653                IMPORT name:name DOT MULT SEMICOLON {:
654         ParseNode pn=new ParseNode("import_ondemand");
655         pn.addChild(name);
656         RESULT=pn;
657         :}       
658         ;
659
660 type_declaration ::=
661                 class_declaration:cd 
662                 {:
663                         RESULT=cd;
664                 :}
665         |       task_declaration:td 
666                 {:
667                         RESULT=td;
668                 :}
669 //      |       interface_declaration
670         |       SEMICOLON {: RESULT=new ParseNode("empty"); :}
671         ;
672
673 // 19.7) Productions used only in the LALR(1) grammar
674 modifiers_opt::=
675         {: RESULT=new ParseNode("empty"); :}
676         |       modifiers:mo {: 
677                 RESULT=mo;
678         :}
679         ;
680 modifiers ::=   modifier:mo {: 
681                 ParseNode pn=new ParseNode("modifier_list");
682                 pn.addChild(mo);
683                 RESULT=pn;
684         :}
685         |       modifiers:mos modifier:mo {: 
686                 mos.addChild(mo);
687                 RESULT=mos;
688         :}
689         ;
690 modifier ::=    
691         PUBLIC {: RESULT=new ParseNode("public"); :}|
692         PROTECTED {: RESULT=new ParseNode("protected"); :}|
693         PRIVATE {: RESULT=new ParseNode("private"); :}|
694         STATIC {: RESULT=new ParseNode("static"); :} |
695 //      ABSTRACT |
696         FINAL {: RESULT=new ParseNode("final"); :}|
697         NATIVE {: RESULT=new ParseNode("native"); :} |
698         SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :}
699 //      TRANSIENT | 
700 //      VOLATILE |
701 //      STRICTFP // note that semantic analysis must check that the
702                          // context of the modifier allows strictfp.
703         ;
704
705 // 19.8) Classes
706
707 // 19.8.1) Class Declaration:
708 class_declaration ::= 
709         modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so //interfaces_opt
710 class_body:body 
711         {:
712         ParseNode pn=new ParseNode("class_declaration");
713         pn.addChild("modifiers").addChild(mo);
714         pn.addChild("name").addChild(id);
715         pn.addChild("super").addChild(so);
716         pn.addChild("classbody").addChild(body);
717         RESULT=pn;
718         :}
719         ;
720 super ::=       EXTENDS class_type:classtype {: 
721                 RESULT=classtype;
722         :}
723         ;
724 super_opt ::=   
725         {: RESULT=new ParseNode("empty"); :}
726         |       super:su {: 
727                 RESULT=su;
728         :}
729         ;
730
731 //interfaces ::= IMPLEMENTS interface_type_list
732 //       ;
733 //interfaces_opt::=
734 //       |       interfaces
735 //       ;
736 //interface_type_list ::=
737 //               interface_type
738 //       |       interface_type_list COMMA interface_type
739 //       ;
740
741 class_body ::=  LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
742         ;
743
744 class_body_declarations_opt ::= 
745         {: RESULT=new ParseNode("empty"); :}
746         |       class_body_declarations:cbd {: RESULT=cbd; :};
747
748 class_body_declarations ::= 
749                 class_body_declaration:cbd {: 
750                         ParseNode pn=new ParseNode("class_body_declaration_list");
751                         pn.addChild(cbd);
752                         RESULT=pn;
753                 :}
754         |       class_body_declarations:cbds class_body_declaration:cbd {: 
755                         cbds.addChild(cbd);
756                         RESULT=cbds;
757                 :}
758         ;
759
760 class_body_declaration ::=
761                 class_member_declaration:member {: 
762                 RESULT=(new ParseNode("member")).addChild(member).getRoot();
763         :}
764 //      |       static_initializer
765         |       constructor_declaration:constructor {: 
766                 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
767         :}
768         |       block:block {:
769                 RESULT=(new ParseNode("block")).addChild(block).getRoot();
770 :}
771         ;
772 class_member_declaration ::=
773         //failure aware computation
774         flag_declaration:flag {: 
775         RESULT=(new ParseNode("flag")).addChild(flag).getRoot(); 
776         :}
777         |
778         field_declaration:field {: 
779         RESULT=(new ParseNode("field")).addChild(field).getRoot(); 
780         :}
781         |       method_declaration:method {:
782         RESULT=(new ParseNode("method")).addChild(method).getRoot(); 
783         :}
784         /* repeat the prod for 'class_declaration' here: */
785 //      |       modifiers_opt CLASS IDENTIFIER super_opt class_body
786 //      |       interface_declaration
787         |       SEMICOLON       {: RESULT=new ParseNode("empty"); :}
788         ;
789
790 //Failure aware computation
791 flag_declaration ::= 
792                 FLAG IDENTIFIER:id SEMICOLON {: 
793                 ParseNode pn=new ParseNode("flag_declaration");
794                 pn.addChild("name").addChild(id);
795                 RESULT=pn;
796         :}      |
797                 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {: 
798                 ParseNode pn=new ParseNode("flag_declaration");
799                 pn.addChild("name").addChild(id);
800                 pn.addChild("external");
801                 RESULT=pn;
802         :}
803         ;
804
805 // 19.8.2) Field Declarations
806 field_declaration ::= 
807                 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {: 
808                 ParseNode pn=new ParseNode("field_declaration");
809                 pn.addChild("modifier").addChild(mo);
810                 pn.addChild("type").addChild(type);
811                 pn.addChild("variables").addChild(var);
812                 RESULT=pn;
813         :}
814         ;
815
816 variable_declarators ::=
817                 variable_declarator:vd {: 
818                 ParseNode pn=new ParseNode("variable_declarators_list");
819                 pn.addChild(vd);
820                 RESULT=pn;
821         :}
822         |       variable_declarators:vds COMMA variable_declarator:vd {:
823                 vds.addChild(vd);
824                 RESULT=vds;
825         :}
826         ;
827 variable_declarator ::=
828                 variable_declarator_id:id {:
829                 ParseNode pn=new ParseNode("variable_declarator");
830                 pn.addChild(id);
831                 RESULT=pn;
832         :}
833         |       variable_declarator_id:id EQ variable_initializer:init {: 
834                 ParseNode pn=new ParseNode("variable_declarator");
835                 pn.addChild(id);
836                 pn.addChild("initializer").addChild(init);
837                 RESULT=pn;
838         :}
839         ;
840 variable_declarator_id ::=
841                 IDENTIFIER:id {: 
842                 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
843         |       variable_declarator_id:id LBRACK RBRACK {:
844                 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
845         ;
846 variable_initializer ::=
847                 expression:exp {: RESULT=exp; :}
848 //      |       array_initializer
849         ;
850
851 // 19.8.3) Method Declarations
852 method_declaration ::=
853                 method_header:header method_body:body {:
854                 ParseNode pn=new ParseNode("method_declaration");
855                 pn.addChild(header);
856                 pn.addChild("body").addChild(body);
857                 RESULT=pn;
858         :}
859         ;
860 method_header ::=
861                 modifiers_opt:mo type:type method_declarator:decl //throws_opt 
862         {:
863                 ParseNode pn=new ParseNode("method_header");
864                 pn.addChild("modifiers").addChild(mo);
865                 pn.addChild("returntype").addChild(type);
866                 pn.addChild(decl);
867                 RESULT=pn;
868         :}
869         |       modifiers_opt:mo VOID method_declarator:decl //throws_opt
870         {:
871                 ParseNode pn=new ParseNode("method_header");
872                 pn.addChild("modifiers").addChild(mo);
873                 pn.addChild(decl);
874                 RESULT=pn;
875         :}
876         ;
877 method_declarator ::=
878                 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {: 
879                 ParseNode pn=new ParseNode("method_declarator");
880                 pn.addChild("name").addChild(id);
881                 pn.addChild("parameters").addChild(params);
882                 RESULT=pn;
883         :}
884 //      |       method_declarator LBRACK RBRACK // deprecated
885 // be careful; the above production also allows 'void foo() []'
886         ;
887 formal_parameter_list_opt ::=
888         {: RESULT=new ParseNode("empty"); :}
889         |       formal_parameter_list:fpl {: 
890                 RESULT=fpl;
891         :}
892         ;
893 formal_parameter_list ::=
894                 formal_parameter:fp {: 
895                 ParseNode pn=new ParseNode("formal_parameter_list");
896                 pn.addChild(fp);
897                 RESULT=pn;
898         :}
899         |       formal_parameter_list:fpl COMMA formal_parameter:fp {: 
900                 fpl.addChild(fp);
901                 RESULT=fpl;
902         :}
903         ;
904 formal_parameter ::=
905                 type:type variable_declarator_id:name {:
906                 ParseNode pn=new ParseNode("formal_parameter");
907                 pn.addChild(type);
908                 pn.addChild(name);
909                 RESULT=pn;
910         :}
911         |
912                 TAG variable_declarator_id:name {:
913                 ParseNode pn=new ParseNode("tag_parameter");
914                 pn.addChild(name);
915                 RESULT=pn;
916         :}
917 //      |       FINAL type variable_declarator_id
918         ;
919 //throws_opt ::=        
920 //      |       throws
921 //      ;
922 //throws ::=    THROWS class_type_list
923 //      ;
924 //class_type_list ::=
925 //              class_type
926 //      |       class_type_list COMMA class_type
927 //      ;
928 method_body ::= block:block {: 
929                 RESULT=block;
930         :}
931         |       SEMICOLON       {: RESULT=new ParseNode("empty"); :}
932         ;
933
934 // 19.8.4) Static Initializers
935 //static_initializer ::=
936 //              STATIC block
937 //      ;
938
939 // 19.8.5) Constructor Declarations
940 constructor_declaration ::=
941                 modifiers_opt:mo constructor_declarator:cd
942 //throws_opt 
943                         constructor_body:body   {:
944                 ParseNode pn=new ParseNode("constructor_declaration");
945                 pn.addChild("modifiers").addChild(mo);
946                 pn.addChild(cd);
947                 pn.addChild("body").addChild(body);
948                 RESULT=pn;
949         :}
950         ;
951 constructor_declarator ::=
952                 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {: 
953                 ParseNode pn=new ParseNode("constructor_declarator");
954                 pn.addChild(name);
955                 pn.addChild("parameters").addChild(fplo);
956                 RESULT=pn;
957         :}
958         ;
959 constructor_body ::=
960 //              LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE |
961 //              LBRACE explicit_constructor_invocation RBRACE |
962                 LBRACE block_statements:block RBRACE {: 
963                 ParseNode pn=new ParseNode("constructor_body");
964                 pn.addChild(block);
965                 RESULT=pn;
966         :}
967         |       LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
968         ;
969 //explicit_constructor_invocation ::=
970 //              THIS LPAREN argument_list_opt RPAREN SEMICOLON
971 //      |       SUPER LPAREN argument_list_opt RPAREN SEMICOLON
972 //      |       primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
973 //      |       primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
974 //      ;
975
976 // 19.9) Interfaces
977
978 // 19.9.1) Interface Declarations
979 //interface_declaration ::=
980 //               modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
981 //                       interface_body
982 //       ;
983 //extends_interfaces_opt ::=
984 //       |       extends_interfaces
985 //       ;
986 //extends_interfaces ::=
987 //               EXTENDS interface_type
988 //       |       extends_interfaces COMMA interface_type
989 //       ;
990 //interface_body ::=
991 //               LBRACE interface_member_declarations_opt RBRACE
992 //       ;
993 //interface_member_declarations_opt ::=
994 //       |       interface_member_declarations
995 //       ;
996 //interface_member_declarations ::=
997 //               interface_member_declaration
998 //       |       interface_member_declarations interface_member_declaration
999 //       ;
1000 //interface_member_declaration ::=
1001 //               constant_declaration
1002 //       |       abstract_method_declaration
1003 //       |       class_declaration
1004 //       |       interface_declaration
1005 //       |       SEMICOLON
1006 //       ;
1007 //constant_declaration ::=
1008 //               field_declaration
1009 //       // need to semantically check that modifiers of field declaration
1010 //       // include only PUBLIC, STATIC, or FINAL.  Other modifiers are
1011 //       // disallowed.
1012 //       ;
1013 //abstract_method_declaration ::=
1014 //               method_header SEMICOLON
1015 //       ;
1016
1017
1018 // 19.10) Arrays
1019 //array_initializer ::=
1020 //              LBRACE variable_initializers COMMA RBRACE
1021 //      |       LBRACE variable_initializers RBRACE
1022 //      |       LBRACE COMMA RBRACE
1023 //      |       LBRACE RBRACE
1024 //      ;
1025 //variable_initializers ::=
1026 //              variable_initializer
1027 //      |       variable_initializers COMMA variable_initializer
1028 //      ;
1029
1030 // 19.11) Blocks and Statements
1031 block ::=       LBRACE block_statements_opt:bso RBRACE {: 
1032         RESULT=bso;
1033         :}
1034         ;
1035 block_statements_opt ::=
1036         {: RESULT=new ParseNode("empty"); :}
1037         |       block_statements:bs {: 
1038         RESULT=bs;
1039         :}
1040         ;
1041 block_statements ::=
1042                 block_statement:bs {:
1043         ParseNode pn=new ParseNode("block_statement_list");
1044         pn.addChild(bs);
1045         RESULT=pn;
1046         :}
1047         |       block_statements:bss block_statement:bs {: 
1048         bss.addChild(bs);
1049         RESULT=bss;
1050         :}
1051         ;
1052 block_statement ::=
1053         tag_variable_declaration_statement:tvds {:
1054                 RESULT=tvds;
1055         :}              
1056         |       local_variable_declaration_statement:lvds {: 
1057                 RESULT=lvds;
1058         :}
1059         |       statement:statement {: 
1060                 RESULT=statement;
1061         :}
1062 //      |       class_declaration
1063 //      |       interface_declaration
1064         ;
1065 tag_variable_declaration_statement ::=
1066                 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {: 
1067                 ParseNode pn=new ParseNode("tag_declaration");
1068                 pn.addChild("single").addChild(id);
1069                 pn.addChild("type").addChild(type);
1070                 RESULT=pn;
1071         :}
1072         ;
1073 local_variable_declaration_statement ::=
1074                 local_variable_declaration:lvd SEMICOLON {: 
1075                 RESULT=lvd;
1076         :}
1077         ;
1078 local_variable_declaration ::=
1079                 type:type variable_declarators:var {: 
1080                 ParseNode pn=new ParseNode("local_variable_declaration");
1081                 pn.addChild(type);
1082                 pn.addChild(var);
1083                 RESULT=pn;
1084 :}
1085 //      |       FINAL type variable_declarators
1086         ;
1087 statement ::=   statement_without_trailing_substatement:st {: 
1088                 RESULT=st;
1089         :}
1090 //      |       labeled_statement:st {: RESULT=st; :}
1091         |       if_then_statement:st {: RESULT=st; :}
1092         |       if_then_else_statement:st {: RESULT=st; :}
1093         |       while_statement:st {: RESULT=st; :}
1094         |       for_statement:st {: RESULT=st; :}
1095         ;
1096 statement_no_short_if ::=
1097                 statement_without_trailing_substatement:st {: RESULT=st; :}
1098 //      |       labeled_statement_no_short_if:st {: RESULT=st; :}
1099         |       if_then_else_statement_no_short_if:st {: RESULT=st; :}
1100         |       while_statement_no_short_if:st {: RESULT=st; :}
1101         |       for_statement_no_short_if:st {: RESULT=st; :}
1102         ;
1103 statement_without_trailing_substatement ::=
1104                 block:st {: RESULT=st; :}
1105         |       empty_statement:st {: RESULT=st; :}
1106         |       expression_statement:st {: RESULT=st; :}
1107 //      |       switch_statement
1108         |       do_statement:dos {:RESULT=dos; :}
1109         |       break_statement:st {: RESULT=st; :}
1110         |       continue_statement:st {: RESULT=st; :}
1111         |       return_statement:st {: RESULT=st; :}
1112         |       task_exitstatement:st {: RESULT=st; :}
1113 //      |       synchronized_statement
1114 //      |       throw_statement
1115 //      |       try_statement
1116 //      |       assert_statement
1117         ;
1118 empty_statement ::=
1119                 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1120         ;
1121 //labeled_statement ::=
1122 //              IDENTIFIER COLON statement
1123 //      ;
1124 //labeled_statement_no_short_if ::=
1125 //              IDENTIFIER COLON statement_no_short_if
1126 //      ;
1127 expression_statement ::=
1128                 statement_expression:se SEMICOLON {: 
1129                 ParseNode pn=new ParseNode("expression");
1130                 pn.addChild(se);
1131                 RESULT=pn; :}
1132         ;
1133 statement_expression ::=
1134                 assignment:st {: RESULT=st; :}
1135         |       preincrement_expression:st {: RESULT=st; :}
1136         |       predecrement_expression:st {: RESULT=st; :}
1137         |       postincrement_expression:st {: RESULT=st; :}
1138         |       postdecrement_expression:st {: RESULT=st; :}
1139         |       method_invocation:st {: RESULT=st; :}
1140         |       class_instance_creation_expression:st {: RESULT=st; :}
1141         ;
1142 if_then_statement ::=
1143                 IF LPAREN expression:exp RPAREN statement:st {: 
1144                 ParseNode pn=new ParseNode("ifstatement");
1145                 pn.addChild("condition").addChild(exp);
1146                 pn.addChild("statement").addChild(st);
1147                 RESULT=pn;
1148         :}
1149         ;
1150 if_then_else_statement ::=
1151                 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1152                         ELSE statement:else_st {:
1153                 ParseNode pn=new ParseNode("ifstatement");
1154                 pn.addChild("condition").addChild(exp);
1155                 pn.addChild("statement").addChild(st);
1156                 pn.addChild("else_statement").addChild(else_st);
1157                 RESULT=pn;
1158         :}
1159         ;
1160 if_then_else_statement_no_short_if ::=
1161                 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1162                         ELSE statement_no_short_if:else_st {:
1163                 ParseNode pn=new ParseNode("ifstatement");
1164                 pn.addChild("condition").addChild(exp);
1165                 pn.addChild("statement").addChild(st);
1166                 pn.addChild("else_statement").addChild(else_st);
1167                 RESULT=pn;
1168         :}
1169         ;
1170 //switch_statement ::=
1171 //              SWITCH LPAREN expression RPAREN switch_block
1172 //      ;
1173 //switch_block ::=
1174 //              LBRACE switch_block_statement_groups switch_labels RBRACE
1175 //      |       LBRACE switch_block_statement_groups RBRACE
1176 //      |       LBRACE switch_labels RBRACE
1177 //      |       LBRACE RBRACE
1178 //      ;
1179 //switch_block_statement_groups ::=
1180 //              switch_block_statement_group
1181 //      |       switch_block_statement_groups switch_block_statement_group
1182 //      ;
1183 //switch_block_statement_group ::=
1184 //              switch_labels block_statements
1185 //      ;
1186 //switch_labels ::=
1187 //              switch_label
1188 //      |       switch_labels switch_label
1189 //      ;
1190 //switch_label ::=
1191 //              CASE constant_expression COLON
1192 //      |       DEFAULT COLON
1193 //      ;
1194
1195 while_statement ::=
1196                 WHILE LPAREN expression:exp RPAREN statement:st {: 
1197                 ParseNode pn=new ParseNode("whilestatement");
1198                 pn.addChild("condition").addChild(exp);
1199                 pn.addChild("statement").addChild(st);
1200                 RESULT=pn;
1201         :}
1202         ;
1203 while_statement_no_short_if ::=
1204                 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1205                 ParseNode pn=new ParseNode("whilestatement");
1206                 pn.addChild("condition").addChild(exp);
1207                 pn.addChild("statement").addChild(st);
1208                 RESULT=pn;
1209                 :}
1210         ;
1211 do_statement ::=
1212                 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {: 
1213                 ParseNode pn=new ParseNode("dowhilestatement");
1214                 pn.addChild("condition").addChild(exp);
1215                 pn.addChild("statement").addChild(st);
1216                 RESULT=pn;
1217         :}
1218         ;
1219 for_statement ::=
1220                 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1221                         for_update_opt:update RPAREN statement:st {: 
1222                 ParseNode pn=new ParseNode("forstatement");
1223                 pn.addChild("initializer").addChild(init);
1224                 pn.addChild("condition").addChild(exp);
1225                 pn.addChild("update").addChild(update);
1226                 pn.addChild("statement").addChild(st);
1227                 RESULT=pn;
1228                 :}
1229         ;
1230 for_statement_no_short_if ::=
1231                 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1232                         for_update_opt:update RPAREN statement_no_short_if:st {:
1233                 ParseNode pn=new ParseNode("forstatement");
1234                 pn.addChild("initializer").addChild(init);
1235                 pn.addChild("condition").addChild(exp);
1236                 pn.addChild("update").addChild(update);
1237                 pn.addChild("statement").addChild(st);
1238                 RESULT=pn;
1239                 :}
1240         ;
1241 for_init_opt ::=
1242         {: RESULT=new ParseNode("empty"); :}
1243         |       for_init:init {: RESULT=init; :}
1244         ;
1245 for_init ::=    statement_expression_list:list {: RESULT=list; :}
1246         |       local_variable_declaration:decl {: RESULT=decl; :}
1247         ;
1248 for_update_opt ::=
1249         {: RESULT=new ParseNode("empty"); :}
1250         |       for_update:update {: RESULT=update; :}
1251         ;
1252 for_update ::=  statement_expression_list:list {: RESULT=list; :}
1253         ;
1254 statement_expression_list ::=
1255                 statement_expression:expr {: 
1256                 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1257         :}
1258         |       statement_expression_list:list COMMA statement_expression:expr {: 
1259                 list.addChild(expr);
1260                 RESULT=list;
1261         :}
1262         ;
1263
1264 //identifier_opt ::= 
1265 //      |       IDENTIFIER
1266 //      ;
1267
1268 break_statement ::=
1269                 BREAK
1270 //identifier_opt 
1271 SEMICOLON {: RESULT=new ParseNode("break"); :}
1272         ;
1273
1274 continue_statement ::=
1275                 CONTINUE  
1276 //identifier_opt 
1277 SEMICOLON
1278 {: RESULT=new ParseNode("continue"); :}
1279         ;
1280 return_statement ::=
1281                 RETURN expression_opt:exp SEMICOLON {: 
1282         RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1283         ;
1284 //throw_statement ::=
1285 //              THROW expression SEMICOLON
1286 //      ;
1287 //synchronized_statement ::=
1288 //              SYNCHRONIZED LPAREN expression RPAREN block
1289 //      ;
1290 //try_statement ::=
1291 //              TRY block catches
1292 //      |       TRY block catches_opt finally
1293 //      ;
1294 //catches_opt ::=
1295 //      |       catches
1296 //      ;
1297 //catches ::=   catch_clause
1298 //      |       catches catch_clause
1299 //      ;
1300 //catch_clause ::=
1301 //              CATCH LPAREN formal_parameter RPAREN block
1302 //      ;
1303 //finally ::=   FINALLY block
1304 //      ;
1305 //assert_statement ::=
1306 //              ASSERT expression SEMICOLON
1307 //      |       ASSERT expression COLON expression SEMICOLON
1308 //      ;
1309
1310 // 19.12) Expressions
1311 primary ::=     primary_no_new_array:st {: 
1312                 RESULT=st; :}
1313 //      |       array_creation_init:st {: 
1314 //              RESULT=st;
1315 //      :}
1316         |       array_creation_uninit:st {:
1317                 RESULT=st;
1318         :}
1319         ;
1320 primary_no_new_array ::=
1321                 literal:lit {: RESULT=lit; :}
1322         |       THIS {: RESULT=new ParseNode("this"); :}
1323         |       LPAREN expression:exp RPAREN {: RESULT=exp; :}
1324         |       class_instance_creation_expression:exp {: RESULT=exp; :}
1325         |       field_access:exp {: RESULT=exp; :}
1326         |       method_invocation:exp {: RESULT=exp; :}
1327         |       array_access:exp {: RESULT=exp; :}
1328 //      |       primitive_type DOT CLASS
1329 //      |       VOID DOT CLASS
1330 //      |       array_type DOT CLASS
1331 //      |       name DOT CLASS
1332 //      |       name DOT THIS
1333         ;
1334 class_instance_creation_expression ::=
1335                 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {: 
1336                 ParseNode pn=new ParseNode("createobject");
1337                 pn.addChild(type);
1338                 pn.addChild(args);
1339                 pn.addChild(feo);
1340                 RESULT=pn;
1341         :}
1342         | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {: 
1343                 ParseNode pn=new ParseNode("createobject");
1344                 pn.addChild(type);
1345                 pn.addChild(args);
1346                 pn.addChild(tl);
1347                 RESULT=pn;
1348         :}
1349         | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {: 
1350                 ParseNode pn=new ParseNode("createobject");
1351                 pn.addChild(type);
1352                 pn.addChild(args);
1353                 pn.addChild(fl);
1354                 pn.addChild(tl);
1355                 RESULT=pn;
1356         :}
1357
1358 //      |       NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1359 //      |       primary DOT NEW IDENTIFIER
1360 //                      LPAREN argument_list_opt RPAREN {: 
1361 //              
1362 //      :}
1363 //      |       primary DOT NEW IDENTIFIER
1364 //                      LPAREN argument_list_opt RPAREN class_body
1365 //      |       name DOT NEW IDENTIFIER
1366 //                      LPAREN argument_list_opt RPAREN
1367 //      |       name DOT NEW IDENTIFIER
1368 //                      LPAREN argument_list_opt RPAREN class_body
1369         ;
1370 cons_argument_list_opt ::=
1371         {: RESULT=new ParseNode("empty"); :}
1372         |       cons_argument_list:args {: RESULT=args; :}
1373         ;
1374
1375 cons_argument_list ::=
1376                 IDENTIFIER:id COLON expression:exp {:
1377                 ParseNode pn=new ParseNode("cons_argument_list");
1378                 ParseNode pnarg=pn.addChild("binding");
1379                 pnarg.addChild("var").addChild(id);
1380                 pnarg.addChild("exp").addChild(exp);
1381                 RESULT=pn;
1382         :}
1383         |       argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1384                 ParseNode pnarg=new ParseNode("binding");
1385                 pnarg.addChild("var").addChild(id);
1386                 pnarg.addChild("exp").addChild(exp);
1387                 list.addChild(pnarg);
1388                 RESULT=list;
1389         :}
1390         ;
1391
1392 argument_list_opt ::=
1393         {: RESULT=new ParseNode("empty"); :}
1394         |       argument_list:args {: RESULT=args; :}
1395         ;
1396
1397 argument_list ::=
1398                 expression:exp {:
1399                 ParseNode pn=new ParseNode("argument_list");
1400                 pn.addChild(exp);
1401                 RESULT=pn;
1402         :}
1403         |       argument_list:list COMMA expression:exp {:
1404                 list.addChild(exp);
1405                 RESULT=list;
1406         :}
1407         ;
1408 array_creation_uninit ::=
1409                 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
1410                 ParseNode pn=new ParseNode("createarray");
1411                 pn.addChild(type);
1412                 pn.addChild(dimexpr);
1413                 pn.addChild("dims_opt").setLiteral(dims);
1414                 RESULT=pn;
1415                 :}
1416         |       NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
1417                 ParseNode pn=new ParseNode("createarray");
1418                 pn.addChild(type);
1419                 pn.addChild(dimexpr);
1420                 pn.addChild("dims_opt").setLiteral(dims);
1421                 RESULT=pn;
1422         :}
1423         ;
1424 //array_creation_init ::=
1425 //              NEW primitive_type dims array_initializer
1426 //      |       NEW class_or_interface_type dims array_initializer
1427 //      ;
1428 dim_exprs ::=   dim_expr:exp {: 
1429                 ParseNode pn=new ParseNode("dim_exprs");
1430                 pn.addChild(exp);
1431                 RESULT=pn; :}
1432         |       dim_exprs:base dim_expr:exp {: 
1433                 base.addChild(exp);
1434                 RESULT=base;
1435         :}
1436         ;
1437 dim_expr ::=    LBRACK expression:exp RBRACK {: RESULT=exp; :}
1438         ;
1439 dims_opt ::= {: RESULT=new Integer(0); :}
1440         |       dims:dims {: RESULT = dims; :}
1441         ;
1442
1443 dims ::=        LBRACK RBRACK {: RESULT=new Integer(1); :}
1444         |       dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1445         ;
1446
1447 field_access ::=
1448                 primary:base DOT IDENTIFIER:id {: 
1449                 ParseNode pn=new ParseNode("fieldaccess");
1450                 pn.addChild("base").addChild(base);
1451                 pn.addChild("field").addChild(id);
1452                 RESULT=pn;
1453 :}
1454 //      |       SUPER DOT IDENTIFIER
1455 //      |       name DOT SUPER DOT IDENTIFIER
1456         ;
1457 method_invocation ::=
1458                 name:name LPAREN argument_list_opt:args RPAREN {: 
1459                 ParseNode pn=new ParseNode("methodinvoke1");
1460                 pn.addChild(name);
1461                 pn.addChild(args);
1462                 RESULT=pn;
1463         :}
1464         |       primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {: 
1465                 ParseNode pn=new ParseNode("methodinvoke2");
1466                 pn.addChild("base").addChild(base);
1467                 pn.addChild("id").addChild(name);
1468                 pn.addChild(args);
1469                 RESULT=pn;
1470         :}
1471 //      |       SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1472 //      |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1473         ;
1474 array_access ::=
1475                 name:name LBRACK expression:exp RBRACK {: 
1476                 ParseNode pn=new ParseNode("arrayaccess");
1477                 pn.addChild("base").addChild(name);
1478                 pn.addChild("index").addChild(exp);
1479                 RESULT=pn;
1480         :}
1481         |       primary_no_new_array:base LBRACK expression:exp RBRACK {: 
1482                 ParseNode pn=new ParseNode("arrayaccess");
1483                 pn.addChild("base").addChild(base);
1484                 pn.addChild("index").addChild(exp);
1485                 RESULT=pn;
1486         :}
1487 //      |       array_creation_init:init LBRACK expression:exp RBRACK {: 
1488 //              ParseNode pn=new ParseNode("arrayaccess");
1489 //              pn.addChild("init").addChild(init);
1490 //              pn.addChild("index").addChild(exp);
1491 //              RESULT=pn;
1492 //      :}
1493         ;
1494 postfix_expression ::=
1495                 primary:exp {: 
1496         RESULT=exp; :}
1497         |       name:exp {: RESULT=exp; :}
1498         |       postincrement_expression:exp {: RESULT=exp; :}
1499         |       postdecrement_expression:exp {: RESULT=exp; :}
1500         ;
1501 postincrement_expression ::=
1502                 postfix_expression:exp PLUSPLUS 
1503                 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1504         ;
1505 postdecrement_expression ::=
1506                 postfix_expression:exp MINUSMINUS
1507                 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1508         ;
1509 unary_expression ::=
1510                 preincrement_expression:exp {: RESULT=exp; :}
1511         |       predecrement_expression:exp {: RESULT=exp; :}
1512         |       PLUS unary_expression:exp 
1513         {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1514         |       MINUS unary_expression:exp
1515         {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1516         |       unary_expression_not_plus_minus:exp {: 
1517                         RESULT=exp; :}
1518         ;
1519 preincrement_expression ::=
1520                 PLUSPLUS unary_expression:exp
1521                 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1522         ;
1523 predecrement_expression ::=
1524                 MINUSMINUS unary_expression:exp
1525                 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1526         ;
1527 unary_expression_not_plus_minus ::=
1528                 postfix_expression:exp {: 
1529                 RESULT=exp; :}
1530 //      |       COMP unary_expression
1531         |       NOT unary_expression:exp 
1532                 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1533         |       cast_expression:exp {: RESULT=exp; :}
1534         ;
1535 cast_expression ::=
1536                 LPAREN primitive_type:type
1537         //dims_opt 
1538                 RPAREN unary_expression:exp {: 
1539                 ParseNode pn=new ParseNode("cast1");
1540                 pn.addChild("type").addChild(type);
1541                 pn.addChild("exp").addChild(exp);
1542                 RESULT=pn;
1543         :}
1544         |       LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {: 
1545                 ParseNode pn=new ParseNode("cast2");
1546                 pn.addChild("type").addChild(type);
1547                 pn.addChild("exp").addChild(exp);
1548                 RESULT=pn;
1549
1550         :}
1551 //      |       LPAREN name dims RPAREN unary_expression_not_plus_minus
1552         ;
1553 multiplicative_expression ::=
1554                 unary_expression:exp {: 
1555                         RESULT=exp; :}
1556         |       multiplicative_expression:exp1 MULT unary_expression:exp2 {: 
1557                 ParseNode pn=new ParseNode("mult");
1558                 pn.addChild(exp1);
1559                 pn.addChild(exp2);
1560                 RESULT=pn;
1561         :}
1562         |       multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1563                 ParseNode pn=new ParseNode("div");
1564                 pn.addChild(exp1);
1565                 pn.addChild(exp2);
1566                 RESULT=pn;
1567         :}
1568         |       multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1569                 ParseNode pn=new ParseNode("mod");
1570                 pn.addChild(exp1);
1571                 pn.addChild(exp2);
1572                 RESULT=pn;
1573         :}
1574         ;
1575 additive_expression ::=
1576                 multiplicative_expression:exp {: 
1577                         RESULT=exp; :}
1578         |       additive_expression:exp1 PLUS multiplicative_expression:exp2 {: 
1579                 ParseNode pn=new ParseNode("add");
1580                 pn.addChild(exp1);
1581                 pn.addChild(exp2);
1582                 RESULT=pn;
1583         :}
1584         |       additive_expression:exp1 MINUS multiplicative_expression:exp2 {: 
1585                 ParseNode pn=new ParseNode("sub");
1586                 pn.addChild(exp1);
1587                 pn.addChild(exp2);
1588                 RESULT=pn;
1589         :}
1590         ;
1591 shift_expression ::=
1592                 additive_expression:exp {: 
1593                         RESULT=exp; :}
1594         |       shift_expression:exp1 LSHIFT additive_expression:exp2 {: 
1595                 ParseNode pn=new ParseNode("leftshift");
1596                 pn.addChild(exp1);
1597                 pn.addChild(exp2);
1598                 RESULT=pn;
1599         :}
1600         |       shift_expression:exp1 RSHIFT additive_expression:exp2 {: 
1601                 ParseNode pn=new ParseNode("rightshift");
1602                 pn.addChild(exp1);
1603                 pn.addChild(exp2);
1604                 RESULT=pn;
1605         :}
1606 //      |       shift_expression URSHIFT additive_expression
1607         ;
1608 relational_expression ::=
1609                 shift_expression:exp {: 
1610                         RESULT=exp; :}
1611         |       relational_expression:exp1 LT shift_expression:exp2 {:
1612                 ParseNode pn=new ParseNode("comp_lt");
1613                 pn.addChild(exp1);
1614                 pn.addChild(exp2);
1615                 RESULT=pn;
1616         :}
1617         |       relational_expression:exp1 GT shift_expression:exp2 {:
1618                 ParseNode pn=new ParseNode("comp_gt");
1619                 pn.addChild(exp1);
1620                 pn.addChild(exp2);
1621                 RESULT=pn;
1622         :}
1623         |       relational_expression:exp1 LTEQ shift_expression:exp2 {:
1624                 ParseNode pn=new ParseNode("comp_lte");
1625                 pn.addChild(exp1);
1626                 pn.addChild(exp2);
1627                 RESULT=pn;
1628         :}
1629         |       relational_expression:exp1 GTEQ shift_expression:exp2 {:
1630                 ParseNode pn=new ParseNode("comp_gte");
1631                 pn.addChild(exp1);
1632                 pn.addChild(exp2);
1633                 RESULT=pn;
1634         :}
1635 //      |       relational_expression INSTANCEOF reference_type
1636         ;
1637
1638 equality_expression ::=
1639                 relational_expression:exp {: 
1640                         RESULT=exp; :}
1641         |       equality_expression:exp1 EQEQ relational_expression:exp2 {: 
1642                 ParseNode pn=new ParseNode("equal");
1643                 pn.addChild(exp1);
1644                 pn.addChild(exp2);
1645                 RESULT=pn;
1646         :}
1647         |       equality_expression:exp1 NOTEQ relational_expression:exp2 {: 
1648                 ParseNode pn=new ParseNode("not_equal");
1649                 pn.addChild(exp1);
1650                 pn.addChild(exp2);
1651                 RESULT=pn;
1652         :}
1653         ;
1654 and_expression ::=
1655                 equality_expression:exp {: 
1656                 RESULT=exp; :}
1657         |       and_expression:exp1 AND equality_expression:exp2 {: 
1658                 ParseNode pn=new ParseNode("bitwise_and");
1659                 pn.addChild(exp1);
1660                 pn.addChild(exp2);
1661                 RESULT=pn;
1662         :}
1663         ;
1664 exclusive_or_expression ::=
1665                 and_expression:expr {: 
1666                         RESULT=expr;
1667                 :}
1668         |       exclusive_or_expression:exp1 XOR and_expression:exp2 {: 
1669                 ParseNode pn=new ParseNode("bitwise_xor");
1670                 pn.addChild(exp1);
1671                 pn.addChild(exp2);
1672                 RESULT=pn;
1673 :}
1674         ;
1675 inclusive_or_expression ::=
1676                 exclusive_or_expression:exclor {: 
1677                         RESULT=exclor; :}
1678         |       inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {: 
1679                 ParseNode pn=new ParseNode("bitwise_or");
1680                 pn.addChild(exp1);
1681                 pn.addChild(exp2);
1682                 RESULT=pn;
1683         :}
1684         ;
1685 conditional_and_expression ::=
1686                 inclusive_or_expression:inclor {: 
1687                         RESULT=inclor; :}
1688         |       conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1689                 ParseNode pn=new ParseNode("logical_and");
1690                 pn.addChild(exp1);
1691                 pn.addChild(exp2);
1692                 RESULT=pn;
1693         :}
1694         ;
1695 conditional_or_expression ::=
1696                 conditional_and_expression:condand {: 
1697                         RESULT=condand; :}
1698         |       conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {: 
1699                 ParseNode pn=new ParseNode("logical_or");
1700                 pn.addChild(exp1);
1701                 pn.addChild(exp2);
1702                 RESULT=pn;
1703         :}
1704         ;
1705 conditional_expression ::=
1706                 conditional_or_expression:condor {: 
1707                         RESULT=condor; :}
1708 //      |       conditional_or_expression QUESTION expression 
1709 //                      COLON conditional_expression
1710         ;
1711 assignment_expression ::=
1712                 conditional_expression:expr {: 
1713                         RESULT=expr; :} |
1714                 assignment:assign {: 
1715                         RESULT=assign; :}
1716         ;
1717 // semantic check necessary here to ensure a valid left-hand side.
1718 // allowing a parenthesized variable here on the lhs was introduced in
1719 // JLS 2; thanks to Eric Blake for pointing this out.
1720 assignment ::=  postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
1721                 ParseNode pn=new ParseNode("assignment");
1722                 pn.addChild("op").addChild(op);
1723                 ParseNode pnargs=pn.addChild("args");
1724                 pnargs.addChild(lvalue);
1725                 pnargs.addChild(rvalue);
1726                 RESULT=pn;
1727          :}
1728         ;
1729 assignment_operator ::=
1730                 EQ {: RESULT=new ParseNode("eq"); :}
1731         |       MULTEQ {: RESULT=new ParseNode("multeq"); :}
1732         |       DIVEQ {: RESULT=new ParseNode("diveq"); :}
1733         |       MODEQ {: RESULT=new ParseNode("modeq"); :}
1734         |       PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
1735         |       MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
1736         |       LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
1737         |       RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
1738 //      |       URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
1739         |       ANDEQ {: RESULT=new ParseNode("andeq"); :}
1740         |       XOREQ {: RESULT=new ParseNode("xoreq"); :}
1741         |       OREQ {: RESULT=new ParseNode("oreq"); :}
1742         ;
1743 expression_opt ::=
1744         {:      RESULT=new ParseNode("empty"); :}
1745         |       expression:exp {: 
1746                 RESULT=exp; :}
1747         ;
1748 expression ::=  assignment_expression:exp {: 
1749                 RESULT=exp; :}
1750         ;
1751 //constant_expression ::=
1752 //              expression
1753 //      ;