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