fix a grammar to allow multiple annotations on method parameter
[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 NEWFLAG; // class_instance_creation_expression
74 terminal PLUSPLUS; // postincrement_expression
75 terminal MINUSMINUS; // postdecrement_expression
76 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
77 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
78 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
79 terminal EQEQ, NOTEQ; // equality_expression
80 terminal AND; // and_expression
81 terminal XOR; // exclusive_or_expression
82 terminal OR;  // inclusive_or_expression
83 terminal ANDAND; // conditional_and_expression
84 terminal OROR; // conditional_or_expression
85 terminal QUESTION; // conditional_expression
86 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
87 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
88 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
89 terminal AT;           // support annotations
90 terminal LOCDEF;          // declaration of location hierarchy
91
92 terminal java.lang.Number INTEGER_LITERAL;
93 terminal java.lang.Number FLOATING_POINT_LITERAL;
94 terminal java.lang.Boolean BOOLEAN_LITERAL;
95 terminal java.lang.Character CHARACTER_LITERAL;
96 terminal java.lang.String STRING_LITERAL;
97 terminal NULL_LITERAL;
98
99 // Reserved but unused:
100 terminal CONST, GOTO;
101 // strictfp keyword, new in Java 1.2
102 terminal STRICTFP;
103 // assert keyword, new in Java 1.4
104 terminal ASSERT; // assert_statement
105 // lexer compatibility with Java 1.5
106 terminal ELLIPSIS;
107 terminal ENUM;
108
109 // added for disjoint reachability analysis
110 terminal GENREACH;
111
112
113 // 19.2) The Syntactic Grammar
114 non terminal ParseNode goal;
115 // 19.3) Lexical Structure
116 non terminal ParseNode literal;
117 // 19.4) Types, Values, and Variables
118 non terminal ParseNode type, primitive_type, numeric_type;
119 non terminal ParseNode integral_type, floating_point_type;
120 non terminal ParseNode reference_type;
121 non terminal ParseNode class_or_interface_type;
122 non terminal ParseNode class_type;
123 non terminal ParseNode interface_type;
124 non terminal ParseNode array_type;
125 // 19.5) Names
126 non terminal ParseNode name, simple_name, qualified_name;
127 // 19.6) Packages
128 non terminal ParseNode compilation_unit;
129 non terminal ParseNode package_declaration_opt, package_declaration;
130 non terminal ParseNode import_declarations_opt, import_declarations;
131 non terminal ParseNode type_declarations_opt, type_declarations;
132 non terminal ParseNode import_declaration;
133 non terminal ParseNode single_type_import_declaration;
134 non terminal ParseNode type_import_on_demand_declaration;
135 non terminal ParseNode type_declaration;
136 // 19.7) Productions used only in the LALR(1) grammar
137 non terminal ParseNode modifiers_opt, modifiers, modifiers_at, modifier;
138 non terminal ParseNode mixed_modifiers, mixed_modifiers_at;
139 // 19.8.1) Class Declaration
140 non terminal ParseNode class_declaration, super, super_opt;
141 non terminal ParseNode interfaces, interfaces_opt, interface_type_list;
142 non terminal ParseNode class_body;
143 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
144 non terminal ParseNode class_body_declaration, class_member_declaration;
145 // 19.8.2) Field Declarations
146 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
147 non terminal ParseNode variable_declarator_id;
148 non terminal ParseNode variable_initializer;
149 // 19.8.3) Method Declarations
150 non terminal ParseNode method_declaration, method_header, method_declarator;
151 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
152 non terminal ParseNode formal_parameter;
153 non terminal ParseNode throws_opt;
154 non terminal ParseNode throws;
155 non terminal ParseNode class_type_list;
156 non terminal ParseNode method_body;
157 // 19.8.4) Static Initializers
158 non terminal ParseNode static_initializer;
159 // 19.8.5) Constructor Declarations
160 non terminal ParseNode constructor_declaration, constructor_declarator;
161 non terminal ParseNode constructor_body;
162 non terminal ParseNode explicit_constructor_invocation;
163 // 19.9.1) Interface Declarations
164 non terminal ParseNode interface_declaration;
165 //non terminal ParseNode normal_interface_declaration
166 non terminal ParseNode annotation_type_declaration;
167 non terminal ParseNode extends_interfaces_opt, extends_interfaces;
168 non terminal ParseNode interface_body;
169 non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
170 non terminal ParseNode interface_member_declaration, constant_declaration;
171 non terminal ParseNode abstract_method_declaration;
172 // 19.10) Arrays
173 non terminal ParseNode array_initializer;
174 non terminal ParseNode variable_initializers;
175 // 19.11) Blocks and Statements
176 non terminal ParseNode block;
177 non terminal ParseNode block_statements_opt, block_statements, block_statement;
178 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
179 non terminal ParseNode statement, statement_no_short_if;
180 non terminal ParseNode statement_without_trailing_substatement;
181 non terminal ParseNode empty_statement;
182 non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
183 non terminal ParseNode expression_statement, statement_expression;
184 non terminal ParseNode if_then_statement;
185 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
186 non terminal ParseNode switch_statement, switch_block;
187 non terminal ParseNode switch_block_statement_groups;
188 non terminal ParseNode switch_block_statement_group;
189 non terminal ParseNode switch_labels, switch_label;
190 non terminal ParseNode while_statement, while_statement_no_short_if;
191 non terminal ParseNode do_statement;
192 non terminal ParseNode for_statement, for_statement_no_short_if;
193 non terminal ParseNode for_init_opt, for_init;
194 non terminal ParseNode for_update_opt, for_update;
195 non terminal ParseNode statement_expression_list;
196 non terminal ParseNode identifier_opt;
197 non terminal ParseNode break_statement, continue_statement;
198 non terminal ParseNode return_statement;
199 non terminal ParseNode throw_statement;
200 non terminal ParseNode synchronized_statement;
201 non terminal ParseNode try_statement;
202 non terminal ParseNode catches_opt;
203 non terminal ParseNode catches, catch_clause;
204 non terminal ParseNode finally;
205 //non terminal ParseNode assert_statement;
206 non terminal ParseNode genreach_statement;
207 // 19.12) Expressions
208 non terminal ParseNode primary, primary_no_new_array;
209 non terminal ParseNode class_instance_creation_expression;
210 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
211 non terminal ParseNode argument_list_opt, argument_list;
212 non terminal ParseNode array_creation_init;
213 non terminal ParseNode array_creation_uninit;
214 non terminal ParseNode dim_exprs, dim_expr;
215 non terminal Integer dims_opt, dims;
216 non terminal ParseNode field_access, method_invocation;
217 non terminal ParseNode array_access;
218 non terminal ParseNode postfix_expression;
219 non terminal ParseNode postincrement_expression, postdecrement_expression;
220 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
221 non terminal ParseNode preincrement_expression, predecrement_expression;
222 non terminal ParseNode cast_expression;
223 non terminal ParseNode multiplicative_expression, additive_expression;
224 non terminal ParseNode shift_expression, relational_expression, equality_expression;
225 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
226 non terminal ParseNode conditional_and_expression, conditional_or_expression;
227 non terminal ParseNode conditional_expression;
228 non terminal ParseNode assignment_expression;
229 non terminal ParseNode assignment;
230 non terminal ParseNode assignment_operator;
231 non terminal ParseNode expression_opt, expression;
232 non terminal ParseNode constant_expression;
233 //failure aware computation keywords
234 terminal FLAG;
235 terminal OPTIONAL;
236 terminal ISAVAILABLE;
237 terminal EXTERNAL;
238 terminal TAG;
239 terminal TASK;
240 terminal TASKEXIT;
241 non terminal ParseNode flag_declaration;
242 non terminal ParseNode task_declaration;
243 non terminal ParseNode task_parameter_list;
244 non terminal ParseNode task_parameter;
245 non terminal ParseNode flag_expression;
246 non terminal ParseNode flag_andexpression;
247 non terminal ParseNode flag_notexpression;
248 non terminal ParseNode task_exitstatement;
249 non terminal ParseNode flag_effects_opt;
250 non terminal ParseNode flag_effects;
251 non terminal ParseNode flag_effect;
252 non terminal ParseNode flag_list;
253 non terminal ParseNode flag_list_opt;
254 non terminal ParseNode flag_change;
255
256 non terminal ParseNode cons_checks_opt;
257 non terminal ParseNode cons_checks;
258 non terminal ParseNode cons_check;
259
260 non terminal ParseNode tag_variable_declaration_statement;
261 non terminal ParseNode tag_expression_list;
262 non terminal ParseNode tag_expression;
263 non terminal ParseNode tag_list;
264 non terminal ParseNode tag_list_opt;
265 non terminal ParseNode tag_change;
266
267 //distributed transaction keywords
268 terminal ATOMIC;
269 terminal GLOBAL;
270 terminal SCRATCH;
271 terminal GETOFFSET;
272 non terminal ParseNode atomic_statement;
273 non terminal ParseNode getoffset_expression;
274
275 //disjointness for Java
276 terminal DISJOINT;
277
278 //coarse-grain parallelization
279 terminal SESE;
280 terminal RBLOCK;
281 non terminal ParseNode sese_statement;
282
283 // mgc
284 // JSR-201) Enum Declaration
285 non terminal ParseNode enum_declaration;
286 non terminal ParseNode enum_body, enum_constants_opt, enum_constants, enum_constant;
287 //non terminal ParseNode enum_arguments_opt, enum_body_declarations_opt;
288
289 // annotation expressions
290 // non terminal ParseNode annotations_opt, 
291 non terminal ParseNode annotations, annotations_at, annotation, annotation_body;
292 non terminal ParseNode normal_annotation_body, marker_annotation_body;
293 non terminal ParseNode single_element_annotation_body;
294 non terminal ParseNode annotation_type_body, annotation_type_element_declarations;
295 non terminal ParseNode annotation_type_element_declarations_opt;
296 non terminal ParseNode annotation_type_element_declaration, default_value_opt, default_value;
297 non terminal ParseNode element_value_pairs_opt, element_value_pairs, element_value_pair;
298 non terminal ParseNode element_values_opt, element_values, element_value, element_value_array_initializer;
299
300 start with goal;
301
302
303 // Task declarations
304 task_declaration ::= 
305         TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN 
306         flag_effects_opt:feo
307         method_body:body 
308         {: 
309         ParseNode pn=new ParseNode("task_declaration",parser.lexer.line_num);
310         pn.addChild("name").addChild(id);
311         pn.addChild(tpl);
312         pn.addChild(feo);
313         pn.addChild("body").addChild(body);     
314         RESULT=pn;
315         :};
316
317 task_parameter_list ::=
318                 task_parameter:fp {: 
319                 ParseNode pn=new ParseNode("task_parameter_list",parser.lexer.line_num);
320                 pn.addChild(fp);
321                 RESULT=pn;
322         :}
323         |       task_parameter_list:fpl COMMA task_parameter:fp {: 
324                 fpl.addChild(fp);
325                 RESULT=fpl;
326         :}
327         ;
328
329 task_parameter ::=
330                 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
331                 ParseNode pn=new ParseNode("task_parameter",parser.lexer.line_num);
332                 pn.addChild(type);
333                 pn.addChild(name);
334                 pn.addChild("flag").addChild(exp);
335                 RESULT=pn;
336         :} 
337         | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
338                 ParseNode pn=new ParseNode("task_parameter",parser.lexer.line_num);
339                 pn.addChild(type);
340                 pn.addChild(name);
341                 pn.addChild("flag").addChild(exp);
342                 pn.addChild("tag").addChild(texp);
343                 RESULT=pn;
344         :}
345         | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
346                 ParseNode pn=new ParseNode("task_parameter",parser.lexer.line_num);
347                 pn.addChild(type);
348                 pn.addChild(name);
349                 pn.addChild("tag").addChild(texp);
350                 RESULT=pn;
351         :}
352         | OPTIONAL task_parameter:fp {:
353                 ParseNode pn=new ParseNode("task_parameter",parser.lexer.line_num);
354                 pn.addChild("optional").addChild(fp);
355                 RESULT=pn;
356         :}              
357         
358         ;
359
360 tag_expression_list ::= tag_expression:te {: 
361         ParseNode pn=new ParseNode("tag_expression_list",parser.lexer.line_num);
362         pn.addChild(te);
363         RESULT=pn;
364         :}
365         | tag_expression_list:tel COMMA tag_expression:te {: 
366         tel.addChild(te);
367         RESULT=tel;
368         :}
369         ;
370
371 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {: 
372                 ParseNode pn=new ParseNode("tag_expression",parser.lexer.line_num);
373                 pn.addChild("type").addChild(type);
374                 pn.addChild("single").addChild(id);
375                 RESULT=pn;
376         :}
377         ;
378
379 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
380         | LBRACE RBRACE {: RESULT = new ParseNode("empty",parser.lexer.line_num); :}    
381         | {: RESULT = new ParseNode("empty",parser.lexer.line_num); :}
382         ;
383
384 tag_list ::= tag_change:fc {: 
385                 ParseNode pn=new ParseNode("tag_list",parser.lexer.line_num);
386                 pn.addChild(fc);
387                 RESULT=pn;
388         :}
389         | tag_list:fl COMMA tag_change:fc {: 
390                 fl.addChild(fc);
391                 RESULT=fl;
392         :};
393
394 tag_change ::= IDENTIFIER:id {: 
395                 RESULT=new ParseNode("name",parser.lexer.line_num).addChild(id).getRoot();
396         :}
397         | NOT IDENTIFIER:id {: 
398                 RESULT=new ParseNode("not",parser.lexer.line_num).addChild("name").addChild(id).getRoot();
399         :};
400
401 flag_expression ::= 
402         flag_andexpression:exp {: 
403                 RESULT=exp;
404         :}
405         | flag_expression:exp1 OROR flag_andexpression:exp2 {: 
406                 ParseNode pn=new ParseNode("or",parser.lexer.line_num);
407                 pn.addChild(exp1);
408                 pn.addChild(exp2);
409                 RESULT=pn;
410         :}
411         ;
412
413 flag_andexpression ::= 
414         flag_notexpression:exp {: RESULT=exp; :}
415         | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {: 
416                 ParseNode pn=new ParseNode("and",parser.lexer.line_num);
417                 pn.addChild(exp1);
418                 pn.addChild(exp2);
419                 RESULT=pn;
420         :}
421         ;
422
423 flag_notexpression ::=
424         NOT flag_notexpression:exp {: 
425                 ParseNode pn=new ParseNode("not",parser.lexer.line_num);
426                 pn.addChild(exp);
427                 RESULT=pn;
428         :}
429         | LPAREN flag_expression:exp RPAREN {: 
430                 RESULT=exp;
431         :}
432         | IDENTIFIER:id {:
433                 ParseNode pn=new ParseNode("name",parser.lexer.line_num);
434                 pn.addChild(id);
435                 RESULT=pn;
436         :}
437         ;
438
439 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {: 
440                 RESULT=(new ParseNode("taskexit",parser.lexer.line_num)).addChild(opt).getRoot().addChild(cco).getRoot();
441         :};
442
443 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
444         | {: RESULT = new ParseNode("empty",parser.lexer.line_num); :}
445         ;
446
447 cons_checks ::= cons_check:cc {: 
448                 ParseNode pn=new ParseNode("cons_checks",parser.lexer.line_num);
449                 pn.addChild(cc);
450                 RESULT=pn;
451         :}
452         |       cons_checks:ccs COMMA cons_check:cc {: 
453                 ccs.addChild(cc);
454                 RESULT=ccs;
455         :};
456
457 cons_check ::=  IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {: 
458                 ParseNode pn=new ParseNode("cons_check",parser.lexer.line_num);
459                 pn.addChild("name").addChild("identifier").addChild(name);
460                 pn.addChild(args);
461                 RESULT=pn;
462         :};
463
464 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
465         | {: RESULT = new ParseNode("empty",parser.lexer.line_num); :}
466         ;
467
468 flag_effects ::= flag_effect:fe {: 
469                 ParseNode pn=new ParseNode("flag_effects_list",parser.lexer.line_num);
470                 pn.addChild(fe);
471                 RESULT=pn;
472         :}
473         |       flag_effects:fes COMMA flag_effect:fe {: 
474                 fes.addChild(fe);
475                 RESULT=fes;
476         :};
477
478 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {: 
479                 ParseNode pn=new ParseNode("flag_effect",parser.lexer.line_num);
480                 pn.addChild("name").addChild(id);
481                 pn.addChild(fl);
482                 pn.addChild(tlo);
483                 RESULT=pn;
484         :}
485         | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {: 
486                 ParseNode pn=new ParseNode("flag_effect",parser.lexer.line_num);
487                 pn.addChild("name").addChild(id);
488                 pn.addChild(tl);
489                 RESULT=pn;
490         :};
491
492 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
493         | LBRACE RBRACE {: RESULT = new ParseNode("empty",parser.lexer.line_num); :}    
494         | 
495         {: RESULT = new ParseNode("empty",parser.lexer.line_num); :}
496         ;
497
498 flag_list ::= flag_change:fc {: 
499                 ParseNode pn=new ParseNode("flag_list",parser.lexer.line_num);
500                 pn.addChild(fc);
501                 RESULT=pn;
502         :}
503         |       flag_list:fl COMMA flag_change:fc {: 
504                 fl.addChild(fc);
505                 RESULT=fl;
506         :};
507
508 flag_change ::= IDENTIFIER:id {: 
509                 RESULT=new ParseNode("name",parser.lexer.line_num).addChild(id).getRoot();
510         :} |
511         NOT IDENTIFIER:id {: 
512                 RESULT=new ParseNode("not",parser.lexer.line_num).addChild("name").addChild(id).getRoot();
513         :};
514
515 // 19.2) The Syntactic Grammar
516 goal ::=        compilation_unit:cu
517         {:
518         RESULT = cu;
519         :}
520         ;
521
522 // 19.3) Lexical Structure.
523
524
525 literal ::=     INTEGER_LITERAL:integer_lit
526         {:
527                 ParseNode pn=new ParseNode("literal",parser.lexer.line_num);
528                 pn.addChild("integer").setLiteral(integer_lit);
529                 RESULT=pn;
530         :}
531         |       FLOATING_POINT_LITERAL:float_lit
532         {:
533                 ParseNode pn=new ParseNode("literal",parser.lexer.line_num);
534                 pn.addChild("float").setLiteral(float_lit);
535                 RESULT=pn;
536         :}
537         |       BOOLEAN_LITERAL:boolean_lit
538         {:
539                 ParseNode pn=new ParseNode("literal",parser.lexer.line_num);
540                 pn.addChild("boolean").setLiteral(boolean_lit);
541                 RESULT=pn;
542         :}
543         |       CHARACTER_LITERAL:char_lit
544         {:
545                 ParseNode pn=new ParseNode("literal",parser.lexer.line_num);
546                 pn.addChild("char").setLiteral(char_lit);
547                 RESULT=pn;
548         :}
549         |       STRING_LITERAL:string_lit
550         {:
551                 ParseNode pn=new ParseNode("literal",parser.lexer.line_num);
552                 pn.addChild("string").setLiteral(string_lit);
553                 RESULT=pn;
554         :}
555         |       NULL_LITERAL 
556         {:
557                 RESULT=(new ParseNode("literal",parser.lexer.line_num)).addChild("null").getRoot();
558         :}
559         ;
560
561 // 19.4) Types, Values, and Variables
562 type    ::=     primitive_type:type {: RESULT=type; :}
563         |       reference_type:type {: RESULT=type; :}
564         ;
565
566 primitive_type ::=
567                 numeric_type:type {: RESULT=type; :}
568         |       BOOLEAN {: RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("boolean").getRoot(); :}
569         ;
570 numeric_type::= integral_type:type {: RESULT=type; :}
571         |       floating_point_type:type {: RESULT=type; :}
572         ;
573 integral_type ::= 
574                 BYTE {: RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("byte").getRoot(); :}
575         |       SHORT  {: RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("short").getRoot(); :}
576         |       INT  {: RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("int").getRoot(); :}
577         |       LONG  {: RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("long").getRoot(); :}
578         |       CHAR  {: RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("char").getRoot(); :}
579         ;
580 floating_point_type ::= 
581                 FLOAT  {: RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("float").getRoot(); :}
582         |       DOUBLE  {: RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("double").getRoot(); :}
583         ;
584
585 reference_type ::=
586                 class_or_interface_type:type {: RESULT=type; :}
587         |       array_type:type {: RESULT=type; :}
588         ;
589 class_or_interface_type ::= name:name {: 
590         RESULT=(new ParseNode("type",parser.lexer.line_num)).addChild("class").addChild(name).getRoot(); 
591         :};
592
593 class_type ::=  class_or_interface_type:type {: RESULT=type; :};
594 interface_type ::= class_or_interface_type:type {: RESULT=type; :};
595
596 array_type ::=  primitive_type:prim dims:dims {: 
597                 ParseNode pn=(new ParseNode("type",parser.lexer.line_num)).addChild("array");
598                 pn.addChild("basetype").addChild(prim);
599                 pn.addChild("dims").setLiteral(dims);
600                 RESULT=pn.getRoot();
601         :}
602         |       name:name dims:dims {: 
603                 ParseNode pn=(new ParseNode("type",parser.lexer.line_num)).addChild("array");
604                 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
605                 pn.addChild("dims").setLiteral(dims);
606                 RESULT=pn.getRoot();
607         :}
608         ;
609
610 // 19.5) Names
611 name    ::=     simple_name:name {: RESULT=name; :}
612         |       qualified_name:name {: RESULT=name; :}
613         ;
614 simple_name ::= IDENTIFIER:id {: 
615         RESULT=(new ParseNode("name",parser.lexer.line_num)).addChild("identifier").addChild(id).getRoot(); 
616         :}
617         ;
618 qualified_name ::= name:name DOT IDENTIFIER:id {: 
619         ParseNode pn=new ParseNode("name",parser.lexer.line_num);
620         pn.addChild("base").addChild(name);
621         pn.addChild("identifier").addChild(id);
622         RESULT=pn;
623         :}
624         ;
625
626 // 19.6) Packages
627 compilation_unit ::=
628                 package_declaration_opt:pdo
629                 import_declarations_opt:ido
630                 type_declarations_opt:tdo {: 
631                 ParseNode pn=new ParseNode("compilation_unit",parser.lexer.line_num);
632                 pn.addChild(tdo);
633                 pn.addChild("packages").addChild(pdo);
634                 pn.addChild("imports").addChild(ido);
635                 RESULT=pn;
636                 :}
637                 ;
638 package_declaration_opt ::= package_declaration:pdo {:
639                 RESULT=pdo;
640         :} |
641         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
642 ;
643
644 import_declarations_opt ::= import_declarations:ido {: 
645                 RESULT=ido;
646         :} | 
647         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
648 ;
649 type_declarations_opt   ::= type_declarations:tds {:
650                 RESULT=tds;
651                 :}   | 
652         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
653         ;
654
655 import_declarations ::=
656                import_declaration:id {: 
657                 ParseNode pn=new ParseNode("import_decls_list",parser.lexer.line_num);
658                 pn.addChild(id);
659                 RESULT=pn;
660         :}
661        |       import_declarations:ids import_declaration:id {: 
662                 ids.addChild(id);
663                 RESULT=ids;
664         :}
665        ;
666
667 type_declarations ::= 
668                 type_declaration:td {:
669                 ParseNode pn=new ParseNode("type_declaration_list",parser.lexer.line_num);
670                 pn.addChild(td);
671                 RESULT=pn;
672                 :}
673         |       type_declarations:tds type_declaration:td {:
674                 tds.addChild(td);
675                 RESULT=tds;
676                 :}
677         ;
678
679 package_declaration ::=
680                 PACKAGE name:name SEMICOLON {: 
681         ParseNode pn=new ParseNode("package",parser.lexer.line_num);
682         pn.addChild(name);
683         RESULT=pn;
684         :}
685        ;
686 import_declaration ::=
687                single_type_import_declaration:sid {: RESULT=sid; :}
688        |       type_import_on_demand_declaration:iod {: RESULT=iod; :}
689        ;
690 single_type_import_declaration ::=
691                IMPORT name:name SEMICOLON {: 
692         ParseNode pn=new ParseNode("import_single",parser.lexer.line_num);
693         pn.addChild(name);
694         RESULT=pn;
695 :}
696        ;
697 type_import_on_demand_declaration ::=
698                IMPORT name:name DOT MULT SEMICOLON {:
699         ParseNode pn=new ParseNode("import_ondemand",parser.lexer.line_num);
700         pn.addChild(name);
701         RESULT=pn;
702         :}       
703         ;
704
705 type_declaration ::=
706                 class_declaration:cd 
707                 {:
708                         RESULT=cd;
709                 :}
710         |       enum_declaration:ed
711             {:
712                 RESULT=ed;
713             :}
714         |       task_declaration:td 
715                 {:
716                         RESULT=td;
717                 :}
718     |   interface_declaration:in
719         {:
720                         RESULT=in;
721                 :}
722         |       SEMICOLON {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
723         ;
724
725 // 19.7) Productions used only in the LALR(1) grammar
726 modifiers_opt::=
727         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
728         |       modifiers:mo {: 
729                 RESULT=mo;
730         :}
731         ;
732 modifiers_at ::=
733                 mixed_modifiers_at
734         |       annotations_at
735         ;
736 modifiers ::=   mixed_modifiers : mmo {:
737                 RESULT=mmo; 
738         :}
739         |       annotations : an {:
740                 ParseNode pn=new ParseNode("modifier_list",parser.lexer.line_num);
741                 pn.addChild(an);
742                 RESULT=pn;
743         :}
744         ;
745 mixed_modifiers_at ::=
746                 mixed_modifiers : mmos AT {:
747                 RESULT=mmos;
748         :}
749         ;
750 mixed_modifiers ::=
751                 modifier : mo {:
752                 ParseNode pn=new ParseNode("modifier_list",parser.lexer.line_num);
753                 pn.addChild(mo);
754                 RESULT=pn;
755         :}
756         |       annotations:as modifier:mo {:
757                 ParseNode pn=new ParseNode("modifier_list",parser.lexer.line_num);
758                 pn.addChild(mo);
759                 pn.addChild(as);
760                 RESULT=pn;
761         :}
762         |       mixed_modifiers : mmos modifier : mo {:
763                 mmos.addChild(mo);
764                 RESULT=mmos;
765         :}
766         |       mixed_modifiers_at:mma annotation_body:ab {:
767                 mma.addChild("annotation_list",parser.lexer.line_num).addChild(ab); 
768                 RESULT=mma;             
769         :}
770         ;
771 modifier ::=    
772         PUBLIC {: RESULT=new ParseNode("public",parser.lexer.line_num); :}|
773         PROTECTED {: RESULT=new ParseNode("protected",parser.lexer.line_num); :}|
774         PRIVATE {: RESULT=new ParseNode("private",parser.lexer.line_num); :}|
775         STATIC {: RESULT=new ParseNode("static",parser.lexer.line_num); :} |
776         ABSTRACT {: RESULT=new ParseNode("abstract",parser.lexer.line_num); :}  |
777         FINAL {: RESULT=new ParseNode("final",parser.lexer.line_num); :}|
778         NATIVE {: RESULT=new ParseNode("native",parser.lexer.line_num); :} |
779         SYNCHRONIZED {: RESULT=new ParseNode("synchronized",parser.lexer.line_num); :} |
780         ATOMIC {: RESULT=new ParseNode("atomic",parser.lexer.line_num); :} |
781         VOLATILE {: RESULT=new ParseNode("volatile",parser.lexer.line_num); :} |
782         TRANSIENT {: RESULT=new ParseNode("transient",parser.lexer.line_num); :} 
783
784 //      STRICTFP // note that semantic analysis must check that the
785                          // context of the modifier allows strictfp.
786         ;
787 //annotations_opt ::=
788 //      {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
789 //      |       annotations:an {: 
790 //              RESULT=an;
791 //      :}
792 //      ;
793 annotations ::= 
794                 AT annotation_body:ab {:
795                 ParseNode pn=new ParseNode("annotation_list",parser.lexer.line_num);
796                 pn.addChild(ab);
797                 RESULT=pn;
798         :}
799         |       annotations_at:aat annotation_body:ab {:
800                 aat.addChild(ab);
801                 RESULT=aat;
802         :}
803         ;
804 annotations_at ::=
805                annotations:as AT {:
806                RESULT=as;
807         :}
808         ;
809 annotation ::=
810                AT annotation_body:ab {:
811                RESULT=ab;
812         :}
813         ;
814 annotation_body ::=
815                 normal_annotation_body:nab {:
816                 ParseNode pn=new ParseNode("annotation_body",parser.lexer.line_num);
817                 pn.addChild(nab);
818                 RESULT = pn;
819         :}
820         |       marker_annotation_body:mab {:
821                 ParseNode pn=new ParseNode("annotation_body",parser.lexer.line_num);
822                 pn.addChild(mab);
823                 RESULT = pn;
824         :}
825         |       single_element_annotation_body:seab {:
826                 ParseNode pn=new ParseNode("annotation_body",parser.lexer.line_num);
827                 pn.addChild(seab);
828                 RESULT = pn;
829         :}
830         ;
831 normal_annotation_body ::=
832                 IDENTIFIER LPAREN element_value_pairs_opt RPAREN
833         ;
834 marker_annotation_body ::=
835                 IDENTIFIER:id
836         {:
837         ParseNode pn=new ParseNode("marker_annotation",parser.lexer.line_num);
838         pn.addChild("name").addChild(id);
839         RESULT=pn;
840         :}
841         ;
842 single_element_annotation_body ::=
843                 IDENTIFIER:id LPAREN STRING_LITERAL:ev RPAREN {:
844                 ParseNode pn=new ParseNode("single_annotation",parser.lexer.line_num);
845                 pn.addChild("name").addChild(id);
846                 pn.addChild("element_value").addChild(ev);
847                 RESULT=pn;
848         :}
849         ;
850 element_value_pairs_opt ::=
851         |       element_value_pairs
852         ;               
853 element_value_pairs ::=
854                 element_value_pair
855         |       element_value_pairs COMMA element_value_pair
856         ;
857 element_value_pair ::=
858                 IDENTIFIER EQ element_value
859         ;
860 element_value ::=
861                 annotation:an {:
862                 RESULT=an;
863         :}  
864         |       element_value_array_initializer:evai {: 
865                 RESULT=evai;
866         :}
867         |       conditional_expression:ce {:
868                 RESULT=ce;
869         :}
870         ;
871 element_value_array_initializer ::=
872                 LBRACE element_values_opt RBRACE
873         ;
874 element_values_opt ::=
875         |       element_values
876         ;
877 element_values ::=
878                 element_value
879         |       element_values COMMA element_value
880         ;
881 // 19.8) Classes
882
883 // 19.8.1) Class Declaration:
884 class_declaration ::= 
885         modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo 
886         class_body:body 
887         {:
888         ParseNode pn=new ParseNode("class_declaration",parser.lexer.line_num);
889         pn.addChild("modifiers").addChild(mo);
890         pn.addChild("name").addChild(id);
891         pn.addChild("super").addChild(so);
892         pn.addChild("superIF").addChild(ifo);
893         pn.addChild("classbody").addChild(body);
894         RESULT=pn;
895         :}
896         ;
897 super ::=       EXTENDS class_type:classtype {: 
898                 RESULT=classtype;
899         :}
900         ;
901 super_opt ::=   
902         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
903         |       super:su {: 
904                 RESULT=su;
905         :}
906         ;
907
908 interfaces ::= IMPLEMENTS interface_type_list:iftl {: RESULT=iftl; :}
909        ;
910 interfaces_opt ::=
911        {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
912        |       interfaces:ifs {: RESULT=ifs; :}
913        ;
914 interface_type_list ::=
915                interface_type:ift {: 
916                         ParseNode pn=new ParseNode("interface_type_list",parser.lexer.line_num);
917                         pn.addChild(ift);
918                         RESULT=pn;
919                 :}
920        |       interface_type_list:iftl COMMA interface_type:ift {: 
921                         iftl.addChild(ift);
922                         RESULT=iftl;
923                 :}
924        ;
925
926 class_body ::=  LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
927         ;
928
929 class_body_declarations_opt ::= 
930         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
931         |       class_body_declarations:cbd {: RESULT=cbd; :};
932
933 class_body_declarations ::= 
934                 class_body_declaration:cbd {: 
935                         ParseNode pn=new ParseNode("class_body_declaration_list",parser.lexer.line_num);
936                         pn.addChild(cbd);
937                         RESULT=pn;
938                 :}
939         |       class_body_declarations:cbds class_body_declaration:cbd {: 
940                         cbds.addChild(cbd);
941                         RESULT=cbds;
942                 :}
943         ;
944
945 class_body_declaration ::=
946                 class_member_declaration:member {: 
947                 RESULT=(new ParseNode("member",parser.lexer.line_num)).addChild(member).getRoot();
948         :}
949         |       static_initializer:block{:
950                 RESULT=(new ParseNode("static_block",parser.lexer.line_num)).addChild(block).getRoot();
951         :}
952         |       constructor_declaration:constructor {: 
953                 RESULT=(new ParseNode("constructor",parser.lexer.line_num)).addChild(constructor).getRoot();
954         :}
955         |       block:block {:
956                 RESULT=(new ParseNode("block",parser.lexer.line_num)).addChild(block).getRoot();
957         :}
958         ;
959 class_member_declaration ::=
960         //failure aware computation
961         flag_declaration:flag {: 
962         RESULT=(new ParseNode("flag",parser.lexer.line_num)).addChild(flag).getRoot(); 
963         :}      
964         |
965         field_declaration:field {: 
966         RESULT=(new ParseNode("field",parser.lexer.line_num)).addChild(field).getRoot(); 
967         :}
968         |       method_declaration:method {:
969         RESULT=(new ParseNode("method",parser.lexer.line_num)).addChild(method).getRoot(); 
970         :}
971         /* repeat the prod for 'class_declaration' here: */
972         |       modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo class_body:body
973         {:
974         ParseNode pn=new ParseNode("inner_class_declaration",parser.lexer.line_num);
975         pn.addChild("modifiers").addChild(mo);
976         pn.addChild("name").addChild(id);
977         pn.addChild("super").addChild(so);
978         pn.addChild("superIF").addChild(ifo);
979         pn.addChild("classbody").addChild(body);
980         RESULT=pn;
981         :}
982         |       enum_declaration:ed
983         {:
984         RESULT=ed; 
985         :}
986     |       interface_declaration:interfaced {: RESULT=interfaced; :}
987         |       SEMICOLON       {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
988         ;
989         
990 // mgc
991 // JSR-201) Enum Declaration
992 enum_declaration ::=
993                 modifiers_opt:mo ENUM IDENTIFIER:id /*interfaces_opt:io*/ enum_body:body
994                 {:
995                         ParseNode pn=new ParseNode("enum_declaration",parser.lexer.line_num);
996                         pn.addChild("modifiers").addChild(mo);
997                         pn.addChild("name").addChild(id);
998                         //pn.addChild("superIF").addChild(ifo);
999                         pn.addChild("enumbody").addChild(body);
1000                         RESULT=pn;
1001                 :}
1002         ;
1003 enum_body ::=
1004                 LBRACE enum_constants_opt:eco /*enum_body_declarations_opt:ebdo*/ RBRACE
1005                 {: RESULT=eco; :}
1006         ;
1007 enum_constants_opt ::=
1008   {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1009         |       enum_constants:ecs
1010         {: RESULT=ecs; :}
1011         ;
1012 enum_constants ::=
1013                 enum_constant:ec {: 
1014                 ParseNode pn=new ParseNode("enum_constants_list",parser.lexer.line_num);
1015                 pn.addChild(ec);
1016                 RESULT=pn;
1017         :}
1018         |       enum_constants:ecs COMMA enum_constant:ec {:
1019             ecs.addChild(ec);
1020             RESULT=ecs;
1021         :}
1022         ;
1023 enum_constant ::=
1024                 IDENTIFIER:id /*enum_arguments_opt*/
1025                 {: 
1026                     ParseNode pn=new ParseNode("enum_constant",parser.lexer.line_num);
1027                     pn.addChild("name").addChild(id);
1028                     RESULT=pn; 
1029                 :}
1030 //      |       IDENTIFIER enum_arguments_opt class_body
1031         ;
1032 //enum_arguments_opt ::=
1033 //      |       LPAREN argument_list_opt RPAREN
1034 //      ;
1035 //enum_body_declarations_opt ::=
1036 //      |       SEMICOLON class_body_declarations_opt:cbdo
1037 //      ;
1038
1039 //Failure aware computation
1040 flag_declaration ::= 
1041                 FLAG IDENTIFIER:id SEMICOLON {: 
1042                 ParseNode pn=new ParseNode("flag_declaration",parser.lexer.line_num);
1043                 pn.addChild("name").addChild(id);
1044                 RESULT=pn;
1045         :}      |
1046                 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {: 
1047                 ParseNode pn=new ParseNode("flag_declaration",parser.lexer.line_num);
1048                 pn.addChild("name").addChild(id);
1049                 pn.addChild("external");
1050                 RESULT=pn;
1051         :}
1052         ;
1053
1054 // 19.8.2) Field Declarations
1055 field_declaration ::= 
1056                 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {: 
1057                 ParseNode pn=new ParseNode("field_declaration",parser.lexer.line_num);
1058                 pn.addChild("modifier").addChild(mo);
1059                 pn.addChild("type").addChild(type);
1060                 pn.addChild("variables").addChild(var);
1061                 RESULT=pn;
1062         :} |
1063                 modifiers_opt:mo GLOBAL type:type variable_declarators:var SEMICOLON {: 
1064                 ParseNode pn=new ParseNode("field_declaration",parser.lexer.line_num);
1065                 pn.addChild("modifier").addChild(mo);
1066                 pn.addChild("type").addChild(type);
1067                 pn.addChild("variables").addChild(var);
1068                 pn.addChild("global");
1069                 RESULT=pn;
1070         :}
1071         ;
1072
1073 variable_declarators ::=
1074                 variable_declarator:vd {: 
1075                 ParseNode pn=new ParseNode("variable_declarators_list",parser.lexer.line_num);
1076                 pn.addChild(vd);
1077                 RESULT=pn;
1078         :}
1079         |       variable_declarators:vds COMMA variable_declarator:vd {:
1080                 vds.addChild(vd);
1081                 RESULT=vds;
1082         :}
1083         ;
1084 variable_declarator ::=
1085                 variable_declarator_id:id {:
1086                 ParseNode pn=new ParseNode("variable_declarator",parser.lexer.line_num);
1087                 pn.addChild(id);
1088                 RESULT=pn;
1089         :}
1090         |       variable_declarator_id:id EQ variable_initializer:init {: 
1091                 ParseNode pn=new ParseNode("variable_declarator",parser.lexer.line_num);
1092                 pn.addChild(id);
1093                 pn.addChild("initializer").addChild(init);
1094                 RESULT=pn;
1095         :}
1096         ;
1097 variable_declarator_id ::=
1098                 IDENTIFIER:id {: 
1099                 RESULT=(new ParseNode("single",parser.lexer.line_num)).addChild(id).getRoot();:}
1100         |       variable_declarator_id:id LBRACK RBRACK {:
1101                 RESULT=(new ParseNode("array",parser.lexer.line_num)).addChild(id).getRoot();:}
1102         ;
1103 variable_initializer ::=
1104                 expression:exp {: RESULT=exp; :}
1105         |       array_initializer:ai {: RESULT=(new ParseNode("array_initializer",parser.lexer.line_num)).addChild(ai).getRoot(); :}
1106         ;
1107
1108 // 19.8.3) Method Declarations
1109 method_declaration ::=
1110                 method_header:header method_body:body {:
1111                 ParseNode pn=new ParseNode("method_declaration",parser.lexer.line_num);
1112                 pn.addChild(header);
1113                 pn.addChild("body").addChild(body);
1114                 RESULT=pn;
1115         :}
1116         ;
1117 method_header ::=
1118                 modifiers_opt:mo type:type method_declarator:decl throws_opt:to 
1119         {:
1120                 ParseNode pn=new ParseNode("method_header",parser.lexer.line_num);
1121                 pn.addChild("modifiers").addChild(mo);
1122                 pn.addChild("returntype").addChild(type);
1123                 pn.addChild("throws").addChild(to);
1124                 pn.addChild(decl);
1125                 RESULT=pn;
1126         :}
1127         |       modifiers_opt:mo VOID method_declarator:decl throws_opt:to
1128         {:
1129                 ParseNode pn=new ParseNode("method_header",parser.lexer.line_num);
1130                 pn.addChild("modifiers").addChild(mo);
1131                 pn.addChild("throws").addChild(to);
1132                 pn.addChild(decl);
1133                 RESULT=pn;
1134         :}
1135         ;
1136 method_declarator ::=
1137                 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {: 
1138                 ParseNode pn=new ParseNode("method_declarator",parser.lexer.line_num);
1139                 pn.addChild("name").addChild(id);
1140                 pn.addChild("parameters").addChild(params);
1141                 RESULT=pn;
1142         :}
1143 //      |       method_declarator LBRACK RBRACK // deprecated
1144 // be careful; the above production also allows 'void foo() []'
1145         ;
1146 formal_parameter_list_opt ::=
1147         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1148         |       formal_parameter_list:fpl {: 
1149                 RESULT=fpl;
1150         :}
1151         ;
1152 formal_parameter_list ::=
1153                 formal_parameter:fp {: 
1154                 ParseNode pn=new ParseNode("formal_parameter_list",parser.lexer.line_num);
1155                 pn.addChild(fp);
1156                 RESULT=pn;
1157         :}
1158         |       formal_parameter_list:fpl COMMA formal_parameter:fp {: 
1159                 fpl.addChild(fp);
1160                 RESULT=fpl;
1161         :}
1162         ;
1163 formal_parameter ::=
1164                 type:type variable_declarator_id:name {:
1165                 ParseNode pn=new ParseNode("formal_parameter",parser.lexer.line_num);
1166                 pn.addChild(type);
1167                 pn.addChild(name);
1168                 RESULT=pn;
1169         :}
1170         |
1171                 TAG variable_declarator_id:name {:
1172                 ParseNode pn=new ParseNode("tag_parameter",parser.lexer.line_num);
1173                 pn.addChild(name);
1174                 RESULT=pn;
1175         :}
1176         |       FINAL type:type variable_declarator_id:name {:
1177                 ParseNode pn=new ParseNode("formal_parameter",parser.lexer.line_num);
1178                 pn.addChild(type);
1179                 pn.addChild(name);
1180                 RESULT=pn;
1181         :}
1182         |       annotations:an type:type variable_declarator_id:name {:
1183                 ParseNode pn=new ParseNode("annotation_parameter",parser.lexer.line_num);
1184                 pn.addChild(type);
1185                 pn.addChild(name);
1186                 pn.addChild(an);
1187                 RESULT=pn;
1188         :}
1189         ;
1190 throws_opt ::=  
1191         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1192         |       throws:trs
1193             {: RESULT=trs; :}
1194         ;
1195 throws ::=      THROWS class_type_list:ctl
1196         {: RESULT=(new ParseNode("throw_list",parser.lexer.line_num)).addChild(ctl).getRoot(); :}
1197         ;
1198 class_type_list ::=
1199                 class_type:ct
1200                 {: 
1201                 ParseNode pn=new ParseNode("class_type_list",parser.lexer.line_num);
1202                 pn.addChild(ct);
1203                 RESULT=pn; 
1204                 :}
1205         |       class_type_list:ctl COMMA class_type:ct
1206             {: 
1207             ctl.addChild(ct);
1208             RESULT=ctl; 
1209             :}
1210         ;
1211 method_body ::= block:block {: 
1212                 RESULT=block;
1213         :}
1214         |       SEMICOLON       {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1215         ;
1216
1217 // 19.8.4) Static Initializers
1218 static_initializer ::=
1219                 STATIC block:body {:
1220                 ParseNode pn=new ParseNode("static_block_declaration",parser.lexer.line_num);
1221                 pn.addChild("body").addChild(body);
1222                 RESULT=pn;
1223         :}
1224         ;
1225
1226 // 19.8.5) Constructor Declarations
1227 constructor_declaration ::=
1228                 modifiers_opt:mo constructor_declarator:cd throws_opt:to 
1229                         constructor_body:body   {:
1230                 ParseNode pn=new ParseNode("constructor_declaration",parser.lexer.line_num);
1231                 pn.addChild("modifiers").addChild(mo);
1232                 pn.addChild("throws").addChild(to);
1233                 pn.addChild(cd);
1234                 pn.addChild("body").addChild(body);
1235                 RESULT=pn;
1236         :} |
1237                 modifiers_opt:mo GLOBAL constructor_declarator:cd throws_opt:to 
1238                         constructor_body:body   {:
1239                 ParseNode pn=new ParseNode("constructor_declaration",parser.lexer.line_num);
1240                 pn.addChild("global");
1241                 pn.addChild("modifiers").addChild(mo);
1242                 pn.addChild("throws").addChild(to);
1243                 pn.addChild(cd);
1244                 pn.addChild("body").addChild(body);
1245                 RESULT=pn;
1246         :}
1247 ;
1248
1249 constructor_declarator ::=
1250                 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {: 
1251                 ParseNode pn=new ParseNode("constructor_declarator",parser.lexer.line_num);
1252                 pn.addChild(name);
1253                 pn.addChild("parameters").addChild(fplo);
1254                 RESULT=pn;
1255         :}
1256         ;
1257 constructor_body ::=
1258                 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {: 
1259                         ParseNode pn=new ParseNode("constructor_body",parser.lexer.line_num);
1260                         pn.addChild(eci);
1261                         pn.addChild(bs);
1262                         RESULT=pn;
1263         :} |
1264                 LBRACE explicit_constructor_invocation:eci RBRACE {: 
1265                         ParseNode pn=new ParseNode("constructor_body",parser.lexer.line_num);
1266                         pn.addChild(eci);
1267                         RESULT=pn;
1268         :} |
1269                 LBRACE block_statements:block RBRACE {: 
1270                 ParseNode pn=new ParseNode("constructor_body",parser.lexer.line_num);
1271                 pn.addChild(block);
1272                 RESULT=pn;
1273         :}
1274         |       LBRACE RBRACE {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1275         ;
1276 explicit_constructor_invocation ::=
1277         THIS LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1278              ParseNode pn=new ParseNode("explconstrinv",parser.lexer.line_num);
1279              pn.addChild(alo);
1280              RESULT=pn;
1281         :}
1282         |       
1283 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {: 
1284         ParseNode pn=new ParseNode("superinvoke",parser.lexer.line_num);
1285         pn.addChild(alo);
1286         RESULT=pn;
1287 :}
1288         |       primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1289         |       primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1290         ;
1291
1292 // 19.9) Interfaces
1293
1294 // 19.9.1) Interface Declarations
1295 interface_declaration ::=
1296                modifiers_opt:mo INTERFACE IDENTIFIER:id extends_interfaces_opt:io
1297                        interface_body:body
1298        {:
1299         ParseNode pn=new ParseNode("interface_declaration",parser.lexer.line_num);
1300         pn.addChild("modifiers").addChild(mo);
1301         pn.addChild("name").addChild(id);
1302         pn.addChild("superIF").addChild(io);
1303         pn.addChild("interfacebody").addChild(body);
1304         RESULT=pn;
1305         :}
1306        | annotation_type_declaration:atd{:
1307         RESULT=atd;
1308        :}
1309        ;
1310 extends_interfaces_opt ::=
1311        {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1312        |       extends_interfaces:eifs {: RESULT=eifs; :}
1313        ;
1314 extends_interfaces ::=
1315                EXTENDS interface_type:ift 
1316                {: 
1317                ParseNode pn=new ParseNode("extend_interface_list",parser.lexer.line_num);
1318                pn.addChild(ift);
1319                RESULT=pn; 
1320                :}
1321      |       extends_interfaces:eifs COMMA interface_type:ift
1322              {:
1323              eifs.addChild(ift);
1324              RESULT=eifs;
1325              :}
1326        ;
1327 interface_body ::=
1328                LBRACE interface_member_declarations_opt:imdo RBRACE
1329                {: RESULT=imdo; :}
1330        ;
1331 interface_member_declarations_opt ::=
1332        {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1333        |       interface_member_declarations:imd {: RESULT=imd; :}
1334        ;
1335 interface_member_declarations ::=
1336                interface_member_declaration:imd {: 
1337                         ParseNode pn=new ParseNode("interface_member_declaration_list",parser.lexer.line_num);
1338                         pn.addChild(imd);
1339                         RESULT=pn;
1340                 :}
1341        |       interface_member_declarations:imds interface_member_declaration:imd {: 
1342                         imds.addChild(imd);
1343                         RESULT=imds;
1344                 :}
1345        ;
1346 interface_member_declaration ::=
1347                constant_declaration:constant {: 
1348                 RESULT=(new ParseNode("constant",parser.lexer.line_num)).addChild(constant).getRoot();
1349         :}
1350        |       abstract_method_declaration:method {:
1351         RESULT=(new ParseNode("method",parser.lexer.line_num)).addChild(method).getRoot(); 
1352         :}
1353            |    enum_declaration:ed {:
1354            RESULT=(new ParseNode("enum_declaration",parser.lexer.line_num)).addChild(ed).getRoot();
1355            :}
1356 //       |       class_declaration:class 
1357        |       interface_declaration:interfaced {: RESULT=interfaced; :}
1358        |       SEMICOLON {: 
1359        RESULT=new ParseNode("empty",parser.lexer.line_num); 
1360        :}
1361        ;
1362 constant_declaration ::=
1363                field_declaration:fd {: RESULT=fd; :}
1364        // need to semantically check that modifiers of field declaration
1365        // include only PUBLIC, STATIC, or FINAL.  Other modifiers are
1366        // disallowed.
1367        ;
1368 abstract_method_declaration ::=
1369                method_header:header SEMICOLON {:
1370                 ParseNode pn=new ParseNode("method_declaration",parser.lexer.line_num);
1371                 pn.addChild("header").addChild(header);
1372                 pn.addChild("body").addChild(new ParseNode("empty",parser.lexer.line_num));
1373                 RESULT=pn;
1374         :}
1375        ;
1376
1377 annotation_type_declaration ::=
1378                 AT INTERFACE IDENTIFIER:id annotation_type_body:atb{:
1379                 ParseNode pn=new ParseNode("annotation_type_declaration",parser.lexer.line_num);
1380                 pn.addChild("name").addChild(id);
1381                 pn.addChild("body").addChild(atb);
1382                 RESULT=pn;
1383
1384         :}
1385         |       modifiers_at:ma INTERFACE IDENTIFIER:id annotation_type_body:atb{:
1386                 ParseNode pn=new ParseNode("annotation_type_declaration",parser.lexer.line_num);
1387                 pn.addChild("name").addChild(id);
1388                 pn.addChild("modifiers").addChild(ma);
1389                 pn.addChild("body").addChild(atb);              
1390                 RESULT=pn;              
1391         :}
1392         ;
1393 annotation_type_body ::=
1394                 LBRACE annotation_type_element_declarations_opt:atedo RBRACE{:
1395                 RESULT=atedo;
1396         :}
1397         ;
1398 annotation_type_element_declarations_opt ::={:
1399                 RESULT=new ParseNode("empty",parser.lexer.line_num);
1400         :}
1401         |       annotation_type_element_declarations:ated{:
1402                 RESULT=ated;
1403         :}
1404         ;
1405 annotation_type_element_declarations ::=
1406                 annotation_type_element_declaration:ated{:
1407                 ParseNode pn=new ParseNode("annotation_type_element_list",parser.lexer.line_num);
1408                 pn.addChild(ated);
1409                 RESULT=pn;
1410         :}
1411         |       annotation_type_element_declarations:ateds annotation_type_element_declaration:ated{:
1412                 ateds.addChild(ated);
1413                 RESULT=ateds;   
1414         :}
1415         ;
1416 annotation_type_element_declaration ::=
1417                 constant_declaration:cd {:
1418                 RESULT=cd;              
1419         :}
1420         |       modifiers_opt:mo type:type IDENTIFIER:id LPAREN RPAREN default_value_opt:dvo SEMICOLON {:
1421                 ParseNode pn=new ParseNode("annotation_type_element_declaration",parser.lexer.line_num);        
1422                 pn.addChild("modifier").addChild(mo);   
1423                 pn.addChild("type").addChild(type);
1424                 pn.addChild("name").addChild(id);
1425                 pn.addChild("defaultvalue").addChild(dvo);
1426                 RESULT=pn;
1427         :}
1428         |       class_declaration:cd{:
1429                 RESULT=cd;
1430         :} 
1431         |       enum_declaration:ed{:
1432                 RESULT=ed;
1433         :}
1434         |       interface_declaration:id{:
1435                 RESULT=id;
1436         :}
1437         |       SEMICOLON{:
1438                 RESULT=new ParseNode("empty",parser.lexer.line_num);
1439         :}
1440         ;
1441 default_value_opt ::= {:
1442                 RESULT=new ParseNode("empty",parser.lexer.line_num);
1443         :}
1444         |       default_value:dv{:
1445                 RESULT=dv;
1446         :}
1447         ;
1448 default_value ::= DEFAULT element_value:ev {:
1449               RESULT=ev;
1450         :}
1451         ;
1452
1453 // 19.10) Arrays
1454 array_initializer ::=
1455                 LBRACE variable_initializers:var_init_list COMMA RBRACE {:
1456                        RESULT=var_init_list;
1457                 :}
1458         |       LBRACE variable_initializers:var_init_list RBRACE {:
1459                        RESULT=var_init_list;
1460                 :}
1461         |       LBRACE COMMA RBRACE {:
1462                        RESULT=new ParseNode("empty",parser.lexer.line_num);                    
1463                 :}
1464         |       LBRACE RBRACE {:
1465                        RESULT=new ParseNode("empty",parser.lexer.line_num);
1466                 :}
1467         ;
1468 variable_initializers ::=
1469                 variable_initializer:var_init {:
1470                        ParseNode pn=new ParseNode("var_init_list",parser.lexer.line_num);
1471                        pn.addChild(var_init);
1472                        RESULT=pn;
1473                 :}
1474         |       variable_initializers:var_init_list COMMA variable_initializer:var_init {:
1475                        var_init_list.addChild(var_init);
1476                        RESULT=var_init_list;
1477                 :}
1478         ;
1479
1480 // 19.11) Blocks and Statements
1481 block ::=       LBRACE block_statements_opt:bso RBRACE {: 
1482         RESULT=bso;
1483         :}
1484         ;
1485 block_statements_opt ::=
1486         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1487         |       block_statements:bs {: 
1488         RESULT=bs;
1489         :}
1490         ;
1491 block_statements ::=
1492                 block_statement:bs {:
1493         ParseNode pn=new ParseNode("block_statement_list",parser.lexer.line_num);
1494         pn.addChild(bs);
1495         RESULT=pn;
1496         :}
1497         |       block_statements:bss block_statement:bs {: 
1498         bss.addChild(bs);
1499         RESULT=bss;
1500         :}
1501         ;
1502 block_statement ::=
1503         tag_variable_declaration_statement:tvds {:
1504                 RESULT=tvds;
1505         :}              
1506         |       local_variable_declaration_statement:lvds {: 
1507                 RESULT=lvds;
1508         :}
1509         |       statement:statement {: 
1510                 RESULT=statement;
1511         :}
1512 //      |       enum_declaration:ed {:
1513 //              RESULT=ed;
1514 //      :}
1515 //      |       class_declaration
1516 //      |       interface_declaration
1517         ;
1518 tag_variable_declaration_statement ::=
1519                 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {: 
1520                 ParseNode pn=new ParseNode("tag_declaration",parser.lexer.line_num);
1521                 pn.addChild("single").addChild(id);
1522                 pn.addChild("type").addChild(type);
1523                 RESULT=pn;
1524         :}
1525         ;
1526 local_variable_declaration_statement ::=
1527                 local_variable_declaration:lvd SEMICOLON {: 
1528                 RESULT=lvd;
1529         :}
1530         ;
1531 local_variable_declaration ::=
1532                 type:type variable_declarators:var {: 
1533                 ParseNode pn=new ParseNode("local_variable_declaration",parser.lexer.line_num);
1534                 pn.addChild(type);
1535                 pn.addChild(var);
1536                 RESULT=pn;
1537         :}
1538 //      |       FINAL type:type variable_declarators:var {: 
1539          /* CAUTION:  only FINAL and annotations are legal modifiers here */
1540         |       modifiers:mo type:type variable_declarators:var {:
1541                 ParseNode pn=new ParseNode("local_variable_declaration",parser.lexer.line_num);
1542                 pn.addChild(type);
1543                 pn.addChild(var);
1544                 pn.addChild("modifiers").addChild(mo);
1545                 RESULT=pn;
1546         :}
1547         ;
1548 statement ::=   statement_without_trailing_substatement:st {: 
1549                 RESULT=st;
1550         :}
1551         |       labeled_statement:st {: RESULT=st; :}
1552         |       if_then_statement:st {: RESULT=st; :}
1553         |       if_then_else_statement:st {: RESULT=st; :}
1554         |       while_statement:st {: RESULT=st; :}
1555         |       for_statement:st {: RESULT=st; :}
1556         ;
1557 statement_no_short_if ::=
1558                 statement_without_trailing_substatement:st {: RESULT=st; :}
1559         |       labeled_statement_no_short_if:st {: RESULT=st; :}
1560         |       if_then_else_statement_no_short_if:st {: RESULT=st; :}
1561         |       while_statement_no_short_if:st {: RESULT=st; :}
1562         |       for_statement_no_short_if:st {: RESULT=st; :}
1563         ;
1564 statement_without_trailing_substatement ::=
1565                 block:st {: RESULT=st; :}
1566         |       empty_statement:st {: RESULT=st; :}
1567         |       expression_statement:st {: RESULT=st; :}
1568         |       switch_statement:st {: RESULT=st; :}
1569         |       do_statement:dos {:RESULT=dos; :}
1570         |       break_statement:st {: RESULT=st; :}
1571         |       continue_statement:st {: RESULT=st; :}
1572         |       return_statement:st {: RESULT=st; :}
1573         |       task_exitstatement:st {: RESULT=st; :}
1574         |       atomic_statement:st {: RESULT=st; :}
1575         |       sese_statement:st {: RESULT=st; :}
1576         |       synchronized_statement:st {: RESULT=st; :}
1577         |       genreach_statement:st {: RESULT=st; :}
1578         |       throw_statement:st {: RESULT=st; :}
1579         |       try_statement:st {: RESULT=st; :}
1580 //      |       assert_statement
1581         ;
1582 empty_statement ::=
1583                 SEMICOLON {: RESULT=new ParseNode("nop",parser.lexer.line_num); :}
1584         ;
1585 labeled_statement ::=
1586                 IDENTIFIER:id COLON statement:st {:
1587                 ParseNode pn=new ParseNode("labeledstatement",parser.lexer.line_num);
1588                 pn.addChild("name").addChild(id);
1589                 pn.addChild("statement").addChild(st);
1590                 RESULT=pn;                              
1591                 :}
1592         ;
1593 labeled_statement_no_short_if ::=
1594                 IDENTIFIER:id COLON statement_no_short_if:st {:
1595                 ParseNode pn=new ParseNode("labeledstatement",parser.lexer.line_num);
1596                 pn.addChild("name").addChild(id);
1597                 pn.addChild("statement").addChild(st);
1598                 RESULT=pn;                              
1599                 :}
1600         ;
1601 expression_statement ::=
1602                 statement_expression:se SEMICOLON {: 
1603                 ParseNode pn=new ParseNode("expression",parser.lexer.line_num);
1604                 pn.addChild(se);
1605                 RESULT=pn; :}
1606         ;
1607 statement_expression ::=
1608                 assignment:st {: RESULT=st; :}
1609         |       preincrement_expression:st {: RESULT=st; :}
1610         |       predecrement_expression:st {: RESULT=st; :}
1611         |       postincrement_expression:st {: RESULT=st; :}
1612         |       postdecrement_expression:st {: RESULT=st; :}
1613         |       method_invocation:st {: RESULT=st; :}
1614         |       class_instance_creation_expression:st {: RESULT=st; :}
1615         ;
1616 if_then_statement ::=
1617                 IF LPAREN expression:exp RPAREN statement:st {: 
1618                 ParseNode pn=new ParseNode("ifstatement",parser.lexer.line_num);
1619                 pn.addChild("condition").addChild(exp);
1620                 pn.addChild("statement").addChild(st);
1621                 RESULT=pn;
1622         :}
1623         ;
1624 if_then_else_statement ::=
1625                 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1626                         ELSE statement:else_st {:
1627                 ParseNode pn=new ParseNode("ifstatement",parser.lexer.line_num);
1628                 pn.addChild("condition").addChild(exp);
1629                 pn.addChild("statement").addChild(st);
1630                 pn.addChild("else_statement").addChild(else_st);
1631                 RESULT=pn;
1632         :}
1633         ;
1634 if_then_else_statement_no_short_if ::=
1635                 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1636                         ELSE statement_no_short_if:else_st {:
1637                 ParseNode pn=new ParseNode("ifstatement",parser.lexer.line_num);
1638                 pn.addChild("condition").addChild(exp);
1639                 pn.addChild("statement").addChild(st);
1640                 pn.addChild("else_statement").addChild(else_st);
1641                 RESULT=pn;
1642         :}
1643         ;
1644 switch_statement ::=
1645                 SWITCH LPAREN expression:exp RPAREN switch_block:body
1646                 {:
1647                     ParseNode pn=new ParseNode("switch_statement",parser.lexer.line_num);
1648                     pn.addChild("condition").addChild(exp);
1649                     pn.addChild("statement").addChild(body);
1650                     RESULT=pn;
1651                 :}
1652         ;
1653 switch_block ::=
1654                 LBRACE switch_block_statement_groups:sbsg switch_labels:sl RBRACE
1655                 {: 
1656                     ParseNode pn = new ParseNode("switch_block",parser.lexer.line_num);
1657                     pn.addChild("switch_labels").addChild(sl);
1658                     pn.addChild("switch_statements").addChild(new ParseNode("empty",parser.lexer.line_num));
1659                     sbsg.addChild(pn);
1660                     RESULT=sbsg; 
1661                 :}
1662         |       LBRACE switch_block_statement_groups:sbsg RBRACE
1663             {: 
1664                     RESULT=sbsg; 
1665                 :}
1666         |       LBRACE switch_labels:sl RBRACE 
1667             {: 
1668                 ParseNode pnb = new ParseNode("switch_block_list",parser.lexer.line_num);
1669                     ParseNode pn = new ParseNode("switch_block",parser.lexer.line_num);
1670                     pn.addChild("switch_labels").addChild(sl);
1671                     pn.addChild("switch_statements").addChild(new ParseNode("empty",parser.lexer.line_num));
1672                     pnb.addChild(pn);
1673                     RESULT=pnb; 
1674                 :}
1675         |       LBRACE RBRACE {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1676         ;
1677 switch_block_statement_groups ::=
1678                 switch_block_statement_group:sbsg
1679                 {: 
1680                     ParseNode pn = new ParseNode("switch_block_list",parser.lexer.line_num);
1681                     pn.addChild(sbsg);
1682                     RESULT=pn;
1683                 :}
1684         |       switch_block_statement_groups:sbsgs switch_block_statement_group:sbsg
1685             {:
1686                 sbsgs.addChild(sbsg);
1687                 RESULT=sbsgs;
1688             :}
1689         ;
1690 switch_block_statement_group ::=
1691                 switch_labels:sls block_statements:body
1692                 {: 
1693                     ParseNode pn=new ParseNode("switch_block",parser.lexer.line_num);
1694                     pn.addChild("switch_labels").addChild(sls);
1695                     pn.addChild("switch_statements").addChild(body);
1696                     RESULT=pn; 
1697                 :}
1698         ;
1699 switch_labels ::=
1700                 switch_label:sl
1701                 {: 
1702                     ParseNode pn=new ParseNode("switch_label_list",parser.lexer.line_num);
1703                     pn.addChild(sl);
1704                     RESULT=pn; 
1705                 :}
1706         |       switch_labels:sls switch_label:sl
1707             {: 
1708                     sls.addChild(sl); 
1709                     RESULT=sls;
1710                 :}
1711         ;
1712 switch_label ::=
1713                 CASE constant_expression:ce COLON
1714                 {: 
1715                     ParseNode pn=new ParseNode("switch_label",parser.lexer.line_num);
1716                     pn.addChild(ce);
1717                     RESULT=pn;
1718                 :}
1719         |       DEFAULT COLON
1720             {: 
1721                     RESULT=new ParseNode("default_switch_label",parser.lexer.line_num); 
1722                 :}
1723         ;
1724
1725 while_statement ::=
1726                 WHILE LPAREN expression:exp RPAREN statement:st {: 
1727                 ParseNode pn=new ParseNode("whilestatement",parser.lexer.line_num);
1728                 pn.addChild("condition").addChild(exp);
1729                 pn.addChild("statement").addChild(st);
1730                 RESULT=pn;
1731         :}
1732         ;
1733 while_statement_no_short_if ::=
1734                 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1735                 ParseNode pn=new ParseNode("whilestatement",parser.lexer.line_num);
1736                 pn.addChild("condition").addChild(exp);
1737                 pn.addChild("statement").addChild(st);
1738                 RESULT=pn;
1739                 :}
1740         ;
1741 do_statement ::=
1742                 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {: 
1743                 ParseNode pn=new ParseNode("dowhilestatement",parser.lexer.line_num);
1744                 pn.addChild("condition").addChild(exp);
1745                 pn.addChild("statement").addChild(st);
1746                 RESULT=pn;
1747         :}
1748         ;
1749 for_statement ::=
1750                 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1751                         for_update_opt:update RPAREN statement:st {: 
1752                 ParseNode pn=new ParseNode("forstatement",parser.lexer.line_num);
1753                 pn.addChild("initializer").addChild(init);
1754                 pn.addChild("condition").addChild(exp);
1755                 pn.addChild("update").addChild(update);
1756                 pn.addChild("statement").addChild(st);
1757                 RESULT=pn;
1758                 :}
1759         ;
1760 for_statement_no_short_if ::=
1761                 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1762                         for_update_opt:update RPAREN statement_no_short_if:st {:
1763                 ParseNode pn=new ParseNode("forstatement",parser.lexer.line_num);
1764                 pn.addChild("initializer").addChild(init);
1765                 pn.addChild("condition").addChild(exp);
1766                 pn.addChild("update").addChild(update);
1767                 pn.addChild("statement").addChild(st);
1768                 RESULT=pn;
1769                 :}
1770         ;
1771 for_init_opt ::=
1772         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1773         |       for_init:init {: RESULT=init; :}
1774         ;
1775 for_init ::=    statement_expression_list:list {: RESULT=list; :}
1776         |       local_variable_declaration:decl {: RESULT=decl; :}
1777         ;
1778 for_update_opt ::=
1779         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1780         |       for_update:update {: RESULT=update; :}
1781         ;
1782 for_update ::=  statement_expression_list:list {: RESULT=list; :}
1783         ;
1784 statement_expression_list ::=
1785                 statement_expression:expr {: 
1786                 RESULT=(new ParseNode("statement_expression_list",parser.lexer.line_num)).addChild(expr).getRoot();
1787         :}
1788         |       statement_expression_list:list COMMA statement_expression:expr {: 
1789                 list.addChild(expr);
1790                 RESULT=list;
1791         :}
1792         ;
1793
1794 identifier_opt ::= {: RESULT=new ParseNode("identifier_opt",parser.lexer.line_num);
1795         :} 
1796         |       IDENTIFIER:id {:
1797                 ParseNode pn=new ParseNode("identifier_opt",parser.lexer.line_num);
1798                 pn.addChild("name").addChild(id);
1799                 RESULT=pn;
1800         :}
1801         ;
1802
1803 break_statement ::=
1804                 BREAK identifier_opt:id SEMICOLON {: 
1805                 ParseNode pn=new ParseNode("break",parser.lexer.line_num);              
1806                 pn.addChild(id);
1807                 RESULT=pn;
1808         :}
1809         ;
1810
1811 continue_statement ::=
1812                 CONTINUE  
1813 //identifier_opt 
1814 SEMICOLON
1815 {: RESULT=new ParseNode("continue",parser.lexer.line_num); :}
1816         ;
1817 return_statement ::=
1818                 RETURN expression_opt:exp SEMICOLON {: 
1819         RESULT=(new ParseNode("return",parser.lexer.line_num)).addChild(exp).getRoot(); :}
1820         ;
1821 throw_statement ::=
1822                 THROW expression:exp SEMICOLON {:
1823                 RESULT=(new ParseNode("throwstatement",parser.lexer.line_num)).addChild(exp).getRoot();
1824                 :}
1825         ;
1826 synchronized_statement ::=
1827                 SYNCHRONIZED LPAREN expression:e RPAREN block:b {: 
1828                 ParseNode pn=new ParseNode("synchronized",parser.lexer.line_num);
1829                 pn.addChild("expr").addChild(e);
1830                 pn.addChild("block").addChild(b);
1831                 RESULT=pn;
1832                 :}
1833         ;
1834 atomic_statement ::=
1835                 ATOMIC block:blk {: 
1836         RESULT=(new ParseNode("atomic",parser.lexer.line_num)).addChild(blk).getRoot();
1837         :}
1838         ;
1839 sese_statement ::=
1840                SESE block:blk {: 
1841                ParseNode pn = new ParseNode("sese",parser.lexer.line_num);
1842                pn.addChild("body").addChild(blk);
1843                RESULT=pn;
1844         :}
1845         |      SESE variable_declarator_id:id block:blk {: 
1846                ParseNode pn = new ParseNode("sese",parser.lexer.line_num);
1847                pn.addChild("body").addChild(blk);
1848                pn.addChild("identifier").addChild(id);
1849                RESULT=pn;
1850         :}
1851         |      RBLOCK block:blk {: 
1852                ParseNode pn = new ParseNode("sese",parser.lexer.line_num);
1853                pn.addChild("body").addChild(blk);
1854                RESULT=pn;
1855         :}
1856         |      RBLOCK variable_declarator_id:id block:blk {: 
1857                ParseNode pn = new ParseNode("sese",parser.lexer.line_num);
1858                pn.addChild("body").addChild(blk);
1859                pn.addChild("identifier").addChild(id);
1860                RESULT=pn;
1861         :}
1862         ;
1863 try_statement ::=
1864                 TRY block:bk catches:ca
1865                 {: 
1866                 ParseNode pn=new ParseNode("trycatchstatement",parser.lexer.line_num);
1867                 pn.addChild("tryblock").addChild(bk); 
1868                 pn.addChild("catchblock").addChild(ca);
1869                 RESULT=pn;
1870                 :}
1871         |       TRY block:bk catches_opt:ca finally:fi
1872             {: 
1873                 ParseNode pn=new ParseNode("trycatchstatement",parser.lexer.line_num);
1874                 pn.addChild("tryblock").addChild(bk); 
1875                 pn.addChild("catchblock").addChild(ca);
1876                 pn.addChild("finallyblock").addChild(fi);
1877                 RESULT=pn;
1878                 :}
1879         ;
1880 catches_opt ::=
1881     {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
1882         |       catches:ca
1883         {: RESULT=ca; :}
1884         ;
1885 catches ::=     catch_clause:ca
1886         {:
1887         ParseNode pn=new ParseNode("catchlist",parser.lexer.line_num);
1888         pn.addChild(ca);
1889         RESULT=pn;
1890         :}
1891         |       catches:cas catch_clause:ca 
1892             {:
1893             cas.addChild(ca);
1894             RESULT=cas;
1895             :}
1896         ;
1897 catch_clause ::=
1898                 CATCH LPAREN formal_parameter:fp RPAREN block:bk
1899                 {:
1900                 ParseNode pn=new ParseNode("catchclause",parser.lexer.line_num);
1901                 pn.addChild("parameter").addChild(fp);
1902                 pn.addChild("block").addChild(bk);
1903                 RESULT=pn;
1904                 :}
1905         ;
1906 finally ::=     FINALLY block:bk
1907     {:
1908     RESULT=bk;
1909     :}
1910         ;
1911 //assert_statement ::=
1912 //              ASSERT expression SEMICOLON
1913 //      |       ASSERT expression COLON expression SEMICOLON
1914 //      ;
1915
1916 // 19.12) Expressions
1917 primary ::=     primary_no_new_array:st {: 
1918                 RESULT=st; :}
1919         |       array_creation_init:st {: 
1920                 RESULT=st;
1921         :}
1922         |       array_creation_uninit:st {:
1923                 RESULT=st;
1924         :}
1925         ;
1926 primary_no_new_array ::=
1927                 literal:lit {: RESULT=lit; :}
1928         |       THIS {: RESULT=new ParseNode("this",parser.lexer.line_num); :}
1929         |       LPAREN expression:exp RPAREN {: RESULT=exp; :}
1930         |       class_instance_creation_expression:exp {: RESULT=exp; :}
1931         |       field_access:exp {: RESULT=exp; :}
1932         |       method_invocation:exp {: RESULT=exp; :}
1933         |       array_access:exp {: RESULT=exp; :}
1934         |       ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {: 
1935                 ParseNode pn=new ParseNode("isavailable",parser.lexer.line_num);
1936                 pn.addChild(id);
1937                 RESULT=pn;
1938         :}
1939 //      |       primitive_type:pt DOT CLASS {:
1940 //          ParseNode pn=new ParseNode("class_type",parser.lexer.line_num);
1941 //          pn.addChild(pt);
1942 //          RESULT=pn;
1943 //      :}
1944 //      |       VOID DOT CLASS
1945 //      |       array_type:at DOT CLASS {:
1946 //          ParseNode pn=new ParseNode("class_type",parser.lexer.line_num);
1947 //          pn.addChild(at);
1948 //          RESULT=pn;
1949 //      :}
1950         |       name:name DOT CLASS {:
1951             ParseNode pn=new ParseNode("class_type",parser.lexer.line_num);
1952             pn.addChild("type").addChild("class").addChild(name);
1953             RESULT=pn;
1954         :}
1955         |       name:name DOT THIS {: 
1956             ParseNode pn=new ParseNode("parentclass",parser.lexer.line_num);
1957             pn.addChild("name").addChild(name);
1958             RESULT=pn;
1959         :}
1960         ;
1961 class_instance_creation_expression ::=
1962         NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {: 
1963                 ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
1964                 pn.addChild(type);
1965                 pn.addChild(args);
1966                 pn.addChild(feo);
1967                 RESULT=pn;
1968         :} |
1969         NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: 
1970                 ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
1971                 pn.addChild(type);
1972                 pn.addChild(args);
1973                 RESULT=pn;
1974         :} 
1975         //Global object
1976         | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: 
1977                 ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
1978                 pn.addChild(type);
1979                 pn.addChild(args);
1980                 pn.addChild("global");
1981                 RESULT=pn;
1982         :}
1983         | SCRATCH NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {: 
1984                 ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
1985                 pn.addChild(type);
1986                 pn.addChild(args);
1987                 pn.addChild("scratch");
1988                 RESULT=pn;
1989         :}
1990         // Objects we want to track in disjointness analysis
1991         | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: 
1992                 ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
1993                 pn.addChild(type);
1994                 pn.addChild(args);
1995                 pn.addChild("disjoint").addChild(id);
1996                 RESULT=pn;
1997         :}
1998         | NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {: 
1999                 ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
2000                 pn.addChild(type);
2001                 pn.addChild(args);
2002                 pn.addChild(tl);
2003                 RESULT=pn;
2004         :}
2005         | NEWFLAG class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {: 
2006                 ParseNode pn=new ParseNode("createobject",parser.lexer.line_num);
2007                 pn.addChild(type);
2008                 pn.addChild(args);
2009                 pn.addChild(fl);
2010                 pn.addChild(tl);
2011                 RESULT=pn;
2012         :}
2013         |       NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN class_body:body {: 
2014                 ParseNode pn=new ParseNode("createobjectcls",parser.lexer.line_num);          
2015                 pn.addChild(type);
2016                 pn.addChild(args);
2017                 pn.addChild("decl").addChild("classbody").addChild(body);
2018                 RESULT=pn;
2019         :}
2020 //      |       primary DOT NEW IDENTIFIER
2021 //                      LPAREN argument_list_opt RPAREN {: 
2022 //              
2023 //      :}
2024 //      |       primary DOT NEW IDENTIFIER
2025 //                      LPAREN argument_list_opt RPAREN class_body
2026 //      |       name DOT NEW IDENTIFIER
2027 //                      LPAREN argument_list_opt RPAREN
2028 //      |       name DOT NEW IDENTIFIER
2029 //                      LPAREN argument_list_opt RPAREN class_body
2030         ;
2031 cons_argument_list_opt ::=
2032         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
2033         |       cons_argument_list:args {: RESULT=args; :}
2034         ;
2035
2036 cons_argument_list ::=
2037                 IDENTIFIER:id COLON expression:exp {:
2038                 ParseNode pn=new ParseNode("cons_argument_list",parser.lexer.line_num);
2039                 ParseNode pnarg=pn.addChild("binding");
2040                 pnarg.addChild("var").addChild(id);
2041                 pnarg.addChild("exp").addChild(exp);
2042                 RESULT=pn;
2043         :}
2044         |       argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
2045                 ParseNode pnarg=new ParseNode("binding",parser.lexer.line_num);
2046                 pnarg.addChild("var").addChild(id);
2047                 pnarg.addChild("exp").addChild(exp);
2048                 list.addChild(pnarg);
2049                 RESULT=list;
2050         :}
2051         ;
2052
2053 argument_list_opt ::=
2054         {: RESULT=new ParseNode("empty",parser.lexer.line_num); :}
2055         |       argument_list:args {: RESULT=args; :}
2056         ;
2057
2058 argument_list ::=
2059                 expression:exp {:
2060                 ParseNode pn=new ParseNode("argument_list",parser.lexer.line_num);
2061                 pn.addChild(exp);
2062                 RESULT=pn;
2063         :}
2064         |       argument_list:list COMMA expression:exp {:
2065                 list.addChild(exp);
2066                 RESULT=list;
2067         :}
2068         ;
2069 array_creation_uninit ::=
2070                 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
2071                 ParseNode pn=new ParseNode("createarray",parser.lexer.line_num);
2072                 pn.addChild(type);
2073                 pn.addChild(dimexpr);
2074                 pn.addChild("dims_opt").setLiteral(dims);
2075                 RESULT=pn;
2076                 :}
2077         |       NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
2078                 ParseNode pn=new ParseNode("createarray",parser.lexer.line_num);
2079                 pn.addChild(type);
2080                 pn.addChild(dimexpr);
2081                 pn.addChild("dims_opt").setLiteral(dims);
2082                 RESULT=pn;
2083         :}
2084         |       GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
2085                 ParseNode pn=new ParseNode("createarray",parser.lexer.line_num);
2086                 pn.addChild(type);
2087                 pn.addChild(dimexpr);
2088                 pn.addChild("dims_opt").setLiteral(dims);
2089                 pn.addChild("global");
2090                 RESULT=pn;
2091                 :}
2092         |       SCRATCH NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
2093                 ParseNode pn=new ParseNode("createarray",parser.lexer.line_num);
2094                 pn.addChild(type);
2095                 pn.addChild(dimexpr);
2096                 pn.addChild("dims_opt").setLiteral(dims);
2097                 pn.addChild("scratch");
2098                 RESULT=pn;
2099                 :}
2100         |       DISJOINT IDENTIFIER:id NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
2101                 ParseNode pn=new ParseNode("createarray",parser.lexer.line_num);
2102                 pn.addChild(type);
2103                 pn.addChild(dimexpr);
2104                 pn.addChild("dims_opt").setLiteral(dims);
2105                 pn.addChild("disjoint").addChild(id);
2106                 RESULT=pn;
2107                 :}
2108         |       GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
2109                 ParseNode pn=new ParseNode("createarray",parser.lexer.line_num);
2110                 pn.addChild(type);
2111                 pn.addChild(dimexpr);
2112                 pn.addChild("dims_opt").setLiteral(dims);
2113                 pn.addChild("global");
2114                 RESULT=pn;
2115                 :}
2116         |       SCRATCH NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
2117                 ParseNode pn=new ParseNode("createarray",parser.lexer.line_num);
2118                 pn.addChild(type);
2119                 pn.addChild(dimexpr);
2120                 pn.addChild("dims_opt").setLiteral(dims);
2121                 pn.addChild("scratch");
2122                 RESULT=pn;
2123                 :}
2124         |       DISJOINT IDENTIFIER:id NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
2125                 ParseNode pn=new ParseNode("createarray",parser.lexer.line_num);
2126                 pn.addChild(type);
2127                 pn.addChild(dimexpr);
2128                 pn.addChild("dims_opt").setLiteral(dims);
2129                 pn.addChild("disjoint").addChild(id);           
2130                 RESULT=pn;
2131                 :}
2132         ;
2133 array_creation_init ::=
2134                 NEW primitive_type:type dims:dims array_initializer:ai {: 
2135                 ParseNode pn=new ParseNode("createarray2",parser.lexer.line_num);
2136                 pn.addChild(type);
2137                 pn.addChild("dims_opt").setLiteral(dims);
2138                 pn.addChild("initializer").addChild(ai);
2139                 RESULT=pn;
2140                 :}
2141         |       NEW class_or_interface_type:type dims:dims array_initializer:ai {: 
2142                 ParseNode pn=new ParseNode("createarray2",parser.lexer.line_num);
2143                 pn.addChild(type);
2144                 pn.addChild("dims_opt").setLiteral(dims);
2145                 pn.addChild("initializer").addChild(ai);
2146                 RESULT=pn;
2147                 :}
2148         ;
2149 dim_exprs ::=   dim_expr:exp {: 
2150                 ParseNode pn=new ParseNode("dim_exprs",parser.lexer.line_num);
2151                 pn.addChild(exp);
2152                 RESULT=pn; :}
2153         |       dim_exprs:base dim_expr:exp {: 
2154                 base.addChild(exp);
2155                 RESULT=base;
2156         :}
2157         ;
2158 dim_expr ::=    LBRACK expression:exp RBRACK {: RESULT=exp; :}
2159         ;
2160 dims_opt ::= {: RESULT=new Integer(0); :}
2161         |       dims:dims {: RESULT = dims; :}
2162         ;
2163
2164 dims ::=        LBRACK RBRACK {: RESULT=new Integer(1); :}
2165         |       dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
2166         ;
2167
2168 field_access ::=
2169                 primary:base DOT IDENTIFIER:id {: 
2170                 ParseNode pn=new ParseNode("fieldaccess",parser.lexer.line_num);
2171                 pn.addChild("base").addChild(base);
2172                 pn.addChild("field").addChild(id);
2173                 RESULT=pn;
2174     :}
2175 //      |       SUPER DOT IDENTIFIER
2176 //      |       name DOT SUPER DOT IDENTIFIER
2177         ;
2178 method_invocation ::=
2179                 name:name LPAREN argument_list_opt:args RPAREN {: 
2180                 ParseNode pn=new ParseNode("methodinvoke1",parser.lexer.line_num);
2181                 pn.addChild(name);
2182                 pn.addChild(args);
2183                 RESULT=pn;
2184         :}
2185         |       primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {: 
2186                 ParseNode pn=new ParseNode("methodinvoke2",parser.lexer.line_num);
2187                 pn.addChild("base").addChild(base);
2188                 pn.addChild("id").addChild(name);
2189                 pn.addChild(args);
2190                 RESULT=pn;
2191         :}
2192         |       SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {: 
2193                 ParseNode name=new ParseNode("name",parser.lexer.line_num);
2194                 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
2195                 name.addChild("identifier").addChild(id);
2196                 ParseNode pn=new ParseNode("methodinvoke1",parser.lexer.line_num);
2197                 pn.addChild(name);
2198                 pn.addChild(args);
2199                 RESULT=pn;
2200         :}
2201 //      |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
2202         ;
2203 array_access ::=
2204                 name:name LBRACK expression:exp RBRACK {: 
2205                 ParseNode pn=new ParseNode("arrayaccess",parser.lexer.line_num);
2206                 pn.addChild("base").addChild(name);
2207                 pn.addChild("index").addChild(exp);
2208                 RESULT=pn;
2209         :}
2210         |       primary_no_new_array:base LBRACK expression:exp RBRACK {: 
2211                 ParseNode pn=new ParseNode("arrayaccess",parser.lexer.line_num);
2212                 pn.addChild("base").addChild(base);
2213                 pn.addChild("index").addChild(exp);
2214                 RESULT=pn;
2215         :}
2216 //      |       array_creation_init:init LBRACK expression:exp RBRACK {: 
2217 //              ParseNode pn=new ParseNode("arrayaccess",parser.lexer.line_num);
2218 //              pn.addChild("init").addChild(init);
2219 //              pn.addChild("index").addChild(exp);
2220 //              RESULT=pn;
2221 //      :}
2222         ;
2223
2224 postfix_expression ::=
2225                 primary:exp {: 
2226         RESULT=exp; :}
2227         |       name:exp {: RESULT=exp; :}
2228         |       postincrement_expression:exp {: RESULT=exp; :}
2229         |       postdecrement_expression:exp {: RESULT=exp; :}
2230         ;
2231 postincrement_expression ::=
2232                 postfix_expression:exp PLUSPLUS 
2233                 {: RESULT=(new ParseNode("postinc",parser.lexer.line_num)).addChild(exp).getRoot(); :}
2234         ;
2235 postdecrement_expression ::=
2236                 postfix_expression:exp MINUSMINUS
2237                 {: RESULT=(new ParseNode("postdec",parser.lexer.line_num)).addChild(exp).getRoot(); :}
2238         ;
2239 unary_expression ::=
2240                 preincrement_expression:exp {: RESULT=exp; :}
2241         |       predecrement_expression:exp {: RESULT=exp; :}
2242         |       PLUS unary_expression:exp 
2243         {: RESULT=(new ParseNode("unaryplus",parser.lexer.line_num)).addChild(exp).getRoot(); :}
2244         |       MINUS unary_expression:exp
2245         {: RESULT=(new ParseNode("unaryminus",parser.lexer.line_num)).addChild(exp).getRoot(); :}
2246         |       unary_expression_not_plus_minus:exp {: 
2247                         RESULT=exp; :}
2248         ;
2249 preincrement_expression ::=
2250                 PLUSPLUS unary_expression:exp
2251                 {: RESULT=(new ParseNode("preinc",parser.lexer.line_num)).addChild(exp).getRoot(); :}
2252         ;
2253 predecrement_expression ::=
2254                 MINUSMINUS unary_expression:exp
2255                 {: RESULT=(new ParseNode("predec",parser.lexer.line_num)).addChild(exp).getRoot(); :}
2256         ;
2257 unary_expression_not_plus_minus ::=
2258                 postfix_expression:exp {: 
2259                 RESULT=exp; :}
2260         |       COMP unary_expression:exp
2261                 {: RESULT=(new ParseNode("comp",parser.lexer.line_num)).addChild(exp).getRoot(); :}
2262         |       NOT unary_expression:exp 
2263                 {: RESULT=(new ParseNode("not",parser.lexer.line_num)).addChild(exp).getRoot(); :}
2264         |       cast_expression:exp {: RESULT=exp; :}
2265         ;
2266 cast_expression ::=
2267                 LPAREN primitive_type:type dims_opt:dims
2268                 RPAREN unary_expression:exp {: 
2269                 ParseNode pn=new ParseNode("cast1",parser.lexer.line_num);
2270 if (dims.intValue()==0)
2271                 pn.addChild("type").addChild(type);
2272 else {
2273                 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
2274                 arrayt.addChild("basetype").addChild(type);
2275                 arrayt.addChild("dims").setLiteral(dims);
2276 }
2277                 pn.addChild("exp").addChild(exp);
2278                 RESULT=pn;
2279         :}
2280         |       LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {: 
2281                 ParseNode pn=new ParseNode("cast2",parser.lexer.line_num);
2282                 pn.addChild("type").addChild(type);
2283                 pn.addChild("exp").addChild(exp);
2284                 RESULT=pn;
2285
2286         :}
2287         |       LPAREN name:name dims:dims RPAREN unary_expression_not_plus_minus:exp {: 
2288                 ParseNode pn=new ParseNode("cast1",parser.lexer.line_num);
2289 if (dims.intValue()==0)
2290                 pn.addChild("type").addChild("class").addChild(name);
2291 else {
2292                 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
2293                 arrayt.addChild("basetype").addChild("type").addChild("class").addChild(name);
2294                 arrayt.addChild("dims").setLiteral(dims);
2295 }
2296                 pn.addChild("exp").addChild(exp);
2297                 RESULT=pn;
2298
2299         :}
2300         ;
2301 multiplicative_expression ::=
2302                 unary_expression:exp {: 
2303                         RESULT=exp; :}
2304         |       multiplicative_expression:exp1 MULT unary_expression:exp2 {: 
2305                 ParseNode pn=new ParseNode("mult",parser.lexer.line_num);
2306                 pn.addChild(exp1);
2307                 pn.addChild(exp2);
2308                 RESULT=pn;
2309         :}
2310         |       multiplicative_expression:exp1 DIV unary_expression:exp2 {:
2311                 ParseNode pn=new ParseNode("div",parser.lexer.line_num);
2312                 pn.addChild(exp1);
2313                 pn.addChild(exp2);
2314                 RESULT=pn;
2315         :}
2316         |       multiplicative_expression:exp1 MOD unary_expression:exp2 {:
2317                 ParseNode pn=new ParseNode("mod",parser.lexer.line_num);
2318                 pn.addChild(exp1);
2319                 pn.addChild(exp2);
2320                 RESULT=pn;
2321         :}
2322         ;
2323 additive_expression ::=
2324                 multiplicative_expression:exp {: 
2325                         RESULT=exp; :}
2326         |       additive_expression:exp1 PLUS multiplicative_expression:exp2 {: 
2327                 ParseNode pn=new ParseNode("add",parser.lexer.line_num);
2328                 pn.addChild(exp1);
2329                 pn.addChild(exp2);
2330                 RESULT=pn;
2331         :}
2332         |       additive_expression:exp1 MINUS multiplicative_expression:exp2 {: 
2333                 ParseNode pn=new ParseNode("sub",parser.lexer.line_num);
2334                 pn.addChild(exp1);
2335                 pn.addChild(exp2);
2336                 RESULT=pn;
2337         :}
2338         ;
2339 shift_expression ::=
2340                 additive_expression:exp {: 
2341                         RESULT=exp; :}
2342         |       shift_expression:exp1 LSHIFT additive_expression:exp2 {: 
2343                 ParseNode pn=new ParseNode("leftshift",parser.lexer.line_num);
2344                 pn.addChild(exp1);
2345                 pn.addChild(exp2);
2346                 RESULT=pn;
2347         :}
2348         |       shift_expression:exp1 RSHIFT additive_expression:exp2 {: 
2349                 ParseNode pn=new ParseNode("rightshift",parser.lexer.line_num);
2350                 pn.addChild(exp1);
2351                 pn.addChild(exp2);
2352                 RESULT=pn;
2353         :}
2354         |       shift_expression:exp1 URSHIFT additive_expression:exp2 {:
2355                 ParseNode pn=new ParseNode("urightshift",parser.lexer.line_num);
2356                 pn.addChild(exp1);      
2357                 pn.addChild(exp2);      
2358                 RESULT=pn;
2359         :}
2360         ;
2361 relational_expression ::=
2362                 shift_expression:exp {: 
2363                         RESULT=exp; :}
2364         |       relational_expression:exp1 LT shift_expression:exp2 {:
2365                 ParseNode pn=new ParseNode("comp_lt",parser.lexer.line_num);
2366                 pn.addChild(exp1);
2367                 pn.addChild(exp2);
2368                 RESULT=pn;
2369         :}
2370         |       relational_expression:exp1 GT shift_expression:exp2 {:
2371                 ParseNode pn=new ParseNode("comp_gt",parser.lexer.line_num);
2372                 pn.addChild(exp1);
2373                 pn.addChild(exp2);
2374                 RESULT=pn;
2375         :}
2376         |       relational_expression:exp1 LTEQ shift_expression:exp2 {:
2377                 ParseNode pn=new ParseNode("comp_lte",parser.lexer.line_num);
2378                 pn.addChild(exp1);
2379                 pn.addChild(exp2);
2380                 RESULT=pn;
2381         :}
2382         |       relational_expression:exp1 GTEQ shift_expression:exp2 {:
2383                 ParseNode pn=new ParseNode("comp_gte",parser.lexer.line_num);
2384                 pn.addChild(exp1);
2385                 pn.addChild(exp2);
2386                 RESULT=pn;
2387         :}
2388         |       relational_expression:exp INSTANCEOF reference_type:type {: 
2389                 ParseNode pn=new ParseNode("instanceof",parser.lexer.line_num);
2390                 pn.addChild("exp").addChild(exp);
2391                 pn.addChild(type);
2392                 RESULT=pn;
2393         :}
2394         ;
2395
2396 equality_expression ::=
2397                 relational_expression:exp {: 
2398                         RESULT=exp; :}
2399         |       equality_expression:exp1 EQEQ relational_expression:exp2 {: 
2400                 ParseNode pn=new ParseNode("equal",parser.lexer.line_num);
2401                 pn.addChild(exp1);
2402                 pn.addChild(exp2);
2403                 RESULT=pn;
2404         :}
2405         |       equality_expression:exp1 NOTEQ relational_expression:exp2 {: 
2406                 ParseNode pn=new ParseNode("not_equal",parser.lexer.line_num);
2407                 pn.addChild(exp1);
2408                 pn.addChild(exp2);
2409                 RESULT=pn;
2410         :}
2411         ;
2412 and_expression ::=
2413                 equality_expression:exp {: 
2414                 RESULT=exp; :}
2415         |       and_expression:exp1 AND equality_expression:exp2 {: 
2416                 ParseNode pn=new ParseNode("bitwise_and",parser.lexer.line_num);
2417                 pn.addChild(exp1);
2418                 pn.addChild(exp2);
2419                 RESULT=pn;
2420         :}
2421         ;
2422 exclusive_or_expression ::=
2423                 and_expression:expr {: 
2424                         RESULT=expr;
2425                 :}
2426         |       exclusive_or_expression:exp1 XOR and_expression:exp2 {: 
2427                 ParseNode pn=new ParseNode("bitwise_xor",parser.lexer.line_num);
2428                 pn.addChild(exp1);
2429                 pn.addChild(exp2);
2430                 RESULT=pn;
2431 :}
2432         ;
2433 inclusive_or_expression ::=
2434                 exclusive_or_expression:exclor {: 
2435                         RESULT=exclor; :}
2436         |       inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {: 
2437                 ParseNode pn=new ParseNode("bitwise_or",parser.lexer.line_num);
2438                 pn.addChild(exp1);
2439                 pn.addChild(exp2);
2440                 RESULT=pn;
2441         :}
2442         ;
2443 conditional_and_expression ::=
2444                 inclusive_or_expression:inclor {: 
2445                         RESULT=inclor; :}
2446         |       conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
2447                 ParseNode pn=new ParseNode("logical_and",parser.lexer.line_num);
2448                 pn.addChild(exp1);
2449                 pn.addChild(exp2);
2450                 RESULT=pn;
2451         :}
2452         ;
2453 conditional_or_expression ::=
2454                 conditional_and_expression:condand {: 
2455                         RESULT=condand; :}
2456         |       conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {: 
2457                 ParseNode pn=new ParseNode("logical_or",parser.lexer.line_num);
2458                 pn.addChild(exp1);
2459                 pn.addChild(exp2);
2460                 RESULT=pn;
2461         :}
2462         ;
2463 conditional_expression ::=
2464                 conditional_or_expression:condor {: 
2465                         RESULT=condor; :}
2466         |       conditional_or_expression:condor QUESTION expression:exptrue
2467                         COLON conditional_expression:expfalse {: 
2468                         ParseNode pn=new ParseNode("tert",parser.lexer.line_num);
2469                         pn.addChild("cond").addChild(condor);
2470                         pn.addChild("trueexpr").addChild(exptrue);
2471                         pn.addChild("falseexpr").addChild(expfalse);
2472                         RESULT=pn;
2473                         :}
2474         ;
2475 getoffset_expression ::=
2476         GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
2477         ParseNode pn = new ParseNode("getoffset",parser.lexer.line_num);
2478         pn.addChild(type);
2479         pn.addChild("field").addChild(id);
2480         RESULT = pn;
2481       :}
2482    ;
2483  
2484 assignment_expression ::=
2485                 conditional_expression:expr {: 
2486                         RESULT=expr; :} |
2487                 assignment:assign {: 
2488                         RESULT=assign; :}             |
2489         getoffset_expression:expr {:
2490             RESULT=expr; :}
2491         ;
2492 // semantic check necessary here to ensure a valid left-hand side.
2493 // allowing a parenthesized variable here on the lhs was introduced in
2494 // JLS 2; thanks to Eric Blake for pointing this out.
2495 assignment ::=  postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
2496                 ParseNode pn=new ParseNode("assignment",parser.lexer.line_num);
2497                 pn.addChild("op").addChild(op);
2498                 ParseNode pnargs=pn.addChild("args");
2499                 pnargs.addChild(lvalue);
2500                 pnargs.addChild(rvalue);
2501                 RESULT=pn;
2502          :}
2503         ;
2504 assignment_operator ::=
2505                 EQ {: RESULT=new ParseNode("eq",parser.lexer.line_num); :}
2506         |       MULTEQ {: RESULT=new ParseNode("multeq",parser.lexer.line_num); :}
2507         |       DIVEQ {: RESULT=new ParseNode("diveq",parser.lexer.line_num); :}
2508         |       MODEQ {: RESULT=new ParseNode("modeq",parser.lexer.line_num); :}
2509         |       PLUSEQ {: RESULT=new ParseNode("pluseq",parser.lexer.line_num); :}
2510         |       MINUSEQ {: RESULT=new ParseNode("minuseq",parser.lexer.line_num); :}
2511         |       LSHIFTEQ {: RESULT=new ParseNode("lshifteq",parser.lexer.line_num); :}
2512         |       RSHIFTEQ {: RESULT=new ParseNode("rshifteq",parser.lexer.line_num); :}
2513         |       URSHIFTEQ {: RESULT=new ParseNode("urshifteq",parser.lexer.line_num); :}
2514         |       ANDEQ {: RESULT=new ParseNode("andeq",parser.lexer.line_num); :}
2515         |       XOREQ {: RESULT=new ParseNode("xoreq",parser.lexer.line_num); :}
2516         |       OREQ {: RESULT=new ParseNode("oreq",parser.lexer.line_num); :}
2517         ;
2518 expression_opt ::=
2519         {:      RESULT=new ParseNode("empty",parser.lexer.line_num); :}
2520         |       expression:exp {: 
2521                 RESULT=exp; :}
2522         ;
2523 expression ::=  assignment_expression:exp {: 
2524                 RESULT=exp; :}
2525         ;
2526 // note that this constraint must be enforced during semantic checking
2527 // 'constant_expression' should include enumerated constants.
2528 constant_expression ::=
2529                 expression:exp 
2530                 {:
2531                     ParseNode pn = new ParseNode("constant_expression",parser.lexer.line_num);
2532                     pn.addChild(exp);
2533                     RESULT=pn;
2534                 :}
2535         ;
2536
2537
2538 genreach_statement ::=
2539                 GENREACH IDENTIFIER:graphName SEMICOLON {: 
2540                 ParseNode pn=new ParseNode("genreach",parser.lexer.line_num);
2541                 pn.addChild("graphName").addChild(graphName);
2542                 RESULT=pn; :}
2543         ;