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