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