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