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