*** empty log message ***
[IRC.git] / Robust / src / Parse / java14.cup
1 package Parse;
2
3 import java_cup.runtime.*;
4 import Lex.Lexer;
5 import IR.Tree.*;
6
7 /* Java 1.4 parser for CUP.  
8  * Copyright (C) 2002-2003 C. Scott Ananian <cananian@alumni.princeton.edu>
9  * This program is released under the terms of the GPL; see the file
10  * COPYING for more details.  There is NO WARRANTY on this code.
11  */
12
13 /*
14 JDK 1.4 Features added:
15   assertion statement.
16   statement_without_trailing_substatement ::= ...
17      |          assert_statement ;
18   assert_statement ::=
19                 ASSERT expression SEMICOLON
20         |       ASSERT expression COLON expression SEMICOLON
21         ;
22 */
23 parser code  {: 
24   Lexer lexer;
25
26   public Parser(Lexer l) {
27     this();
28     lexer=l;
29   }
30
31   public void syntax_error(java_cup.runtime.Symbol current) {
32     report_error("Syntax error (" + current.sym + ")", current);
33   }
34   public void report_error(String message, java_cup.runtime.Symbol info) {
35     lexer.errorMsg(message, info);
36   }
37 :};
38
39 scan with {: return lexer.nextToken(); :};
40
41 terminal BOOLEAN; // primitive_type
42 terminal BYTE, SHORT, INT, LONG, CHAR; // integral_type
43 terminal FLOAT, DOUBLE; // floating_point_type
44 terminal LBRACK, RBRACK; // array_type
45 terminal java.lang.String IDENTIFIER; // name
46 terminal DOT; // qualified_name
47 terminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;
48 terminal PACKAGE; // package_declaration
49 terminal IMPORT; // import_declaration
50 terminal PUBLIC, PROTECTED, PRIVATE; // modifier
51 terminal STATIC; // modifier
52 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
53 terminal CLASS; // class_declaration
54 terminal EXTENDS; // super
55 //terminal IMPLEMENTS; // interfaces
56 terminal VOID; // method_header
57 terminal THROWS; // throws
58 terminal THIS, SUPER; // explicit_constructor_invocation
59 //terminal INTERFACE; // interface_declaration
60 terminal IF, ELSE; // if_then_statement, if_then_else_statement
61 terminal SWITCH; // switch_statement
62 terminal CASE, DEFAULT; // switch_label
63 terminal DO, WHILE; // while_statement, do_statement
64 terminal FOR; // for_statement
65 terminal BREAK; // break_statement
66 terminal CONTINUE; // continue_statement
67 terminal RETURN; // return_statement
68 terminal THROW; // throw_statement
69 terminal TRY; // try_statement
70 terminal CATCH; // catch_clause
71 terminal FINALLY; // finally
72 terminal NEW; // class_instance_creation_expression
73 terminal PLUSPLUS; // postincrement_expression
74 terminal MINUSMINUS; // postdecrement_expression
75 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
76 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
77 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
78 terminal EQEQ, NOTEQ; // equality_expression
79 terminal AND; // and_expression
80 terminal XOR; // exclusive_or_expression
81 terminal OR;  // inclusive_or_expression
82 terminal ANDAND; // conditional_and_expression
83 terminal OROR; // conditional_or_expression
84 terminal QUESTION; // conditional_expression
85 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
86 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
87 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
88
89 terminal java.lang.Number INTEGER_LITERAL;
90 terminal java.lang.Number FLOATING_POINT_LITERAL;
91 terminal java.lang.Boolean BOOLEAN_LITERAL;
92 terminal java.lang.Character CHARACTER_LITERAL;
93 terminal java.lang.String STRING_LITERAL;
94 terminal NULL_LITERAL;
95
96 // Reserved but unused:
97 terminal CONST, GOTO;
98 // strictfp keyword, new in Java 1.2
99 terminal STRICTFP;
100 // assert keyword, new in Java 1.4
101 terminal ASSERT; // assert_statement
102 // lexer compatibility with Java 1.5
103 terminal ELLIPSIS;
104 terminal ENUM;
105
106 //failure aware computation keywords
107 terminal FLAG;
108 terminal TAG;
109 terminal TASK;
110 non terminal ParseNode flag_declaration;
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, modifier;
137 // 19.8.1) Class Declaration
138 non terminal ParseNode class_declaration, super, super_opt;
139 //non terminal interfaces, interfaces_opt, interface_type_list;
140 non terminal ParseNode class_body;
141 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
142 non terminal ParseNode class_body_declaration, class_member_declaration;
143 // 19.8.2) Field Declarations
144 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
145 non terminal ParseNode variable_declarator_id;
146 non terminal ParseNode variable_initializer;
147 // 19.8.3) Method Declarations
148 non terminal ParseNode method_declaration, method_header, method_declarator;
149 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
150 non terminal ParseNode formal_parameter;
151 //non terminal ParseNode throws_opt;
152 //non terminal ParseNode throws;
153 //non terminal ParseNode class_type_list;
154 non terminal ParseNode method_body;
155 // 19.8.4) Static Initializers
156 //non terminal ParseNode static_initializer;
157 // 19.8.5) Constructor Declarations
158 non terminal ParseNode constructor_declaration, constructor_declarator;
159 non terminal ParseNode constructor_body;
160 //non terminal ParseNode explicit_constructor_invocation;
161 // 19.9.1) Interface Declarations
162 //non terminal ParseNode interface_declaration;
163 //non terminal ParseNode extends_interfaces_opt, extends_interfaces;
164 //non terminal ParseNode interface_body;
165 //non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
166 //non terminal ParseNode interface_member_declaration, constant_declaration;
167 //non terminal ParseNode abstract_method_declaration;
168 // 19.10) Arrays
169 //non terminal ParseNode array_initializer;
170 //non terminal ParseNode variable_initializers;
171 // 19.11) Blocks and Statements
172 non terminal ParseNode block;
173 non terminal ParseNode block_statements_opt, block_statements, block_statement;
174 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
175 non terminal ParseNode statement, statement_no_short_if;
176 non terminal ParseNode statement_without_trailing_substatement;
177 non terminal ParseNode empty_statement;
178 //non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
179 non terminal ParseNode expression_statement, statement_expression;
180 non terminal ParseNode if_then_statement;
181 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
182 //non terminal ParseNode switch_statement, switch_block;
183 //non terminal ParseNode switch_block_statement_groups;
184 //non terminal ParseNode switch_block_statement_group;
185 //non terminal ParseNode switch_labels, switch_label;
186 non terminal ParseNode while_statement, while_statement_no_short_if;
187 non terminal ParseNode do_statement;
188 non terminal ParseNode for_statement, for_statement_no_short_if;
189 non terminal ParseNode for_init_opt, for_init;
190 non terminal ParseNode for_update_opt, for_update;
191 non terminal ParseNode statement_expression_list;
192 //non terminal ParseNode identifier_opt;
193 non terminal ParseNode break_statement, continue_statement;
194 non terminal ParseNode return_statement;
195 //non terminal ParseNode throw_statement;
196 //non terminal ParseNode synchronized_statement, try_statement;
197 //non terminal ParseNode catches_opt;
198 //non terminal ParseNode catches, catch_clause;
199 //non terminal ParseNode finally;
200 //non terminal ParseNode assert_statement;
201 // 19.12) Expressions
202 non terminal ParseNode primary, primary_no_new_array;
203 non terminal ParseNode class_instance_creation_expression;
204 non terminal ParseNode argument_list_opt, argument_list;
205 //non terminal ParseNode array_creation_init;
206 non terminal ParseNode array_creation_uninit;
207 non terminal ParseNode dim_exprs, dim_expr;
208 non terminal Integer dims_opt, dims;
209 non terminal ParseNode field_access, method_invocation;
210 non terminal ParseNode array_access;
211 non terminal ParseNode postfix_expression;
212 non terminal ParseNode postincrement_expression, postdecrement_expression;
213 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
214 non terminal ParseNode preincrement_expression, predecrement_expression;
215 non terminal ParseNode cast_expression;
216 non terminal ParseNode multiplicative_expression, additive_expression;
217 non terminal ParseNode shift_expression, relational_expression, equality_expression;
218 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
219 non terminal ParseNode conditional_and_expression, conditional_or_expression;
220 non terminal ParseNode conditional_expression;
221 non terminal ParseNode assignment_expression;
222 non terminal ParseNode assignment;
223 non terminal ParseNode assignment_operator;
224 non terminal ParseNode expression_opt, expression;
225 //non terminal ParseNode constant_expression;
226
227 start with goal;
228
229 // 19.2) The Syntactic Grammar
230 goal ::=        compilation_unit:cu
231         {:
232         RESULT = cu;
233         :}
234         ;
235
236 // 19.3) Lexical Structure.
237
238
239 literal ::=     INTEGER_LITERAL:integer_lit
240         {:
241                 ParseNode pn=new ParseNode("literal");
242                 pn.addChild("integer").setLiteral(integer_lit);
243                 RESULT=pn;
244         :}
245         |       FLOATING_POINT_LITERAL:float_lit
246         {:
247                 ParseNode pn=new ParseNode("literal");
248                 pn.addChild("float").setLiteral(float_lit);
249                 RESULT=pn;
250         :}
251         |       BOOLEAN_LITERAL:boolean_lit
252         {:
253                 ParseNode pn=new ParseNode("literal");
254                 pn.addChild("boolean").setLiteral(boolean_lit);
255                 RESULT=pn;
256         :}
257         |       CHARACTER_LITERAL:char_lit
258         {:
259                 ParseNode pn=new ParseNode("literal");
260                 pn.addChild("char").setLiteral(char_lit);
261                 RESULT=pn;
262         :}
263         |       STRING_LITERAL:string_lit
264         {:
265                 ParseNode pn=new ParseNode("literal");
266                 pn.addChild("string").setLiteral(string_lit);
267                 RESULT=pn;
268         :}
269         |       NULL_LITERAL 
270         {:
271                 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
272         :}
273         ;
274
275 // 19.4) Types, Values, and Variables
276 type    ::=     primitive_type:type {: RESULT=type; :}
277         |       reference_type:type {: RESULT=type; :}
278         ;
279
280 primitive_type ::=
281                 numeric_type:type {: RESULT=type; :}
282         |       BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
283         ;
284 numeric_type::= integral_type:type {: RESULT=type; :}
285         |       floating_point_type:type {: RESULT=type; :}
286         ;
287 integral_type ::= 
288                 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
289         |       SHORT  {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
290         |       INT  {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
291         |       LONG  {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
292         |       CHAR  {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
293         ;
294 floating_point_type ::= 
295                 FLOAT  {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
296         |       DOUBLE  {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
297         ;
298
299 reference_type ::=
300                 class_or_interface_type:type {: RESULT=type; :}
301         |       array_type:type {: RESULT=type; :}
302         ;
303 class_or_interface_type ::= name:name {: 
304         RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot(); 
305         :};
306
307 class_type ::=  class_or_interface_type:type {: RESULT=type; :};
308 //interface_type ::= class_or_interface_type;
309
310 array_type ::=  primitive_type:prim dims:dims {: 
311                 ParseNode pn=(new ParseNode("type")).addChild("array");
312                 pn.addChild("basetype").addChild(prim);
313                 pn.addChild("dims").setLiteral(dims);
314                 RESULT=pn;
315         :}
316         |       name:name dims:dims {: 
317                 ParseNode pn=(new ParseNode("type")).addChild("array");
318                 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
319                 pn.addChild("dims").setLiteral(dims);
320                 RESULT=pn;
321         :}
322         ;
323
324 // 19.5) Names
325 name    ::=     simple_name:name {: RESULT=name; :}
326         |       qualified_name:name {: RESULT=name; :}
327         ;
328 simple_name ::= IDENTIFIER:id {: 
329         RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot(); 
330         :}
331         ;
332 qualified_name ::= name:name DOT IDENTIFIER:id {: 
333         ParseNode pn=new ParseNode("name");
334         pn.addChild("base").addChild(name);
335         pn.addChild("identifier").addChild(id);
336         RESULT=pn;
337         :}
338         ;
339
340 // 19.6) Packages
341 compilation_unit ::=
342 //              package_declaration_opt
343 //              import_declarations_opt
344                 type_declarations_opt:tdo {: 
345                 ParseNode pn=new ParseNode("compilation_unit");
346                 pn.addChild(tdo);
347                 RESULT=pn;
348                 :}
349                 ;
350 //package_declaration_opt ::= package_declaration | ;
351 //import_declarations_opt ::= import_declarations | ;
352 type_declarations_opt   ::= type_declarations:tds {:
353                 RESULT=tds;
354                 :}   | 
355         {: RESULT=new ParseNode("empty"); :}
356         ;
357
358 //import_declarations ::=
359 //               import_declaration
360 //       |       import_declarations import_declaration
361 //       ;
362
363 type_declarations ::= 
364                 type_declaration:td {:
365                 ParseNode pn=new ParseNode("type_declaration_list");
366                 pn.addChild(td);
367                 RESULT=pn;
368                 :}
369         |       type_declarations:tds type_declaration:td {:
370                 tds.addChild(td);
371                 RESULT=tds;
372                 :}
373         ;
374
375 //package_declaration ::=
376 //               PACKAGE name SEMICOLON
377 //       ;
378 //import_declaration ::=
379 //               single_type_import_declaration
380 //       |       type_import_on_demand_declaration
381 //       ;
382 //single_type_import_declaration ::=
383 //               IMPORT name SEMICOLON
384 //       ;
385 //type_import_on_demand_declaration ::=
386 //               IMPORT name DOT MULT SEMICOLON
387 //       ;
388
389 type_declaration ::=
390                 class_declaration:cd 
391                 {:
392                         RESULT=cd;
393                 :}
394 //      |       interface_declaration
395         |       SEMICOLON {: RESULT=new ParseNode("empty"); :}
396         ;
397
398 // 19.7) Productions used only in the LALR(1) grammar
399 modifiers_opt::=
400         {: RESULT=new ParseNode("empty"); :}
401         |       modifiers:mo {: 
402                 RESULT=mo;
403         :}
404         ;
405 modifiers ::=   modifier:mo {: 
406                 ParseNode pn=new ParseNode("modifier_list");
407                 pn.addChild(mo);
408                 RESULT=pn;
409         :}
410         |       modifiers:mos modifier:mo {: 
411                 mos.addChild(mo);
412                 RESULT=mos;
413         :}
414         ;
415 modifier ::=    
416         PUBLIC {: RESULT=new ParseNode("public"); :}|
417         PROTECTED {: RESULT=new ParseNode("protected"); :}|
418         PRIVATE {: RESULT=new ParseNode("private"); :}|
419         STATIC {: RESULT=new ParseNode("static"); :} |
420 //      ABSTRACT |
421         FINAL {: RESULT=new ParseNode("final"); :}|
422         NATIVE {: RESULT=new ParseNode("native"); :}
423 //      SYNCHRONIZED | 
424 //      TRANSIENT | 
425 //      VOLATILE |
426 //      STRICTFP // note that semantic analysis must check that the
427                          // context of the modifier allows strictfp.
428         ;
429
430 // 19.8) Classes
431
432 // 19.8.1) Class Declaration:
433 class_declaration ::= 
434         modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so //interfaces_opt
435 class_body:body 
436         {:
437         ParseNode pn=new ParseNode("class_declaration");
438         pn.addChild("modifiers").addChild(mo);
439         pn.addChild("name").addChild(id);
440         pn.addChild("super").addChild(so);
441         pn.addChild("classbody").addChild(body);
442         RESULT=pn;
443         :}
444         ;
445 super ::=       EXTENDS class_type:classtype {: 
446                 RESULT=classtype;
447         :}
448         ;
449 super_opt ::=   
450         {: RESULT=new ParseNode("empty"); :}
451         |       super:su {: 
452                 RESULT=su;
453         :}
454         ;
455
456 //interfaces ::= IMPLEMENTS interface_type_list
457 //       ;
458 //interfaces_opt::=
459 //       |       interfaces
460 //       ;
461 //interface_type_list ::=
462 //               interface_type
463 //       |       interface_type_list COMMA interface_type
464 //       ;
465
466 class_body ::=  LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
467         ;
468
469 class_body_declarations_opt ::= 
470         {: RESULT=new ParseNode("empty"); :}
471         |       class_body_declarations:cbd {: RESULT=cbd; :};
472
473 class_body_declarations ::= 
474                 class_body_declaration:cbd {: 
475                         ParseNode pn=new ParseNode("class_body_declaration_list");
476                         pn.addChild(cbd);
477                         RESULT=pn;
478                 :}
479         |       class_body_declarations:cbds class_body_declaration:cbd {: 
480                         cbds.addChild(cbd);
481                         RESULT=cbds;
482                 :}
483         ;
484
485 class_body_declaration ::=
486                 class_member_declaration:member {: 
487                 RESULT=(new ParseNode("member")).addChild(member).getRoot();
488         :}
489 //      |       static_initializer
490         |       constructor_declaration:constructor {: 
491                 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
492         :}
493         |       block:block {:
494                 RESULT=(new ParseNode("block")).addChild(block).getRoot();
495 :}
496         ;
497 class_member_declaration ::=
498         //failure aware computation
499         flag_declaration:flag {: 
500         RESULT=(new ParseNode("flag")).addChild(flag).getRoot(); 
501         :}
502         |
503         field_declaration:field {: 
504         RESULT=(new ParseNode("field")).addChild(field).getRoot(); 
505         :}
506         |       method_declaration:method {:
507         RESULT=(new ParseNode("method")).addChild(method).getRoot(); 
508         :}
509         /* repeat the prod for 'class_declaration' here: */
510 //      |       modifiers_opt CLASS IDENTIFIER super_opt class_body
511 //      |       interface_declaration
512         |       SEMICOLON       {: RESULT=new ParseNode("empty"); :}
513         ;
514
515 //Failure aware computation
516 flag_declaration ::= 
517                 FLAG IDENTIFIER:id SEMICOLON {: 
518                 ParseNode pn=new ParseNode("flag_declaration");
519                 pn.addChild("name").addChild(id);
520                 RESULT=pn;
521         :}
522         ;
523
524 // 19.8.2) Field Declarations
525 field_declaration ::= 
526                 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {: 
527                 ParseNode pn=new ParseNode("field_declaration");
528                 pn.addChild("modifier").addChild(mo);
529                 pn.addChild("type").addChild(type);
530                 pn.addChild("variables").addChild(var);
531                 RESULT=pn;
532         :}
533         ;
534
535 variable_declarators ::=
536                 variable_declarator:vd {: 
537                 ParseNode pn=new ParseNode("variable_declarators_list");
538                 pn.addChild(vd);
539                 RESULT=pn;
540         :}
541         |       variable_declarators:vds COMMA variable_declarator:vd {:
542                 vds.addChild(vd);
543                 RESULT=vds;
544         :}
545         ;
546 variable_declarator ::=
547                 variable_declarator_id:id {:
548                 ParseNode pn=new ParseNode("variable_declarator");
549                 pn.addChild(id);
550                 RESULT=pn;
551         :}
552         |       variable_declarator_id:id EQ variable_initializer:init {: 
553                 ParseNode pn=new ParseNode("variable_declarator");
554                 pn.addChild(id);
555                 pn.addChild("initializer").addChild(init);
556                 RESULT=pn;
557         :}
558         ;
559 variable_declarator_id ::=
560                 IDENTIFIER:id {: 
561                 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
562         |       variable_declarator_id:id LBRACK RBRACK {:
563                 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
564         ;
565 variable_initializer ::=
566                 expression:exp {: RESULT=exp; :}
567 //      |       array_initializer
568         ;
569
570 // 19.8.3) Method Declarations
571 method_declaration ::=
572                 method_header:header method_body:body {:
573                 ParseNode pn=new ParseNode("method_declaration");
574                 pn.addChild(header);
575                 pn.addChild("body").addChild(body);
576                 RESULT=pn;
577         :}
578         ;
579 method_header ::=
580                 modifiers_opt:mo type:type method_declarator:decl //throws_opt 
581         {:
582                 ParseNode pn=new ParseNode("method_header");
583                 pn.addChild("modifiers").addChild(mo);
584                 pn.addChild("returntype").addChild(type);
585                 pn.addChild(decl);
586                 RESULT=pn;
587         :}
588         |       modifiers_opt:mo VOID method_declarator:decl //throws_opt
589         {:
590                 ParseNode pn=new ParseNode("method_header");
591                 pn.addChild("modifiers").addChild(mo);
592                 pn.addChild(decl);
593                 RESULT=pn;
594         :}
595         ;
596 method_declarator ::=
597                 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {: 
598                 ParseNode pn=new ParseNode("method_declarator");
599                 pn.addChild("name").addChild(id);
600                 pn.addChild("parameters").addChild(params);
601                 RESULT=pn;
602         :}
603 //      |       method_declarator LBRACK RBRACK // deprecated
604 // be careful; the above production also allows 'void foo() []'
605         ;
606 formal_parameter_list_opt ::=
607         {: RESULT=new ParseNode("empty"); :}
608         |       formal_parameter_list:fpl {: 
609                 RESULT=fpl;
610         :}
611         ;
612 formal_parameter_list ::=
613                 formal_parameter:fp {: 
614                 ParseNode pn=new ParseNode("formal_parameter_list");
615                 pn.addChild(fp);
616                 RESULT=pn;
617         :}
618         |       formal_parameter_list:fpl COMMA formal_parameter:fp {: 
619                 fpl.addChild(fp);
620                 RESULT=fpl;
621         :}
622         ;
623 formal_parameter ::=
624                 type:type variable_declarator_id:name {:
625                 ParseNode pn=new ParseNode("formal_parameter");
626                 pn.addChild(type);
627                 pn.addChild(name);
628                 RESULT=pn;
629         :}
630 //      |       FINAL type variable_declarator_id
631         ;
632 //throws_opt ::=        
633 //      |       throws
634 //      ;
635 //throws ::=    THROWS class_type_list
636 //      ;
637 //class_type_list ::=
638 //              class_type
639 //      |       class_type_list COMMA class_type
640 //      ;
641 method_body ::= block:block {: 
642                 RESULT=block;
643         :}
644         |       SEMICOLON       {: RESULT=new ParseNode("empty"); :}
645         ;
646
647 // 19.8.4) Static Initializers
648 //static_initializer ::=
649 //              STATIC block
650 //      ;
651
652 // 19.8.5) Constructor Declarations
653 constructor_declaration ::=
654                 modifiers_opt:mo constructor_declarator:cd
655 //throws_opt 
656                         constructor_body:body   {:
657                 ParseNode pn=new ParseNode("constructor_declaration");
658                 pn.addChild("modifiers").addChild(mo);
659                 pn.addChild(cd);
660                 pn.addChild("body").addChild(body);
661                 RESULT=pn;
662         :}
663         ;
664 constructor_declarator ::=
665                 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {: 
666                 ParseNode pn=new ParseNode("constructor_declarator");
667                 pn.addChild(name);
668                 pn.addChild("parameters").addChild(fplo);
669                 RESULT=pn;
670         :}
671         ;
672 constructor_body ::=
673 //              LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE |
674 //              LBRACE explicit_constructor_invocation RBRACE |
675                 LBRACE block_statements:block RBRACE {: 
676                 ParseNode pn=new ParseNode("constructor_body");
677                 pn.addChild(block);
678                 RESULT=pn;
679         :}
680         |       LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
681         ;
682 //explicit_constructor_invocation ::=
683 //              THIS LPAREN argument_list_opt RPAREN SEMICOLON
684 //      |       SUPER LPAREN argument_list_opt RPAREN SEMICOLON
685 //      |       primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
686 //      |       primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
687 //      ;
688
689 // 19.9) Interfaces
690
691 // 19.9.1) Interface Declarations
692 //interface_declaration ::=
693 //               modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt
694 //                       interface_body
695 //       ;
696 //extends_interfaces_opt ::=
697 //       |       extends_interfaces
698 //       ;
699 //extends_interfaces ::=
700 //               EXTENDS interface_type
701 //       |       extends_interfaces COMMA interface_type
702 //       ;
703 //interface_body ::=
704 //               LBRACE interface_member_declarations_opt RBRACE
705 //       ;
706 //interface_member_declarations_opt ::=
707 //       |       interface_member_declarations
708 //       ;
709 //interface_member_declarations ::=
710 //               interface_member_declaration
711 //       |       interface_member_declarations interface_member_declaration
712 //       ;
713 //interface_member_declaration ::=
714 //               constant_declaration
715 //       |       abstract_method_declaration
716 //       |       class_declaration
717 //       |       interface_declaration
718 //       |       SEMICOLON
719 //       ;
720 //constant_declaration ::=
721 //               field_declaration
722 //       // need to semantically check that modifiers of field declaration
723 //       // include only PUBLIC, STATIC, or FINAL.  Other modifiers are
724 //       // disallowed.
725 //       ;
726 //abstract_method_declaration ::=
727 //               method_header SEMICOLON
728 //       ;
729
730
731 // 19.10) Arrays
732 //array_initializer ::=
733 //              LBRACE variable_initializers COMMA RBRACE
734 //      |       LBRACE variable_initializers RBRACE
735 //      |       LBRACE COMMA RBRACE
736 //      |       LBRACE RBRACE
737 //      ;
738 //variable_initializers ::=
739 //              variable_initializer
740 //      |       variable_initializers COMMA variable_initializer
741 //      ;
742
743 // 19.11) Blocks and Statements
744 block ::=       LBRACE block_statements_opt:bso RBRACE {: 
745         RESULT=bso;
746         :}
747         ;
748 block_statements_opt ::=
749         {: RESULT=new ParseNode("empty"); :}
750         |       block_statements:bs {: 
751         RESULT=bs;
752         :}
753         ;
754 block_statements ::=
755                 block_statement:bs {:
756         ParseNode pn=new ParseNode("block_statement_list");
757         pn.addChild(bs);
758         RESULT=pn;
759         :}
760         |       block_statements:bss block_statement:bs {: 
761         bss.addChild(bs);
762         RESULT=bss;
763         :}
764         ;
765 block_statement ::=
766                 local_variable_declaration_statement:lvds {: 
767                 RESULT=lvds;
768         :}
769         |       statement:statement {: 
770                 RESULT=statement;
771         :}
772 //      |       class_declaration
773 //      |       interface_declaration
774         ;
775 local_variable_declaration_statement ::=
776                 local_variable_declaration:lvd SEMICOLON {: 
777                 RESULT=lvd;
778         :}
779         ;
780 local_variable_declaration ::=
781                 type:type variable_declarators:var {: 
782                 ParseNode pn=new ParseNode("local_variable_declaration");
783                 pn.addChild(type);
784                 pn.addChild(var);
785                 RESULT=pn;
786 :}
787 //      |       FINAL type variable_declarators
788         ;
789 statement ::=   statement_without_trailing_substatement:st {: 
790                 RESULT=st;
791         :}
792 //      |       labeled_statement:st {: RESULT=st; :}
793         |       if_then_statement:st {: RESULT=st; :}
794         |       if_then_else_statement:st {: RESULT=st; :}
795         |       while_statement:st {: RESULT=st; :}
796         |       for_statement:st {: RESULT=st; :}
797         ;
798 statement_no_short_if ::=
799                 statement_without_trailing_substatement:st {: RESULT=st; :}
800 //      |       labeled_statement_no_short_if:st {: RESULT=st; :}
801         |       if_then_else_statement_no_short_if:st {: RESULT=st; :}
802         |       while_statement_no_short_if:st {: RESULT=st; :}
803         |       for_statement_no_short_if:st {: RESULT=st; :}
804         ;
805 statement_without_trailing_substatement ::=
806                 block:st {: RESULT=st; :}
807         |       empty_statement:st {: RESULT=st; :}
808         |       expression_statement:st {: RESULT=st; :}
809 //      |       switch_statement
810         |       do_statement
811         |       break_statement:st {: RESULT=st; :}
812         |       continue_statement:st {: RESULT=st; :}
813         |       return_statement:st {: RESULT=st; :}
814 //      |       synchronized_statement
815 //      |       throw_statement
816 //      |       try_statement
817 //      |       assert_statement
818         ;
819 empty_statement ::=
820                 SEMICOLON {: RESULT=new ParseNode("nop"); :}
821         ;
822 //labeled_statement ::=
823 //              IDENTIFIER COLON statement
824 //      ;
825 //labeled_statement_no_short_if ::=
826 //              IDENTIFIER COLON statement_no_short_if
827 //      ;
828 expression_statement ::=
829                 statement_expression:se SEMICOLON {: 
830                 ParseNode pn=new ParseNode("expression");
831                 pn.addChild(se);
832                 RESULT=pn; :}
833         ;
834 statement_expression ::=
835                 assignment:st {: RESULT=st; :}
836         |       preincrement_expression:st {: RESULT=st; :}
837         |       predecrement_expression:st {: RESULT=st; :}
838         |       postincrement_expression:st {: RESULT=st; :}
839         |       postdecrement_expression:st {: RESULT=st; :}
840         |       method_invocation:st {: RESULT=st; :}
841         |       class_instance_creation_expression:st {: RESULT=st; :}
842         ;
843 if_then_statement ::=
844                 IF LPAREN expression:exp RPAREN statement:st {: 
845                 ParseNode pn=new ParseNode("ifstatement");
846                 pn.addChild("condition").addChild(exp);
847                 pn.addChild("statement").addChild(st);
848                 RESULT=pn;
849         :}
850         ;
851 if_then_else_statement ::=
852                 IF LPAREN expression:exp RPAREN statement_no_short_if:st
853                         ELSE statement:else_st {:
854                 ParseNode pn=new ParseNode("ifstatement");
855                 pn.addChild("condition").addChild(exp);
856                 pn.addChild("statement").addChild(st);
857                 pn.addChild("else_statement").addChild(else_st);
858                 RESULT=pn;
859         :}
860         ;
861 if_then_else_statement_no_short_if ::=
862                 IF LPAREN expression:exp RPAREN statement_no_short_if:st
863                         ELSE statement_no_short_if:else_st {:
864                 ParseNode pn=new ParseNode("ifstatement");
865                 pn.addChild("condition").addChild(exp);
866                 pn.addChild("statement").addChild(st);
867                 pn.addChild("else_statement").addChild(else_st);
868                 RESULT=pn;
869         :}
870         ;
871 //switch_statement ::=
872 //              SWITCH LPAREN expression RPAREN switch_block
873 //      ;
874 //switch_block ::=
875 //              LBRACE switch_block_statement_groups switch_labels RBRACE
876 //      |       LBRACE switch_block_statement_groups RBRACE
877 //      |       LBRACE switch_labels RBRACE
878 //      |       LBRACE RBRACE
879 //      ;
880 //switch_block_statement_groups ::=
881 //              switch_block_statement_group
882 //      |       switch_block_statement_groups switch_block_statement_group
883 //      ;
884 //switch_block_statement_group ::=
885 //              switch_labels block_statements
886 //      ;
887 //switch_labels ::=
888 //              switch_label
889 //      |       switch_labels switch_label
890 //      ;
891 //switch_label ::=
892 //              CASE constant_expression COLON
893 //      |       DEFAULT COLON
894 //      ;
895
896 while_statement ::=
897                 WHILE LPAREN expression:exp RPAREN statement:st {: 
898                 ParseNode pn=new ParseNode("whilestatement");
899                 pn.addChild("condition").addChild(exp);
900                 pn.addChild("statement").addChild(st);
901                 RESULT=pn;
902         :}
903         ;
904 while_statement_no_short_if ::=
905                 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
906                 ParseNode pn=new ParseNode("whilestatement");
907                 pn.addChild("condition").addChild(exp);
908                 pn.addChild("statement").addChild(st);
909                 RESULT=pn;
910                 :}
911         ;
912 do_statement ::=
913                 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {: 
914                 ParseNode pn=new ParseNode("dowhilestatement");
915                 pn.addChild("condition").addChild(exp);
916                 pn.addChild("statement").addChild(st);
917                 RESULT=pn;
918         :}
919         ;
920 for_statement ::=
921                 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
922                         for_update_opt:update RPAREN statement:st {: 
923                 ParseNode pn=new ParseNode("forstatement");
924                 pn.addChild("initializer").addChild(init);
925                 pn.addChild("condition").addChild(exp);
926                 pn.addChild("update").addChild(update);
927                 pn.addChild("statement").addChild(st);
928                 RESULT=pn;
929                 :}
930         ;
931 for_statement_no_short_if ::=
932                 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
933                         for_update_opt:update RPAREN statement_no_short_if:st {:
934                 ParseNode pn=new ParseNode("forstatement");
935                 pn.addChild("initializer").addChild(init);
936                 pn.addChild("condition").addChild(exp);
937                 pn.addChild("update").addChild(update);
938                 pn.addChild("statement").addChild(st);
939                 RESULT=pn;
940                 :}
941         ;
942 for_init_opt ::=
943         {: RESULT=new ParseNode("empty"); :}
944         |       for_init:init {: RESULT=init; :}
945         ;
946 for_init ::=    statement_expression_list:list {: RESULT=list; :}
947         |       local_variable_declaration:decl {: RESULT=decl; :}
948         ;
949 for_update_opt ::=
950         {: RESULT=new ParseNode("empty"); :}
951         |       for_update:update {: RESULT=update; :}
952         ;
953 for_update ::=  statement_expression_list:list {: RESULT=list; :}
954         ;
955 statement_expression_list ::=
956                 statement_expression:expr {: 
957                 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
958         :}
959         |       statement_expression_list:list COMMA statement_expression:expr {: 
960                 list.addChild(expr);
961                 RESULT=list;
962         :}
963         ;
964
965 //identifier_opt ::= 
966 //      |       IDENTIFIER
967 //      ;
968
969 break_statement ::=
970                 BREAK
971 //identifier_opt 
972 SEMICOLON {: RESULT=new ParseNode("break"); :}
973         ;
974
975 continue_statement ::=
976                 CONTINUE  
977 //identifier_opt 
978 SEMICOLON
979 {: RESULT=new ParseNode("continue"); :}
980         ;
981 return_statement ::=
982                 RETURN expression_opt:exp SEMICOLON {: 
983         RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
984         ;
985 //throw_statement ::=
986 //              THROW expression SEMICOLON
987 //      ;
988 //synchronized_statement ::=
989 //              SYNCHRONIZED LPAREN expression RPAREN block
990 //      ;
991 //try_statement ::=
992 //              TRY block catches
993 //      |       TRY block catches_opt finally
994 //      ;
995 //catches_opt ::=
996 //      |       catches
997 //      ;
998 //catches ::=   catch_clause
999 //      |       catches catch_clause
1000 //      ;
1001 //catch_clause ::=
1002 //              CATCH LPAREN formal_parameter RPAREN block
1003 //      ;
1004 //finally ::=   FINALLY block
1005 //      ;
1006 //assert_statement ::=
1007 //              ASSERT expression SEMICOLON
1008 //      |       ASSERT expression COLON expression SEMICOLON
1009 //      ;
1010
1011 // 19.12) Expressions
1012 primary ::=     primary_no_new_array:st {: 
1013                 RESULT=st; :}
1014 //      |       array_creation_init:st {: 
1015 //              RESULT=st;
1016 //      :}
1017         |       array_creation_uninit:st {:
1018                 RESULT=st;
1019         :}
1020         ;
1021 primary_no_new_array ::=
1022                 literal:lit {: RESULT=lit; :}
1023         |       THIS {: RESULT=new ParseNode("this"); :}
1024         |       LPAREN expression:exp RPAREN {: RESULT=exp; :}
1025         |       class_instance_creation_expression:exp {: RESULT=exp; :}
1026         |       field_access:exp {: RESULT=exp; :}
1027         |       method_invocation:exp {: RESULT=exp; :}
1028         |       array_access:exp {: RESULT=exp; :}
1029 //      |       primitive_type DOT CLASS
1030 //      |       VOID DOT CLASS
1031 //      |       array_type DOT CLASS
1032 //      |       name DOT CLASS
1033 //      |       name DOT THIS
1034         ;
1035 class_instance_creation_expression ::=
1036                 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN {: 
1037                 ParseNode pn=new ParseNode("createobject");
1038                 pn.addChild(type);
1039                 pn.addChild(args);
1040                 RESULT=pn;
1041         :}
1042 //      |       NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1043 //      |       primary DOT NEW IDENTIFIER
1044 //                      LPAREN argument_list_opt RPAREN {: 
1045 //              
1046 //      :}
1047 //      |       primary DOT NEW IDENTIFIER
1048 //                      LPAREN argument_list_opt RPAREN class_body
1049 //      |       name DOT NEW IDENTIFIER
1050 //                      LPAREN argument_list_opt RPAREN
1051 //      |       name DOT NEW IDENTIFIER
1052 //                      LPAREN argument_list_opt RPAREN class_body
1053         ;
1054 argument_list_opt ::=
1055         {: RESULT=new ParseNode("empty"); :}
1056         |       argument_list:args {: RESULT=args; :}
1057         ;
1058 argument_list ::=
1059                 expression:exp {:
1060                 ParseNode pn=new ParseNode("argument_list");
1061                 pn.addChild(exp);
1062                 RESULT=pn;
1063         :}
1064         |       argument_list:list COMMA expression:exp {:
1065                 list.addChild(exp);
1066                 RESULT=list;
1067         :}
1068         ;
1069 array_creation_uninit ::=
1070                 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {: 
1071                 ParseNode pn=new ParseNode("createarray");
1072                 pn.addChild(type);
1073                 pn.addChild(dimexpr);
1074                 pn.addChild("dims_opt").setLiteral(dims);
1075                 RESULT=pn;
1076                 :}
1077         |       NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {: 
1078                 ParseNode pn=new ParseNode("createarray");
1079                 pn.addChild(type);
1080                 pn.addChild(dimexpr);
1081                 pn.addChild("dims_opt").setLiteral(dims);
1082                 RESULT=pn;
1083         :}
1084         ;
1085 //array_creation_init ::=
1086 //              NEW primitive_type dims array_initializer
1087 //      |       NEW class_or_interface_type dims array_initializer
1088 //      ;
1089 dim_exprs ::=   dim_expr:exp {: 
1090                 ParseNode pn=new ParseNode("dim_exprs");
1091                 pn.addChild(exp);
1092                 RESULT=pn; :}
1093         |       dim_exprs:base dim_expr:exp {: 
1094                 base.addChild(exp);
1095                 RESULT=base;
1096         :}
1097         ;
1098 dim_expr ::=    LBRACK expression:exp RBRACK {: RESULT=exp; :}
1099         ;
1100 dims_opt ::= {: RESULT=null; :}
1101         |       dims:dims {: RESULT = dims; :}
1102         ;
1103
1104 dims ::=        LBRACK RBRACK {: RESULT=new Integer(0); :}
1105         |       dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1106         ;
1107
1108 field_access ::=
1109                 primary:base DOT IDENTIFIER:id {: 
1110                 ParseNode pn=new ParseNode("fieldaccess");
1111                 pn.addChild("base").addChild(base);
1112                 pn.addChild("field").addChild(id);
1113                 RESULT=pn;
1114 :}
1115 //      |       SUPER DOT IDENTIFIER
1116 //      |       name DOT SUPER DOT IDENTIFIER
1117         ;
1118 method_invocation ::=
1119                 name:name LPAREN argument_list_opt:args RPAREN {: 
1120                 ParseNode pn=new ParseNode("methodinvoke1");
1121                 pn.addChild(name);
1122                 pn.addChild(args);
1123                 RESULT=pn;
1124         :}
1125         |       primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {: 
1126                 ParseNode pn=new ParseNode("methodinvoke2");
1127                 pn.addChild("base").addChild(base);
1128                 pn.addChild("id").addChild(name);
1129                 pn.addChild(args);
1130                 RESULT=pn;
1131         :}
1132 //      |       SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1133 //      |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1134         ;
1135 array_access ::=
1136                 name:name LBRACK expression:exp RBRACK {: 
1137                 ParseNode pn=new ParseNode("arrayaccess");
1138                 pn.addChild("base").addChild(name);
1139                 pn.addChild("index").addChild(exp);
1140                 RESULT=pn;
1141         :}
1142         |       primary_no_new_array:base LBRACK expression:exp RBRACK {: 
1143                 ParseNode pn=new ParseNode("arrayaccess");
1144                 pn.addChild("base").addChild(base);
1145                 pn.addChild("index").addChild(exp);
1146                 RESULT=pn;
1147         :}
1148 //      |       array_creation_init:init LBRACK expression:exp RBRACK {: 
1149 //              ParseNode pn=new ParseNode("arrayaccess");
1150 //              pn.addChild("init").addChild(init);
1151 //              pn.addChild("index").addChild(exp);
1152 //              RESULT=pn;
1153 //      :}
1154         ;
1155 postfix_expression ::=
1156                 primary:exp {: 
1157         RESULT=exp; :}
1158         |       name:exp {: RESULT=exp; :}
1159         |       postincrement_expression:exp {: RESULT=exp; :}
1160         |       postdecrement_expression:exp {: RESULT=exp; :}
1161         ;
1162 postincrement_expression ::=
1163                 postfix_expression:exp PLUSPLUS 
1164                 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1165         ;
1166 postdecrement_expression ::=
1167                 postfix_expression:exp MINUSMINUS
1168                 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1169         ;
1170 unary_expression ::=
1171                 preincrement_expression:exp {: RESULT=exp; :}
1172         |       predecrement_expression:exp {: RESULT=exp; :}
1173         |       PLUS unary_expression:exp 
1174         {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1175         |       MINUS unary_expression:exp
1176         {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1177         |       unary_expression_not_plus_minus:exp {: 
1178                         RESULT=exp; :}
1179         ;
1180 preincrement_expression ::=
1181                 PLUSPLUS unary_expression:exp
1182                 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
1183         ;
1184 predecrement_expression ::=
1185                 MINUSMINUS unary_expression:exp
1186                 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
1187         ;
1188 unary_expression_not_plus_minus ::=
1189                 postfix_expression:exp {: 
1190                 RESULT=exp; :}
1191 //      |       COMP unary_expression
1192         |       NOT unary_expression:exp 
1193                 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
1194         |       cast_expression:exp {: RESULT=exp; :}
1195         ;
1196 cast_expression ::=
1197                 LPAREN primitive_type:type
1198         //dims_opt 
1199                 RPAREN unary_expression:exp {: 
1200                 ParseNode pn=new ParseNode("cast1");
1201                 pn.addChild("type").addChild(type);
1202                 pn.addChild("exp").addChild(exp);
1203                 RESULT=pn;
1204         :}
1205         |       LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {: 
1206                 ParseNode pn=new ParseNode("cast2");
1207                 pn.addChild("type").addChild(type);
1208                 pn.addChild("exp").addChild(exp);
1209                 RESULT=pn;
1210
1211         :}
1212 //      |       LPAREN name dims RPAREN unary_expression_not_plus_minus
1213         ;
1214 multiplicative_expression ::=
1215                 unary_expression:exp {: 
1216                         RESULT=exp; :}
1217         |       multiplicative_expression:exp1 MULT unary_expression:exp2 {: 
1218                 ParseNode pn=new ParseNode("mult");
1219                 pn.addChild(exp1);
1220                 pn.addChild(exp2);
1221                 RESULT=pn;
1222         :}
1223         |       multiplicative_expression:exp1 DIV unary_expression:exp2 {:
1224                 ParseNode pn=new ParseNode("div");
1225                 pn.addChild(exp1);
1226                 pn.addChild(exp2);
1227                 RESULT=pn;
1228         :}
1229         |       multiplicative_expression:exp1 MOD unary_expression:exp2 {:
1230                 ParseNode pn=new ParseNode("mod");
1231                 pn.addChild(exp1);
1232                 pn.addChild(exp2);
1233                 RESULT=pn;
1234         :}
1235         ;
1236 additive_expression ::=
1237                 multiplicative_expression:exp {: 
1238                         RESULT=exp; :}
1239         |       additive_expression:exp1 PLUS multiplicative_expression:exp2 {: 
1240                 ParseNode pn=new ParseNode("add");
1241                 pn.addChild(exp1);
1242                 pn.addChild(exp2);
1243                 RESULT=pn;
1244         :}
1245         |       additive_expression:exp1 MINUS multiplicative_expression:exp2 {: 
1246                 ParseNode pn=new ParseNode("sub");
1247                 pn.addChild(exp1);
1248                 pn.addChild(exp2);
1249                 RESULT=pn;
1250         :}
1251         ;
1252 shift_expression ::=
1253                 additive_expression:exp {: 
1254                         RESULT=exp; :}
1255         |       shift_expression:exp1 LSHIFT additive_expression:exp2 {: 
1256                 ParseNode pn=new ParseNode("leftshift");
1257                 pn.addChild(exp1);
1258                 pn.addChild(exp2);
1259                 RESULT=pn;
1260         :}
1261         |       shift_expression:exp1 RSHIFT additive_expression:exp2 {: 
1262                 ParseNode pn=new ParseNode("rightshift");
1263                 pn.addChild(exp1);
1264                 pn.addChild(exp2);
1265                 RESULT=pn;
1266         :}
1267 //      |       shift_expression URSHIFT additive_expression
1268         ;
1269 relational_expression ::=
1270                 shift_expression:exp {: 
1271                         RESULT=exp; :}
1272         |       relational_expression:exp1 LT shift_expression:exp2 {:
1273                 ParseNode pn=new ParseNode("comp_lt");
1274                 pn.addChild(exp1);
1275                 pn.addChild(exp2);
1276                 RESULT=pn;
1277         :}
1278         |       relational_expression:exp1 GT shift_expression:exp2 {:
1279                 ParseNode pn=new ParseNode("comp_gt");
1280                 pn.addChild(exp1);
1281                 pn.addChild(exp2);
1282                 RESULT=pn;
1283         :}
1284         |       relational_expression:exp1 LTEQ shift_expression:exp2 {:
1285                 ParseNode pn=new ParseNode("comp_lte");
1286                 pn.addChild(exp1);
1287                 pn.addChild(exp2);
1288                 RESULT=pn;
1289         :}
1290         |       relational_expression:exp1 GTEQ shift_expression:exp2 {:
1291                 ParseNode pn=new ParseNode("comp_gte");
1292                 pn.addChild(exp1);
1293                 pn.addChild(exp2);
1294                 RESULT=pn;
1295         :}
1296 //      |       relational_expression INSTANCEOF reference_type
1297         ;
1298
1299 equality_expression ::=
1300                 relational_expression:exp {: 
1301                         RESULT=exp; :}
1302         |       equality_expression:exp1 EQEQ relational_expression:exp2 {: 
1303                 ParseNode pn=new ParseNode("equal");
1304                 pn.addChild(exp1);
1305                 pn.addChild(exp2);
1306                 RESULT=pn;
1307         :}
1308         |       equality_expression:exp1 NOTEQ relational_expression:exp2 {: 
1309                 ParseNode pn=new ParseNode("not_equal");
1310                 pn.addChild(exp1);
1311                 pn.addChild(exp2);
1312                 RESULT=pn;
1313         :}
1314         ;
1315 and_expression ::=
1316                 equality_expression:exp {: 
1317                 RESULT=exp; :}
1318         |       and_expression:exp1 AND equality_expression:exp2 {: 
1319                 ParseNode pn=new ParseNode("bitwise_and");
1320                 pn.addChild(exp1);
1321                 pn.addChild(exp2);
1322                 RESULT=pn;
1323         :}
1324         ;
1325 exclusive_or_expression ::=
1326                 and_expression:expr {: 
1327                         RESULT=expr;
1328                 :}
1329         |       exclusive_or_expression:exp1 XOR and_expression:exp2 {: 
1330                 ParseNode pn=new ParseNode("bitwise_xor");
1331                 pn.addChild(exp1);
1332                 pn.addChild(exp2);
1333                 RESULT=pn;
1334 :}
1335         ;
1336 inclusive_or_expression ::=
1337                 exclusive_or_expression:exclor {: 
1338                         RESULT=exclor; :}
1339         |       inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {: 
1340                 ParseNode pn=new ParseNode("bitwise_or");
1341                 pn.addChild(exp1);
1342                 pn.addChild(exp2);
1343                 RESULT=pn;
1344         :}
1345         ;
1346 conditional_and_expression ::=
1347                 inclusive_or_expression:inclor {: 
1348                         RESULT=inclor; :}
1349         |       conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
1350                 ParseNode pn=new ParseNode("logical_and");
1351                 pn.addChild(exp1);
1352                 pn.addChild(exp2);
1353                 RESULT=pn;
1354         :}
1355         ;
1356 conditional_or_expression ::=
1357                 conditional_and_expression:condand {: 
1358                         RESULT=condand; :}
1359         |       conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {: 
1360                 ParseNode pn=new ParseNode("logical_or");
1361                 pn.addChild(exp1);
1362                 pn.addChild(exp2);
1363                 RESULT=pn;
1364         :}
1365         ;
1366 conditional_expression ::=
1367                 conditional_or_expression:condor {: 
1368                         RESULT=condor; :}
1369 //      |       conditional_or_expression QUESTION expression 
1370 //                      COLON conditional_expression
1371         ;
1372 assignment_expression ::=
1373                 conditional_expression:expr {: 
1374                         RESULT=expr; :} |
1375                 assignment:assign {: 
1376                         RESULT=assign; :}
1377         ;
1378 // semantic check necessary here to ensure a valid left-hand side.
1379 // allowing a parenthesized variable here on the lhs was introduced in
1380 // JLS 2; thanks to Eric Blake for pointing this out.
1381 assignment ::=  postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
1382                 ParseNode pn=new ParseNode("assignment");
1383                 pn.addChild("op").addChild(op);
1384                 ParseNode pnargs=pn.addChild("args");
1385                 pnargs.addChild(lvalue);
1386                 pnargs.addChild(rvalue);
1387                 RESULT=pn;
1388          :}
1389         ;
1390 assignment_operator ::=
1391                 EQ {: RESULT=new ParseNode("eq"); :}
1392         |       MULTEQ {: RESULT=new ParseNode("multeq"); :}
1393         |       DIVEQ {: RESULT=new ParseNode("diveq"); :}
1394         |       MODEQ {: RESULT=new ParseNode("modeq"); :}
1395         |       PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
1396         |       MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
1397         |       LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
1398         |       RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
1399 //      |       URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
1400         |       ANDEQ {: RESULT=new ParseNode("andeq"); :}
1401         |       XOREQ {: RESULT=new ParseNode("xoreq"); :}
1402         |       OREQ {: RESULT=new ParseNode("oreq"); :}
1403         ;
1404 expression_opt ::=
1405         {:      RESULT=new ParseNode("empty"); :}
1406         |       expression:exp {: 
1407                 RESULT=exp; :}
1408         ;
1409 expression ::=  assignment_expression:exp {: 
1410                 RESULT=exp; :}
1411         ;
1412 //constant_expression ::=
1413 //              expression
1414 //      ;