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