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