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