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