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