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