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