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