3 import java_cup.runtime.*;
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.
14 JDK 1.4 Features added:
16 statement_without_trailing_substatement ::= ...
19 ASSERT expression SEMICOLON
20 | ASSERT expression COLON expression SEMICOLON
26 public Parser(Lexer l) {
31 public void syntax_error(java_cup.runtime.Symbol current) {
32 report_error("Syntax error (" + current.sym + ")", current);
34 public void report_error(String message, java_cup.runtime.Symbol info) {
35 lexer.errorMsg(message, info);
39 scan with {: return lexer.nextToken(); :};
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
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;
96 // Reserved but unused:
98 // strictfp keyword, new in Java 1.2
100 // assert keyword, new in Java 1.4
101 terminal ASSERT; // assert_statement
102 // lexer compatibility with Java 1.5
106 // added for disjoint reachability analysis
110 // 19.2) The Syntactic Grammar
111 non terminal ParseNode goal;
112 // 19.3) Lexical Structure
113 non terminal ParseNode literal;
114 // 19.4) Types, Values, and Variables
115 non terminal ParseNode type, primitive_type, numeric_type;
116 non terminal ParseNode integral_type, floating_point_type;
117 non terminal ParseNode reference_type;
118 non terminal ParseNode class_or_interface_type;
119 non terminal ParseNode class_type;
120 non terminal ParseNode interface_type;
121 non terminal ParseNode array_type;
123 non terminal ParseNode name, simple_name, qualified_name;
125 non terminal ParseNode compilation_unit;
126 non terminal ParseNode package_declaration_opt, package_declaration;
127 non terminal ParseNode import_declarations_opt, import_declarations;
128 non terminal ParseNode type_declarations_opt, type_declarations;
129 non terminal ParseNode import_declaration;
130 non terminal ParseNode single_type_import_declaration;
131 non terminal ParseNode type_import_on_demand_declaration;
132 non terminal ParseNode type_declaration;
133 // 19.7) Productions used only in the LALR(1) grammar
134 non terminal ParseNode modifiers_opt, modifiers, modifier;
135 // 19.8.1) Class Declaration
136 non terminal ParseNode class_declaration, super, super_opt;
137 non terminal ParseNode interfaces, interfaces_opt, interface_type_list;
138 non terminal ParseNode class_body;
139 non terminal ParseNode class_body_declarations, class_body_declarations_opt;
140 non terminal ParseNode class_body_declaration, class_member_declaration;
141 // 19.8.2) Field Declarations
142 non terminal ParseNode field_declaration, variable_declarators, variable_declarator;
143 non terminal ParseNode variable_declarator_id;
144 non terminal ParseNode variable_initializer;
145 // 19.8.3) Method Declarations
146 non terminal ParseNode method_declaration, method_header, method_declarator;
147 non terminal ParseNode formal_parameter_list_opt, formal_parameter_list;
148 non terminal ParseNode formal_parameter;
149 non terminal ParseNode throws_opt;
150 non terminal ParseNode throws;
151 non terminal ParseNode class_type_list;
152 non terminal ParseNode method_body;
153 // 19.8.4) Static Initializers
154 non terminal ParseNode static_initializer;
155 // 19.8.5) Constructor Declarations
156 non terminal ParseNode constructor_declaration, constructor_declarator;
157 non terminal ParseNode constructor_body;
158 non terminal ParseNode explicit_constructor_invocation;
159 // 19.9.1) Interface Declarations
160 non terminal ParseNode interface_declaration;
161 non terminal ParseNode extends_interfaces_opt, extends_interfaces;
162 non terminal ParseNode interface_body;
163 non terminal ParseNode interface_member_declarations_opt, interface_member_declarations;
164 non terminal ParseNode interface_member_declaration, constant_declaration;
165 non terminal ParseNode abstract_method_declaration;
167 non terminal ParseNode array_initializer;
168 non terminal ParseNode variable_initializers;
169 // 19.11) Blocks and Statements
170 non terminal ParseNode block;
171 non terminal ParseNode block_statements_opt, block_statements, block_statement;
172 non terminal ParseNode local_variable_declaration_statement, local_variable_declaration;
173 non terminal ParseNode statement, statement_no_short_if;
174 non terminal ParseNode statement_without_trailing_substatement;
175 non terminal ParseNode empty_statement;
176 //non terminal ParseNode labeled_statement, labeled_statement_no_short_if;
177 non terminal ParseNode expression_statement, statement_expression;
178 non terminal ParseNode if_then_statement;
179 non terminal ParseNode if_then_else_statement, if_then_else_statement_no_short_if;
180 non terminal ParseNode switch_statement, switch_block;
181 non terminal ParseNode switch_block_statement_groups;
182 non terminal ParseNode switch_block_statement_group;
183 non terminal ParseNode switch_labels, switch_label;
184 non terminal ParseNode while_statement, while_statement_no_short_if;
185 non terminal ParseNode do_statement;
186 non terminal ParseNode for_statement, for_statement_no_short_if;
187 non terminal ParseNode for_init_opt, for_init;
188 non terminal ParseNode for_update_opt, for_update;
189 non terminal ParseNode statement_expression_list;
190 //non terminal ParseNode identifier_opt;
191 non terminal ParseNode break_statement, continue_statement;
192 non terminal ParseNode return_statement;
193 non terminal ParseNode throw_statement;
194 non terminal ParseNode synchronized_statement;
195 non terminal ParseNode try_statement;
196 non terminal ParseNode catches_opt;
197 non terminal ParseNode catches, catch_clause;
198 non terminal ParseNode finally;
199 //non terminal ParseNode assert_statement;
200 non terminal ParseNode genreach_statement;
201 // 19.12) Expressions
202 non terminal ParseNode primary, primary_no_new_array;
203 non terminal ParseNode class_instance_creation_expression;
204 non terminal ParseNode cons_argument_list_opt, cons_argument_list;
205 non terminal ParseNode argument_list_opt, argument_list;
206 non terminal ParseNode array_creation_init;
207 non terminal ParseNode array_creation_uninit;
208 non terminal ParseNode dim_exprs, dim_expr;
209 non terminal Integer dims_opt, dims;
210 non terminal ParseNode field_access, method_invocation;
211 non terminal ParseNode array_access;
212 non terminal ParseNode postfix_expression;
213 non terminal ParseNode postincrement_expression, postdecrement_expression;
214 non terminal ParseNode unary_expression, unary_expression_not_plus_minus;
215 non terminal ParseNode preincrement_expression, predecrement_expression;
216 non terminal ParseNode cast_expression;
217 non terminal ParseNode multiplicative_expression, additive_expression;
218 non terminal ParseNode shift_expression, relational_expression, equality_expression;
219 non terminal ParseNode and_expression, exclusive_or_expression, inclusive_or_expression;
220 non terminal ParseNode conditional_and_expression, conditional_or_expression;
221 non terminal ParseNode conditional_expression;
222 non terminal ParseNode assignment_expression;
223 non terminal ParseNode assignment;
224 non terminal ParseNode assignment_operator;
225 non terminal ParseNode expression_opt, expression;
226 non terminal ParseNode constant_expression;
227 //failure aware computation keywords
230 terminal ISAVAILABLE;
235 non terminal ParseNode flag_declaration;
236 non terminal ParseNode task_declaration;
237 non terminal ParseNode task_parameter_list;
238 non terminal ParseNode task_parameter;
239 non terminal ParseNode flag_expression;
240 non terminal ParseNode flag_andexpression;
241 non terminal ParseNode flag_notexpression;
242 non terminal ParseNode task_exitstatement;
243 non terminal ParseNode flag_effects_opt;
244 non terminal ParseNode flag_effects;
245 non terminal ParseNode flag_effect;
246 non terminal ParseNode flag_list;
247 non terminal ParseNode flag_list_opt;
248 non terminal ParseNode flag_change;
250 non terminal ParseNode cons_checks_opt;
251 non terminal ParseNode cons_checks;
252 non terminal ParseNode cons_check;
254 non terminal ParseNode tag_variable_declaration_statement;
255 non terminal ParseNode tag_expression_list;
256 non terminal ParseNode tag_expression;
257 non terminal ParseNode tag_list;
258 non terminal ParseNode tag_list_opt;
259 non terminal ParseNode tag_change;
261 //distributed transaction keywords
266 non terminal ParseNode atomic_statement;
267 non terminal ParseNode getoffset_expression;
269 //disjointness for Java
272 //coarse-grain parallelization
275 non terminal ParseNode sese_statement;
278 // JSR-201) Enum Declaration
279 non terminal ParseNode enum_declaration;
280 non terminal ParseNode enum_body, enum_constants_opt, enum_constants, enum_constant;
281 //non terminal ParseNode enum_arguments_opt, enum_body_declarations_opt;
289 TASK IDENTIFIER:id LPAREN task_parameter_list:tpl RPAREN
293 ParseNode pn=new ParseNode("task_declaration");
294 pn.addChild("name").addChild(id);
297 pn.addChild("body").addChild(body);
301 task_parameter_list ::=
303 ParseNode pn=new ParseNode("task_parameter_list");
307 | task_parameter_list:fpl COMMA task_parameter:fp {:
314 type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE {:
315 ParseNode pn=new ParseNode("task_parameter");
318 pn.addChild("flag").addChild(exp);
321 | type:type variable_declarator_id:name LBRACE flag_expression:exp RBRACE LBRACE tag_expression_list:texp RBRACE {:
322 ParseNode pn=new ParseNode("task_parameter");
325 pn.addChild("flag").addChild(exp);
326 pn.addChild("tag").addChild(texp);
329 | type:type variable_declarator_id:name LBRACE RBRACE LBRACE tag_expression_list:texp RBRACE {:
330 ParseNode pn=new ParseNode("task_parameter");
333 pn.addChild("tag").addChild(texp);
336 | OPTIONAL task_parameter:fp {:
337 ParseNode pn=new ParseNode("task_parameter");
338 pn.addChild("optional").addChild(fp);
344 tag_expression_list ::= tag_expression:te {:
345 ParseNode pn=new ParseNode("tag_expression_list");
349 | tag_expression_list:tel COMMA tag_expression:te {:
355 tag_expression ::= IDENTIFIER:type IDENTIFIER:id {:
356 ParseNode pn=new ParseNode("tag_expression");
357 pn.addChild("type").addChild(type);
358 pn.addChild("single").addChild(id);
363 tag_list_opt ::= LBRACE tag_list:fl RBRACE {:RESULT=fl;:}
364 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
365 | {: RESULT = new ParseNode("empty"); :}
368 tag_list ::= tag_change:fc {:
369 ParseNode pn=new ParseNode("tag_list");
373 | tag_list:fl COMMA tag_change:fc {:
378 tag_change ::= IDENTIFIER:id {:
379 RESULT=new ParseNode("name").addChild(id).getRoot();
381 | NOT IDENTIFIER:id {:
382 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
386 flag_andexpression:exp {:
389 | flag_expression:exp1 OROR flag_andexpression:exp2 {:
390 ParseNode pn=new ParseNode("or");
397 flag_andexpression ::=
398 flag_notexpression:exp {: RESULT=exp; :}
399 | flag_notexpression:exp1 ANDAND flag_andexpression:exp2 {:
400 ParseNode pn=new ParseNode("and");
407 flag_notexpression ::=
408 NOT flag_notexpression:exp {:
409 ParseNode pn=new ParseNode("not");
413 | LPAREN flag_expression:exp RPAREN {:
417 ParseNode pn=new ParseNode("name");
423 task_exitstatement ::= TASKEXIT flag_effects_opt:opt cons_checks_opt:cco SEMICOLON {:
424 RESULT=(new ParseNode("taskexit")).addChild(opt).getRoot().addChild(cco).getRoot();
427 cons_checks_opt ::= ASSERT LPAREN cons_checks:cc RPAREN {: RESULT=cc; :}
428 | {: RESULT = new ParseNode("empty"); :}
431 cons_checks ::= cons_check:cc {:
432 ParseNode pn=new ParseNode("cons_checks");
436 | cons_checks:ccs COMMA cons_check:cc {:
441 cons_check ::= IDENTIFIER:name LPAREN cons_argument_list_opt:args RPAREN {:
442 ParseNode pn=new ParseNode("cons_check");
443 pn.addChild("name").addChild("identifier").addChild(name);
448 flag_effects_opt ::= LPAREN flag_effects:fe RPAREN {:RESULT=fe;:}
449 | {: RESULT = new ParseNode("empty"); :}
452 flag_effects ::= flag_effect:fe {:
453 ParseNode pn=new ParseNode("flag_effects_list");
457 | flag_effects:fes COMMA flag_effect:fe {:
462 flag_effect ::= IDENTIFIER:id LBRACE flag_list:fl RBRACE tag_list_opt:tlo {:
463 ParseNode pn=new ParseNode("flag_effect");
464 pn.addChild("name").addChild(id);
469 | IDENTIFIER:id LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
470 ParseNode pn=new ParseNode("flag_effect");
471 pn.addChild("name").addChild(id);
476 flag_list_opt ::= LBRACE flag_list:fl RBRACE {:RESULT=fl;:}
477 | LBRACE RBRACE {: RESULT = new ParseNode("empty"); :}
479 {: RESULT = new ParseNode("empty"); :}
482 flag_list ::= flag_change:fc {:
483 ParseNode pn=new ParseNode("flag_list");
487 | flag_list:fl COMMA flag_change:fc {:
492 flag_change ::= IDENTIFIER:id {:
493 RESULT=new ParseNode("name").addChild(id).getRoot();
496 RESULT=new ParseNode("not").addChild("name").addChild(id).getRoot();
499 // 19.2) The Syntactic Grammar
500 goal ::= compilation_unit:cu
506 // 19.3) Lexical Structure.
509 literal ::= INTEGER_LITERAL:integer_lit
511 ParseNode pn=new ParseNode("literal");
512 pn.addChild("integer").setLiteral(integer_lit);
515 | FLOATING_POINT_LITERAL:float_lit
517 ParseNode pn=new ParseNode("literal");
518 pn.addChild("float").setLiteral(float_lit);
521 | BOOLEAN_LITERAL:boolean_lit
523 ParseNode pn=new ParseNode("literal");
524 pn.addChild("boolean").setLiteral(boolean_lit);
527 | CHARACTER_LITERAL:char_lit
529 ParseNode pn=new ParseNode("literal");
530 pn.addChild("char").setLiteral(char_lit);
533 | STRING_LITERAL:string_lit
535 ParseNode pn=new ParseNode("literal");
536 pn.addChild("string").setLiteral(string_lit);
541 RESULT=(new ParseNode("literal")).addChild("null").getRoot();
545 // 19.4) Types, Values, and Variables
546 type ::= primitive_type:type {: RESULT=type; :}
547 | reference_type:type {: RESULT=type; :}
551 numeric_type:type {: RESULT=type; :}
552 | BOOLEAN {: RESULT=(new ParseNode("type")).addChild("boolean").getRoot(); :}
554 numeric_type::= integral_type:type {: RESULT=type; :}
555 | floating_point_type:type {: RESULT=type; :}
558 BYTE {: RESULT=(new ParseNode("type")).addChild("byte").getRoot(); :}
559 | SHORT {: RESULT=(new ParseNode("type")).addChild("short").getRoot(); :}
560 | INT {: RESULT=(new ParseNode("type")).addChild("int").getRoot(); :}
561 | LONG {: RESULT=(new ParseNode("type")).addChild("long").getRoot(); :}
562 | CHAR {: RESULT=(new ParseNode("type")).addChild("char").getRoot(); :}
564 floating_point_type ::=
565 FLOAT {: RESULT=(new ParseNode("type")).addChild("float").getRoot(); :}
566 | DOUBLE {: RESULT=(new ParseNode("type")).addChild("double").getRoot(); :}
570 class_or_interface_type:type {: RESULT=type; :}
571 | array_type:type {: RESULT=type; :}
573 class_or_interface_type ::= name:name {:
574 RESULT=(new ParseNode("type")).addChild("class").addChild(name).getRoot();
577 class_type ::= class_or_interface_type:type {: RESULT=type; :};
578 interface_type ::= class_or_interface_type:type {: RESULT=type; :};
580 array_type ::= primitive_type:prim dims:dims {:
581 ParseNode pn=(new ParseNode("type")).addChild("array");
582 pn.addChild("basetype").addChild(prim);
583 pn.addChild("dims").setLiteral(dims);
586 | name:name dims:dims {:
587 ParseNode pn=(new ParseNode("type")).addChild("array");
588 pn.addChild("basetype").addChild("type").addChild("class").addChild(name);
589 pn.addChild("dims").setLiteral(dims);
595 name ::= simple_name:name {: RESULT=name; :}
596 | qualified_name:name {: RESULT=name; :}
598 simple_name ::= IDENTIFIER:id {:
599 RESULT=(new ParseNode("name")).addChild("identifier").addChild(id).getRoot();
602 qualified_name ::= name:name DOT IDENTIFIER:id {:
603 ParseNode pn=new ParseNode("name");
604 pn.addChild("base").addChild(name);
605 pn.addChild("identifier").addChild(id);
612 package_declaration_opt:pdo
613 import_declarations_opt:ido
614 type_declarations_opt:tdo {:
615 ParseNode pn=new ParseNode("compilation_unit");
617 pn.addChild("packages").addChild(pdo);
618 pn.addChild("imports").addChild(ido);
622 package_declaration_opt ::= package_declaration:pdo {:
625 {: RESULT=new ParseNode("empty"); :}
628 import_declarations_opt ::= import_declarations:ido {:
631 {: RESULT=new ParseNode("empty"); :}
633 type_declarations_opt ::= type_declarations:tds {:
636 {: RESULT=new ParseNode("empty"); :}
639 import_declarations ::=
640 import_declaration:id {:
641 ParseNode pn=new ParseNode("import_decls_list");
645 | import_declarations:ids import_declaration:id {:
651 type_declarations ::=
652 type_declaration:td {:
653 ParseNode pn=new ParseNode("type_declaration_list");
657 | type_declarations:tds type_declaration:td {:
663 package_declaration ::=
664 PACKAGE name:name SEMICOLON {:
665 ParseNode pn=new ParseNode("package");
670 import_declaration ::=
671 single_type_import_declaration:sid {: RESULT=sid; :}
672 | type_import_on_demand_declaration:iod {: RESULT=iod; :}
674 single_type_import_declaration ::=
675 IMPORT name:name SEMICOLON {:
676 ParseNode pn=new ParseNode("import_single");
681 type_import_on_demand_declaration ::=
682 IMPORT name:name DOT MULT SEMICOLON {:
683 ParseNode pn=new ParseNode("import_ondemand");
694 | enum_declaration:ed
698 | task_declaration:td
702 | interface_declaration:in
706 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
709 // 19.7) Productions used only in the LALR(1) grammar
711 {: RESULT=new ParseNode("empty"); :}
716 modifiers ::= modifier:mo {:
717 ParseNode pn=new ParseNode("modifier_list");
721 | modifiers:mos modifier:mo {:
727 PUBLIC {: RESULT=new ParseNode("public"); :}|
728 PROTECTED {: RESULT=new ParseNode("protected"); :}|
729 PRIVATE {: RESULT=new ParseNode("private"); :}|
730 STATIC {: RESULT=new ParseNode("static"); :} |
731 ABSTRACT {: RESULT=new ParseNode("abstract"); :} |
732 FINAL {: RESULT=new ParseNode("final"); :}|
733 NATIVE {: RESULT=new ParseNode("native"); :} |
734 SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :} |
735 ATOMIC {: RESULT=new ParseNode("atomic"); :} |
736 VOLATILE {: RESULT=new ParseNode("volatile"); :} |
737 TRANSIENT {: RESULT=new ParseNode("transient"); :}
739 // STRICTFP // note that semantic analysis must check that the
740 // context of the modifier allows strictfp.
745 // 19.8.1) Class Declaration:
746 class_declaration ::=
747 modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo
750 ParseNode pn=new ParseNode("class_declaration");
751 pn.addChild("modifiers").addChild(mo);
752 pn.addChild("name").addChild(id);
753 pn.addChild("super").addChild(so);
754 pn.addChild("superIF").addChild(ifo);
755 pn.addChild("classbody").addChild(body);
759 super ::= EXTENDS class_type:classtype {:
764 {: RESULT=new ParseNode("empty"); :}
770 interfaces ::= IMPLEMENTS interface_type_list:iftl {: RESULT=iftl; :}
773 {: RESULT=new ParseNode("empty"); :}
774 | interfaces:ifs {: RESULT=ifs; :}
776 interface_type_list ::=
777 interface_type:ift {:
778 ParseNode pn=new ParseNode("interface_type_list");
782 | interface_type_list:iftl COMMA interface_type:ift {:
788 class_body ::= LBRACE class_body_declarations_opt:cbdo RBRACE {: RESULT=cbdo; :}
791 class_body_declarations_opt ::=
792 {: RESULT=new ParseNode("empty"); :}
793 | class_body_declarations:cbd {: RESULT=cbd; :};
795 class_body_declarations ::=
796 class_body_declaration:cbd {:
797 ParseNode pn=new ParseNode("class_body_declaration_list");
801 | class_body_declarations:cbds class_body_declaration:cbd {:
807 class_body_declaration ::=
808 class_member_declaration:member {:
809 RESULT=(new ParseNode("member")).addChild(member).getRoot();
811 | static_initializer:block{:
812 RESULT=(new ParseNode("static_block")).addChild(block).getRoot();
814 | constructor_declaration:constructor {:
815 RESULT=(new ParseNode("constructor")).addChild(constructor).getRoot();
818 RESULT=(new ParseNode("block")).addChild(block).getRoot();
821 class_member_declaration ::=
822 //failure aware computation
823 flag_declaration:flag {:
824 RESULT=(new ParseNode("flag")).addChild(flag).getRoot();
827 field_declaration:field {:
828 RESULT=(new ParseNode("field")).addChild(field).getRoot();
830 | method_declaration:method {:
831 RESULT=(new ParseNode("method")).addChild(method).getRoot();
833 /* repeat the prod for 'class_declaration' here: */
834 | modifiers_opt:mo CLASS IDENTIFIER:id super_opt:so interfaces_opt:ifo class_body:body
836 ParseNode pn=new ParseNode("inner_class_declaration");
837 pn.addChild("modifiers").addChild(mo);
838 pn.addChild("name").addChild(id);
839 pn.addChild("super").addChild(so);
840 pn.addChild("superIF").addChild(ifo);
841 pn.addChild("classbody").addChild(body);
844 | enum_declaration:ed
848 // | interface_declaration:interfaced {:
849 // RESULT=(new ParseNode("interface")).addChild(interfaced).getRoot();
851 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
855 // JSR-201) Enum Declaration
857 modifiers_opt:mo ENUM IDENTIFIER:id /*interfaces_opt:io*/ enum_body:body
859 ParseNode pn=new ParseNode("enum_declaration");
860 pn.addChild("modifiers").addChild(mo);
861 pn.addChild("name").addChild(id);
862 //pn.addChild("superIF").addChild(ifo);
863 pn.addChild("enumbody").addChild(body);
868 LBRACE enum_constants_opt:eco /*enum_body_declarations_opt:ebdo*/ RBRACE
871 enum_constants_opt ::=
872 {: RESULT=new ParseNode("empty"); :}
878 ParseNode pn=new ParseNode("enum_constants_list");
882 | enum_constants:ecs COMMA enum_constant:ec {:
888 IDENTIFIER:id /*enum_arguments_opt*/
890 ParseNode pn=new ParseNode("enum_constant");
891 pn.addChild("name").addChild(id);
894 // | IDENTIFIER enum_arguments_opt class_body
896 //enum_arguments_opt ::=
897 // | LPAREN argument_list_opt RPAREN
899 //enum_body_declarations_opt ::=
900 // | SEMICOLON class_body_declarations_opt:cbdo
904 //Failure aware computation
906 FLAG IDENTIFIER:id SEMICOLON {:
907 ParseNode pn=new ParseNode("flag_declaration");
908 pn.addChild("name").addChild(id);
911 EXTERNAL FLAG IDENTIFIER:id SEMICOLON {:
912 ParseNode pn=new ParseNode("flag_declaration");
913 pn.addChild("name").addChild(id);
914 pn.addChild("external");
919 // 19.8.2) Field Declarations
920 field_declaration ::=
921 modifiers_opt:mo type:type variable_declarators:var SEMICOLON {:
922 ParseNode pn=new ParseNode("field_declaration");
923 pn.addChild("modifier").addChild(mo);
924 pn.addChild("type").addChild(type);
925 pn.addChild("variables").addChild(var);
928 modifiers_opt:mo GLOBAL type:type variable_declarators:var SEMICOLON {:
929 ParseNode pn=new ParseNode("field_declaration");
930 pn.addChild("modifier").addChild(mo);
931 pn.addChild("type").addChild(type);
932 pn.addChild("variables").addChild(var);
933 pn.addChild("global");
938 variable_declarators ::=
939 variable_declarator:vd {:
940 ParseNode pn=new ParseNode("variable_declarators_list");
944 | variable_declarators:vds COMMA variable_declarator:vd {:
949 variable_declarator ::=
950 variable_declarator_id:id {:
951 ParseNode pn=new ParseNode("variable_declarator");
955 | variable_declarator_id:id EQ variable_initializer:init {:
956 ParseNode pn=new ParseNode("variable_declarator");
958 pn.addChild("initializer").addChild(init);
962 variable_declarator_id ::=
964 RESULT=(new ParseNode("single")).addChild(id).getRoot();:}
965 | variable_declarator_id:id LBRACK RBRACK {:
966 RESULT=(new ParseNode("array")).addChild(id).getRoot();:}
968 variable_initializer ::=
969 expression:exp {: RESULT=exp; :}
970 | array_initializer:ai {: RESULT=(new ParseNode("array_initializer")).addChild(ai).getRoot(); :}
973 // 19.8.3) Method Declarations
974 method_declaration ::=
975 method_header:header method_body:body {:
976 ParseNode pn=new ParseNode("method_declaration");
978 pn.addChild("body").addChild(body);
983 modifiers_opt:mo type:type method_declarator:decl throws_opt:to
985 ParseNode pn=new ParseNode("method_header");
986 pn.addChild("modifiers").addChild(mo);
987 pn.addChild("returntype").addChild(type);
988 pn.addChild("throws").addChild(to);
992 | modifiers_opt:mo VOID method_declarator:decl throws_opt:to
994 ParseNode pn=new ParseNode("method_header");
995 pn.addChild("modifiers").addChild(mo);
996 pn.addChild("throws").addChild(to);
1001 method_declarator ::=
1002 IDENTIFIER:id LPAREN formal_parameter_list_opt:params RPAREN {:
1003 ParseNode pn=new ParseNode("method_declarator");
1004 pn.addChild("name").addChild(id);
1005 pn.addChild("parameters").addChild(params);
1008 // | method_declarator LBRACK RBRACK // deprecated
1009 // be careful; the above production also allows 'void foo() []'
1011 formal_parameter_list_opt ::=
1012 {: RESULT=new ParseNode("empty"); :}
1013 | formal_parameter_list:fpl {:
1017 formal_parameter_list ::=
1018 formal_parameter:fp {:
1019 ParseNode pn=new ParseNode("formal_parameter_list");
1023 | formal_parameter_list:fpl COMMA formal_parameter:fp {:
1028 formal_parameter ::=
1029 type:type variable_declarator_id:name {:
1030 ParseNode pn=new ParseNode("formal_parameter");
1036 TAG variable_declarator_id:name {:
1037 ParseNode pn=new ParseNode("tag_parameter");
1041 | FINAL type:type variable_declarator_id:name {:
1042 ParseNode pn=new ParseNode("formal_parameter");
1049 {: RESULT=new ParseNode("empty"); :}
1053 throws ::= THROWS class_type_list:ctl
1054 {: RESULT=(new ParseNode("throw_list")).addChild(ctl).getRoot(); :}
1059 ParseNode pn=new ParseNode("class_type_list");
1063 | class_type_list:ctl COMMA class_type:ct
1069 method_body ::= block:block {:
1072 | SEMICOLON {: RESULT=new ParseNode("empty"); :}
1075 // 19.8.4) Static Initializers
1076 static_initializer ::=
1077 STATIC block:body {:
1078 ParseNode pn=new ParseNode("static_block_declaration");
1079 pn.addChild("body").addChild(body);
1084 // 19.8.5) Constructor Declarations
1085 constructor_declaration ::=
1086 modifiers_opt:mo constructor_declarator:cd throws_opt:to
1087 constructor_body:body {:
1088 ParseNode pn=new ParseNode("constructor_declaration");
1089 pn.addChild("modifiers").addChild(mo);
1090 pn.addChild("throws").addChild(to);
1092 pn.addChild("body").addChild(body);
1095 modifiers_opt:mo GLOBAL constructor_declarator:cd throws_opt:to
1096 constructor_body:body {:
1097 ParseNode pn=new ParseNode("constructor_declaration");
1098 pn.addChild("global");
1099 pn.addChild("modifiers").addChild(mo);
1100 pn.addChild("throws").addChild(to);
1102 pn.addChild("body").addChild(body);
1107 constructor_declarator ::=
1108 simple_name:name LPAREN formal_parameter_list_opt:fplo RPAREN {:
1109 ParseNode pn=new ParseNode("constructor_declarator");
1111 pn.addChild("parameters").addChild(fplo);
1115 constructor_body ::=
1116 LBRACE explicit_constructor_invocation:eci block_statements:bs RBRACE {:
1117 ParseNode pn=new ParseNode("constructor_body");
1122 LBRACE explicit_constructor_invocation:eci RBRACE {:
1123 ParseNode pn=new ParseNode("constructor_body");
1127 LBRACE block_statements:block RBRACE {:
1128 ParseNode pn=new ParseNode("constructor_body");
1132 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1134 explicit_constructor_invocation ::=
1135 THIS LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1136 ParseNode pn=new ParseNode("explconstrinv");
1141 SUPER LPAREN argument_list_opt:alo RPAREN SEMICOLON {:
1142 ParseNode pn=new ParseNode("superinvoke");
1146 // | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
1147 // | primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
1152 // 19.9.1) Interface Declarations
1153 interface_declaration ::=
1154 modifiers_opt:mo INTERFACE IDENTIFIER:id extends_interfaces_opt:io
1157 ParseNode pn=new ParseNode("interface_declaration");
1158 pn.addChild("modifiers").addChild(mo);
1159 pn.addChild("name").addChild(id);
1160 pn.addChild("superIF").addChild(io);
1161 pn.addChild("interfacebody").addChild(body);
1165 extends_interfaces_opt ::=
1166 {: RESULT=new ParseNode("empty"); :}
1167 | extends_interfaces:eifs {: RESULT=eifs; :}
1169 extends_interfaces ::=
1170 EXTENDS interface_type:ift
1172 ParseNode pn=new ParseNode("extend_interface_list");
1176 | extends_interfaces:eifs COMMA interface_type:ift
1183 LBRACE interface_member_declarations_opt:imdo RBRACE
1186 interface_member_declarations_opt ::=
1187 {: RESULT=new ParseNode("empty"); :}
1188 | interface_member_declarations:imd {: RESULT=imd; :}
1190 interface_member_declarations ::=
1191 interface_member_declaration:imd {:
1192 ParseNode pn=new ParseNode("interface_member_declaration_list");
1196 | interface_member_declarations:imds interface_member_declaration:imd {:
1201 interface_member_declaration ::=
1202 constant_declaration:constant {:
1203 RESULT=(new ParseNode("constant")).addChild(constant).getRoot();
1205 | abstract_method_declaration:method {:
1206 RESULT=(new ParseNode("method")).addChild(method).getRoot();
1208 | enum_declaration:ed {:
1209 RESULT=(new ParseNode("enum_declaration")).addChild(ed).getRoot();
1211 // | class_declaration:class
1212 // | interface_declaration:interface
1214 RESULT=new ParseNode("empty");
1217 constant_declaration ::=
1218 field_declaration:fd {: RESULT=fd; :}
1219 // need to semantically check that modifiers of field declaration
1220 // include only PUBLIC, STATIC, or FINAL. Other modifiers are
1223 abstract_method_declaration ::=
1224 method_header:header SEMICOLON {:
1225 ParseNode pn=new ParseNode("method_declaration");
1226 pn.addChild("header").addChild(header);
1227 pn.addChild("body").addChild(new ParseNode("empty"));
1234 array_initializer ::=
1235 LBRACE variable_initializers:var_init_list COMMA RBRACE {:
1236 RESULT=var_init_list;
1238 | LBRACE variable_initializers:var_init_list RBRACE {:
1239 RESULT=var_init_list;
1241 | LBRACE COMMA RBRACE {:
1242 RESULT=new ParseNode("empty");
1245 RESULT=new ParseNode("empty");
1248 variable_initializers ::=
1249 variable_initializer:var_init {:
1250 ParseNode pn=new ParseNode("var_init_list");
1251 pn.addChild(var_init);
1254 | variable_initializers:var_init_list COMMA variable_initializer:var_init {:
1255 var_init_list.addChild(var_init);
1256 RESULT=var_init_list;
1260 // 19.11) Blocks and Statements
1261 block ::= LBRACE block_statements_opt:bso RBRACE {:
1265 block_statements_opt ::=
1266 {: RESULT=new ParseNode("empty"); :}
1267 | block_statements:bs {:
1271 block_statements ::=
1272 block_statement:bs {:
1273 ParseNode pn=new ParseNode("block_statement_list");
1277 | block_statements:bss block_statement:bs {:
1283 tag_variable_declaration_statement:tvds {:
1286 | local_variable_declaration_statement:lvds {:
1289 | statement:statement {:
1292 // | enum_declaration:ed {:
1295 // | class_declaration
1296 // | interface_declaration
1298 tag_variable_declaration_statement ::=
1299 TAG IDENTIFIER:id EQ NEW TAG LPAREN IDENTIFIER:type RPAREN SEMICOLON {:
1300 ParseNode pn=new ParseNode("tag_declaration");
1301 pn.addChild("single").addChild(id);
1302 pn.addChild("type").addChild(type);
1306 local_variable_declaration_statement ::=
1307 local_variable_declaration:lvd SEMICOLON {:
1311 local_variable_declaration ::=
1312 type:type variable_declarators:var {:
1313 ParseNode pn=new ParseNode("local_variable_declaration");
1318 | FINAL type:type variable_declarators:var {:
1319 ParseNode pn=new ParseNode("local_variable_declaration");
1325 statement ::= statement_without_trailing_substatement:st {:
1328 // | labeled_statement:st {: RESULT=st; :}
1329 | if_then_statement:st {: RESULT=st; :}
1330 | if_then_else_statement:st {: RESULT=st; :}
1331 | while_statement:st {: RESULT=st; :}
1332 | for_statement:st {: RESULT=st; :}
1334 statement_no_short_if ::=
1335 statement_without_trailing_substatement:st {: RESULT=st; :}
1336 // | labeled_statement_no_short_if:st {: RESULT=st; :}
1337 | if_then_else_statement_no_short_if:st {: RESULT=st; :}
1338 | while_statement_no_short_if:st {: RESULT=st; :}
1339 | for_statement_no_short_if:st {: RESULT=st; :}
1341 statement_without_trailing_substatement ::=
1342 block:st {: RESULT=st; :}
1343 | empty_statement:st {: RESULT=st; :}
1344 | expression_statement:st {: RESULT=st; :}
1345 | switch_statement:st {: RESULT=st; :}
1346 | do_statement:dos {:RESULT=dos; :}
1347 | break_statement:st {: RESULT=st; :}
1348 | continue_statement:st {: RESULT=st; :}
1349 | return_statement:st {: RESULT=st; :}
1350 | task_exitstatement:st {: RESULT=st; :}
1351 | atomic_statement:st {: RESULT=st; :}
1352 | sese_statement:st {: RESULT=st; :}
1353 | synchronized_statement:st {: RESULT=st; :}
1354 | genreach_statement:st {: RESULT=st; :}
1355 | throw_statement:st {: RESULT=st; :}
1356 | try_statement:st {: RESULT=st; :}
1357 // | assert_statement
1360 SEMICOLON {: RESULT=new ParseNode("nop"); :}
1362 //labeled_statement ::=
1363 // IDENTIFIER COLON statement
1365 //labeled_statement_no_short_if ::=
1366 // IDENTIFIER COLON statement_no_short_if
1368 expression_statement ::=
1369 statement_expression:se SEMICOLON {:
1370 ParseNode pn=new ParseNode("expression");
1374 statement_expression ::=
1375 assignment:st {: RESULT=st; :}
1376 | preincrement_expression:st {: RESULT=st; :}
1377 | predecrement_expression:st {: RESULT=st; :}
1378 | postincrement_expression:st {: RESULT=st; :}
1379 | postdecrement_expression:st {: RESULT=st; :}
1380 | method_invocation:st {: RESULT=st; :}
1381 | class_instance_creation_expression:st {: RESULT=st; :}
1383 if_then_statement ::=
1384 IF LPAREN expression:exp RPAREN statement:st {:
1385 ParseNode pn=new ParseNode("ifstatement");
1386 pn.addChild("condition").addChild(exp);
1387 pn.addChild("statement").addChild(st);
1391 if_then_else_statement ::=
1392 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1393 ELSE statement:else_st {:
1394 ParseNode pn=new ParseNode("ifstatement");
1395 pn.addChild("condition").addChild(exp);
1396 pn.addChild("statement").addChild(st);
1397 pn.addChild("else_statement").addChild(else_st);
1401 if_then_else_statement_no_short_if ::=
1402 IF LPAREN expression:exp RPAREN statement_no_short_if:st
1403 ELSE statement_no_short_if:else_st {:
1404 ParseNode pn=new ParseNode("ifstatement");
1405 pn.addChild("condition").addChild(exp);
1406 pn.addChild("statement").addChild(st);
1407 pn.addChild("else_statement").addChild(else_st);
1411 switch_statement ::=
1412 SWITCH LPAREN expression:exp RPAREN switch_block:body
1414 ParseNode pn=new ParseNode("switch_statement");
1415 pn.addChild("condition").addChild(exp);
1416 pn.addChild("statement").addChild(body);
1421 LBRACE switch_block_statement_groups:sbsg switch_labels:sl RBRACE
1423 ParseNode pn = new ParseNode("switch_block");
1424 pn.addChild("switch_labels").addChild(sl);
1425 pn.addChild("switch_statements").addChild(new ParseNode("empty"));
1429 | LBRACE switch_block_statement_groups:sbsg RBRACE
1433 | LBRACE switch_labels:sl RBRACE
1435 ParseNode pnb = new ParseNode("switch_block_list");
1436 ParseNode pn = new ParseNode("switch_block");
1437 pn.addChild("switch_labels").addChild(sl);
1438 pn.addChild("switch_statements").addChild(new ParseNode("empty"));
1442 | LBRACE RBRACE {: RESULT=new ParseNode("empty"); :}
1444 switch_block_statement_groups ::=
1445 switch_block_statement_group:sbsg
1447 ParseNode pn = new ParseNode("switch_block_list");
1451 | switch_block_statement_groups:sbsgs switch_block_statement_group:sbsg
1453 sbsgs.addChild(sbsg);
1457 switch_block_statement_group ::=
1458 switch_labels:sls block_statements:body
1460 ParseNode pn=new ParseNode("switch_block");
1461 pn.addChild("switch_labels").addChild(sls);
1462 pn.addChild("switch_statements").addChild(body);
1469 ParseNode pn=new ParseNode("switch_label_list");
1473 | switch_labels:sls switch_label:sl
1480 CASE constant_expression:ce COLON
1482 ParseNode pn=new ParseNode("switch_label");
1488 RESULT=new ParseNode("default_switch_label");
1493 WHILE LPAREN expression:exp RPAREN statement:st {:
1494 ParseNode pn=new ParseNode("whilestatement");
1495 pn.addChild("condition").addChild(exp);
1496 pn.addChild("statement").addChild(st);
1500 while_statement_no_short_if ::=
1501 WHILE LPAREN expression:exp RPAREN statement_no_short_if:st {:
1502 ParseNode pn=new ParseNode("whilestatement");
1503 pn.addChild("condition").addChild(exp);
1504 pn.addChild("statement").addChild(st);
1509 DO statement:st WHILE LPAREN expression:exp RPAREN SEMICOLON {:
1510 ParseNode pn=new ParseNode("dowhilestatement");
1511 pn.addChild("condition").addChild(exp);
1512 pn.addChild("statement").addChild(st);
1517 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1518 for_update_opt:update RPAREN statement:st {:
1519 ParseNode pn=new ParseNode("forstatement");
1520 pn.addChild("initializer").addChild(init);
1521 pn.addChild("condition").addChild(exp);
1522 pn.addChild("update").addChild(update);
1523 pn.addChild("statement").addChild(st);
1527 for_statement_no_short_if ::=
1528 FOR LPAREN for_init_opt:init SEMICOLON expression_opt:exp SEMICOLON
1529 for_update_opt:update RPAREN statement_no_short_if:st {:
1530 ParseNode pn=new ParseNode("forstatement");
1531 pn.addChild("initializer").addChild(init);
1532 pn.addChild("condition").addChild(exp);
1533 pn.addChild("update").addChild(update);
1534 pn.addChild("statement").addChild(st);
1539 {: RESULT=new ParseNode("empty"); :}
1540 | for_init:init {: RESULT=init; :}
1542 for_init ::= statement_expression_list:list {: RESULT=list; :}
1543 | local_variable_declaration:decl {: RESULT=decl; :}
1546 {: RESULT=new ParseNode("empty"); :}
1547 | for_update:update {: RESULT=update; :}
1549 for_update ::= statement_expression_list:list {: RESULT=list; :}
1551 statement_expression_list ::=
1552 statement_expression:expr {:
1553 RESULT=(new ParseNode("statement_expression_list")).addChild(expr).getRoot();
1555 | statement_expression_list:list COMMA statement_expression:expr {:
1556 list.addChild(expr);
1561 //identifier_opt ::=
1568 SEMICOLON {: RESULT=new ParseNode("break"); :}
1571 continue_statement ::=
1575 {: RESULT=new ParseNode("continue"); :}
1577 return_statement ::=
1578 RETURN expression_opt:exp SEMICOLON {:
1579 RESULT=(new ParseNode("return")).addChild(exp).getRoot(); :}
1582 THROW expression:exp SEMICOLON {:
1583 RESULT=(new ParseNode("throwstatement")).addChild(exp).getRoot();
1586 synchronized_statement ::=
1587 SYNCHRONIZED LPAREN expression:e RPAREN block:b {:
1588 ParseNode pn=new ParseNode("synchronized");
1589 pn.addChild("expr").addChild(e);
1590 pn.addChild("block").addChild(b);
1594 atomic_statement ::=
1596 RESULT=(new ParseNode("atomic")).addChild(blk).getRoot();
1601 ParseNode pn = new ParseNode("sese");
1602 pn.addChild("body").addChild(blk);
1605 | SESE variable_declarator_id:id block:blk {:
1606 ParseNode pn = new ParseNode("sese");
1607 pn.addChild("body").addChild(blk);
1608 pn.addChild("identifier").addChild(id);
1611 | RBLOCK block:blk {:
1612 ParseNode pn = new ParseNode("sese");
1613 pn.addChild("body").addChild(blk);
1616 | RBLOCK variable_declarator_id:id block:blk {:
1617 ParseNode pn = new ParseNode("sese");
1618 pn.addChild("body").addChild(blk);
1619 pn.addChild("identifier").addChild(id);
1624 TRY block:bk catches:ca
1626 ParseNode pn=new ParseNode("trycatchstatement");
1627 pn.addChild("tryblock").addChild(bk);
1628 pn.addChild("catchblock").addChild(ca);
1631 | TRY block:bk catches_opt:ca finally:fi
1633 ParseNode pn=new ParseNode("trycatchstatement");
1634 pn.addChild("tryblock").addChild(bk);
1635 pn.addChild("catchblock").addChild(ca);
1636 pn.addChild("finallyblock").addChild(fi);
1641 {: RESULT=new ParseNode("empty"); :}
1645 catches ::= catch_clause:ca
1647 ParseNode pn=new ParseNode("catchlist");
1651 | catches:cas catch_clause:ca
1658 CATCH LPAREN formal_parameter:fp RPAREN block:bk
1660 ParseNode pn=new ParseNode("catchclause");
1661 pn.addChild("parameter").addChild(fp);
1662 pn.addChild("block").addChild(bk);
1666 finally ::= FINALLY block:bk
1671 //assert_statement ::=
1672 // ASSERT expression SEMICOLON
1673 // | ASSERT expression COLON expression SEMICOLON
1676 // 19.12) Expressions
1677 primary ::= primary_no_new_array:st {:
1679 | array_creation_init:st {:
1682 | array_creation_uninit:st {:
1686 primary_no_new_array ::=
1687 literal:lit {: RESULT=lit; :}
1688 | THIS {: RESULT=new ParseNode("this"); :}
1689 | LPAREN expression:exp RPAREN {: RESULT=exp; :}
1690 | class_instance_creation_expression:exp {: RESULT=exp; :}
1691 | field_access:exp {: RESULT=exp; :}
1692 | method_invocation:exp {: RESULT=exp; :}
1693 | array_access:exp {: RESULT=exp; :}
1694 | ISAVAILABLE LPAREN IDENTIFIER:id RPAREN {:
1695 ParseNode pn=new ParseNode("isavailable");
1699 // | primitive_type:pt DOT CLASS {:
1700 // ParseNode pn=new ParseNode("class_type");
1705 // | array_type:at DOT CLASS {:
1706 // ParseNode pn=new ParseNode("class_type");
1710 | name:name DOT CLASS {:
1711 ParseNode pn=new ParseNode("class_type");
1712 pn.addChild("type").addChild("class").addChild(name);
1717 class_instance_creation_expression ::=
1718 NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1719 ParseNode pn=new ParseNode("createobject");
1726 | GLOBAL NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1727 ParseNode pn=new ParseNode("createobject");
1731 pn.addChild("global");
1734 | SCRATCH NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1735 ParseNode pn=new ParseNode("createobject");
1739 pn.addChild("scratch");
1742 // Objects we want to track in disjointness analysis
1743 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN flag_list_opt:feo {:
1744 ParseNode pn=new ParseNode("createobject");
1748 pn.addChild("disjoint").addChild(id);
1751 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE RBRACE LBRACE tag_list:tl RBRACE {:
1752 ParseNode pn=new ParseNode("createobject");
1758 | NEW class_or_interface_type:type LPAREN argument_list_opt:args RPAREN LBRACE flag_list:fl RBRACE LBRACE tag_list:tl RBRACE {:
1759 ParseNode pn=new ParseNode("createobject");
1767 // | NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
1768 // | primary DOT NEW IDENTIFIER
1769 // LPAREN argument_list_opt RPAREN {:
1772 // | primary DOT NEW IDENTIFIER
1773 // LPAREN argument_list_opt RPAREN class_body
1774 // | name DOT NEW IDENTIFIER
1775 // LPAREN argument_list_opt RPAREN
1776 // | name DOT NEW IDENTIFIER
1777 // LPAREN argument_list_opt RPAREN class_body
1779 cons_argument_list_opt ::=
1780 {: RESULT=new ParseNode("empty"); :}
1781 | cons_argument_list:args {: RESULT=args; :}
1784 cons_argument_list ::=
1785 IDENTIFIER:id COLON expression:exp {:
1786 ParseNode pn=new ParseNode("cons_argument_list");
1787 ParseNode pnarg=pn.addChild("binding");
1788 pnarg.addChild("var").addChild(id);
1789 pnarg.addChild("exp").addChild(exp);
1792 | argument_list:list COMMA IDENTIFIER:id COLON expression:exp {:
1793 ParseNode pnarg=new ParseNode("binding");
1794 pnarg.addChild("var").addChild(id);
1795 pnarg.addChild("exp").addChild(exp);
1796 list.addChild(pnarg);
1801 argument_list_opt ::=
1802 {: RESULT=new ParseNode("empty"); :}
1803 | argument_list:args {: RESULT=args; :}
1808 ParseNode pn=new ParseNode("argument_list");
1812 | argument_list:list COMMA expression:exp {:
1817 array_creation_uninit ::=
1818 NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1819 ParseNode pn=new ParseNode("createarray");
1821 pn.addChild(dimexpr);
1822 pn.addChild("dims_opt").setLiteral(dims);
1825 | NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1826 ParseNode pn=new ParseNode("createarray");
1828 pn.addChild(dimexpr);
1829 pn.addChild("dims_opt").setLiteral(dims);
1832 | GLOBAL NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1833 ParseNode pn=new ParseNode("createarray");
1835 pn.addChild(dimexpr);
1836 pn.addChild("dims_opt").setLiteral(dims);
1837 pn.addChild("global");
1840 | SCRATCH NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1841 ParseNode pn=new ParseNode("createarray");
1843 pn.addChild(dimexpr);
1844 pn.addChild("dims_opt").setLiteral(dims);
1845 pn.addChild("scratch");
1848 | DISJOINT IDENTIFIER:id NEW primitive_type:type dim_exprs:dimexpr dims_opt:dims {:
1849 ParseNode pn=new ParseNode("createarray");
1851 pn.addChild(dimexpr);
1852 pn.addChild("dims_opt").setLiteral(dims);
1853 pn.addChild("disjoint").addChild(id);
1856 | GLOBAL NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1857 ParseNode pn=new ParseNode("createarray");
1859 pn.addChild(dimexpr);
1860 pn.addChild("dims_opt").setLiteral(dims);
1861 pn.addChild("global");
1864 | SCRATCH NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1865 ParseNode pn=new ParseNode("createarray");
1867 pn.addChild(dimexpr);
1868 pn.addChild("dims_opt").setLiteral(dims);
1869 pn.addChild("scratch");
1872 | DISJOINT IDENTIFIER:id NEW class_or_interface_type:type dim_exprs:dimexpr dims_opt:dims {:
1873 ParseNode pn=new ParseNode("createarray");
1875 pn.addChild(dimexpr);
1876 pn.addChild("dims_opt").setLiteral(dims);
1877 pn.addChild("disjoint").addChild(id);
1881 array_creation_init ::=
1882 NEW primitive_type:type dims:dims array_initializer:ai {:
1883 ParseNode pn=new ParseNode("createarray2");
1885 pn.addChild("dims_opt").setLiteral(dims);
1886 pn.addChild("initializer").addChild(ai);
1889 | NEW class_or_interface_type:type dims:dims array_initializer:ai {:
1890 ParseNode pn=new ParseNode("createarray2");
1892 pn.addChild("dims_opt").setLiteral(dims);
1893 pn.addChild("initializer").addChild(ai);
1897 dim_exprs ::= dim_expr:exp {:
1898 ParseNode pn=new ParseNode("dim_exprs");
1901 | dim_exprs:base dim_expr:exp {:
1906 dim_expr ::= LBRACK expression:exp RBRACK {: RESULT=exp; :}
1908 dims_opt ::= {: RESULT=new Integer(0); :}
1909 | dims:dims {: RESULT = dims; :}
1912 dims ::= LBRACK RBRACK {: RESULT=new Integer(1); :}
1913 | dims:dims LBRACK RBRACK {: RESULT=new Integer(dims.intValue()+1); :}
1917 primary:base DOT IDENTIFIER:id {:
1918 ParseNode pn=new ParseNode("fieldaccess");
1919 pn.addChild("base").addChild(base);
1920 pn.addChild("field").addChild(id);
1923 // | SUPER DOT IDENTIFIER
1924 // | name DOT SUPER DOT IDENTIFIER
1926 method_invocation ::=
1927 name:name LPAREN argument_list_opt:args RPAREN {:
1928 ParseNode pn=new ParseNode("methodinvoke1");
1933 | primary:base DOT IDENTIFIER:name LPAREN argument_list_opt:args RPAREN {:
1934 ParseNode pn=new ParseNode("methodinvoke2");
1935 pn.addChild("base").addChild(base);
1936 pn.addChild("id").addChild(name);
1940 | SUPER DOT IDENTIFIER:id LPAREN argument_list_opt:args RPAREN {:
1941 ParseNode name=new ParseNode("name");
1942 name.addChild("base").addChild("name").addChild("identifier").addChild("super");
1943 name.addChild("identifier").addChild(id);
1944 ParseNode pn=new ParseNode("methodinvoke1");
1949 // | name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
1952 name:name LBRACK expression:exp RBRACK {:
1953 ParseNode pn=new ParseNode("arrayaccess");
1954 pn.addChild("base").addChild(name);
1955 pn.addChild("index").addChild(exp);
1958 | primary_no_new_array:base LBRACK expression:exp RBRACK {:
1959 ParseNode pn=new ParseNode("arrayaccess");
1960 pn.addChild("base").addChild(base);
1961 pn.addChild("index").addChild(exp);
1964 // | array_creation_init:init LBRACK expression:exp RBRACK {:
1965 // ParseNode pn=new ParseNode("arrayaccess");
1966 // pn.addChild("init").addChild(init);
1967 // pn.addChild("index").addChild(exp);
1972 postfix_expression ::=
1975 | name:exp {: RESULT=exp; :}
1976 | postincrement_expression:exp {: RESULT=exp; :}
1977 | postdecrement_expression:exp {: RESULT=exp; :}
1979 postincrement_expression ::=
1980 postfix_expression:exp PLUSPLUS
1981 {: RESULT=(new ParseNode("postinc")).addChild(exp).getRoot(); :}
1983 postdecrement_expression ::=
1984 postfix_expression:exp MINUSMINUS
1985 {: RESULT=(new ParseNode("postdec")).addChild(exp).getRoot(); :}
1987 unary_expression ::=
1988 preincrement_expression:exp {: RESULT=exp; :}
1989 | predecrement_expression:exp {: RESULT=exp; :}
1990 | PLUS unary_expression:exp
1991 {: RESULT=(new ParseNode("unaryplus")).addChild(exp).getRoot(); :}
1992 | MINUS unary_expression:exp
1993 {: RESULT=(new ParseNode("unaryminus")).addChild(exp).getRoot(); :}
1994 | unary_expression_not_plus_minus:exp {:
1997 preincrement_expression ::=
1998 PLUSPLUS unary_expression:exp
1999 {: RESULT=(new ParseNode("preinc")).addChild(exp).getRoot(); :}
2001 predecrement_expression ::=
2002 MINUSMINUS unary_expression:exp
2003 {: RESULT=(new ParseNode("predec")).addChild(exp).getRoot(); :}
2005 unary_expression_not_plus_minus ::=
2006 postfix_expression:exp {:
2008 | COMP unary_expression:exp
2009 {: RESULT=(new ParseNode("comp")).addChild(exp).getRoot(); :}
2010 | NOT unary_expression:exp
2011 {: RESULT=(new ParseNode("not")).addChild(exp).getRoot(); :}
2012 | cast_expression:exp {: RESULT=exp; :}
2015 LPAREN primitive_type:type dims_opt:dims
2016 RPAREN unary_expression:exp {:
2017 ParseNode pn=new ParseNode("cast1");
2018 if (dims.intValue()==0)
2019 pn.addChild("type").addChild(type);
2021 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
2022 arrayt.addChild("basetype").addChild(type);
2023 arrayt.addChild("dims").setLiteral(dims);
2025 pn.addChild("exp").addChild(exp);
2028 | LPAREN expression:type RPAREN unary_expression_not_plus_minus:exp {:
2029 ParseNode pn=new ParseNode("cast2");
2030 pn.addChild("type").addChild(type);
2031 pn.addChild("exp").addChild(exp);
2035 | LPAREN name:name dims:dims RPAREN unary_expression_not_plus_minus:exp {:
2036 ParseNode pn=new ParseNode("cast1");
2037 if (dims.intValue()==0)
2038 pn.addChild("type").addChild("class").addChild(name);
2040 ParseNode arrayt=pn.addChild("type").addChild("type").addChild("array");
2041 arrayt.addChild("basetype").addChild("type").addChild("class").addChild(name);
2042 arrayt.addChild("dims").setLiteral(dims);
2044 pn.addChild("exp").addChild(exp);
2049 multiplicative_expression ::=
2050 unary_expression:exp {:
2052 | multiplicative_expression:exp1 MULT unary_expression:exp2 {:
2053 ParseNode pn=new ParseNode("mult");
2058 | multiplicative_expression:exp1 DIV unary_expression:exp2 {:
2059 ParseNode pn=new ParseNode("div");
2064 | multiplicative_expression:exp1 MOD unary_expression:exp2 {:
2065 ParseNode pn=new ParseNode("mod");
2071 additive_expression ::=
2072 multiplicative_expression:exp {:
2074 | additive_expression:exp1 PLUS multiplicative_expression:exp2 {:
2075 ParseNode pn=new ParseNode("add");
2080 | additive_expression:exp1 MINUS multiplicative_expression:exp2 {:
2081 ParseNode pn=new ParseNode("sub");
2087 shift_expression ::=
2088 additive_expression:exp {:
2090 | shift_expression:exp1 LSHIFT additive_expression:exp2 {:
2091 ParseNode pn=new ParseNode("leftshift");
2096 | shift_expression:exp1 RSHIFT additive_expression:exp2 {:
2097 ParseNode pn=new ParseNode("rightshift");
2102 | shift_expression:exp1 URSHIFT additive_expression:exp2 {:
2103 ParseNode pn=new ParseNode("urightshift");
2109 relational_expression ::=
2110 shift_expression:exp {:
2112 | relational_expression:exp1 LT shift_expression:exp2 {:
2113 ParseNode pn=new ParseNode("comp_lt");
2118 | relational_expression:exp1 GT shift_expression:exp2 {:
2119 ParseNode pn=new ParseNode("comp_gt");
2124 | relational_expression:exp1 LTEQ shift_expression:exp2 {:
2125 ParseNode pn=new ParseNode("comp_lte");
2130 | relational_expression:exp1 GTEQ shift_expression:exp2 {:
2131 ParseNode pn=new ParseNode("comp_gte");
2136 | relational_expression:exp INSTANCEOF reference_type:type {:
2137 ParseNode pn=new ParseNode("instanceof");
2138 pn.addChild("exp").addChild(exp);
2144 equality_expression ::=
2145 relational_expression:exp {:
2147 | equality_expression:exp1 EQEQ relational_expression:exp2 {:
2148 ParseNode pn=new ParseNode("equal");
2153 | equality_expression:exp1 NOTEQ relational_expression:exp2 {:
2154 ParseNode pn=new ParseNode("not_equal");
2161 equality_expression:exp {:
2163 | and_expression:exp1 AND equality_expression:exp2 {:
2164 ParseNode pn=new ParseNode("bitwise_and");
2170 exclusive_or_expression ::=
2171 and_expression:expr {:
2174 | exclusive_or_expression:exp1 XOR and_expression:exp2 {:
2175 ParseNode pn=new ParseNode("bitwise_xor");
2181 inclusive_or_expression ::=
2182 exclusive_or_expression:exclor {:
2184 | inclusive_or_expression:exp1 OR exclusive_or_expression:exp2 {:
2185 ParseNode pn=new ParseNode("bitwise_or");
2191 conditional_and_expression ::=
2192 inclusive_or_expression:inclor {:
2194 | conditional_and_expression:exp1 ANDAND inclusive_or_expression:exp2 {:
2195 ParseNode pn=new ParseNode("logical_and");
2201 conditional_or_expression ::=
2202 conditional_and_expression:condand {:
2204 | conditional_or_expression:exp1 OROR conditional_and_expression:exp2 {:
2205 ParseNode pn=new ParseNode("logical_or");
2211 conditional_expression ::=
2212 conditional_or_expression:condor {:
2214 | conditional_or_expression:condor QUESTION expression:exptrue
2215 COLON conditional_expression:expfalse {:
2216 ParseNode pn=new ParseNode("tert");
2217 pn.addChild("cond").addChild(condor);
2218 pn.addChild("trueexpr").addChild(exptrue);
2219 pn.addChild("falseexpr").addChild(expfalse);
2223 getoffset_expression ::=
2224 GETOFFSET LBRACE class_or_interface_type:type COMMA IDENTIFIER:id RBRACE {:
2225 ParseNode pn = new ParseNode("getoffset");
2227 pn.addChild("field").addChild(id);
2232 assignment_expression ::=
2233 conditional_expression:expr {:
2235 assignment:assign {:
2237 getoffset_expression:expr {:
2240 // semantic check necessary here to ensure a valid left-hand side.
2241 // allowing a parenthesized variable here on the lhs was introduced in
2242 // JLS 2; thanks to Eric Blake for pointing this out.
2243 assignment ::= postfix_expression:lvalue assignment_operator:op assignment_expression:rvalue {:
2244 ParseNode pn=new ParseNode("assignment");
2245 pn.addChild("op").addChild(op);
2246 ParseNode pnargs=pn.addChild("args");
2247 pnargs.addChild(lvalue);
2248 pnargs.addChild(rvalue);
2252 assignment_operator ::=
2253 EQ {: RESULT=new ParseNode("eq"); :}
2254 | MULTEQ {: RESULT=new ParseNode("multeq"); :}
2255 | DIVEQ {: RESULT=new ParseNode("diveq"); :}
2256 | MODEQ {: RESULT=new ParseNode("modeq"); :}
2257 | PLUSEQ {: RESULT=new ParseNode("pluseq"); :}
2258 | MINUSEQ {: RESULT=new ParseNode("minuseq"); :}
2259 | LSHIFTEQ {: RESULT=new ParseNode("lshifteq"); :}
2260 | RSHIFTEQ {: RESULT=new ParseNode("rshifteq"); :}
2261 | URSHIFTEQ {: RESULT=new ParseNode("urshifteq"); :}
2262 | ANDEQ {: RESULT=new ParseNode("andeq"); :}
2263 | XOREQ {: RESULT=new ParseNode("xoreq"); :}
2264 | OREQ {: RESULT=new ParseNode("oreq"); :}
2267 {: RESULT=new ParseNode("empty"); :}
2271 expression ::= assignment_expression:exp {:
2274 // note that this constraint must be enforced during semantic checking
2275 // 'constant_expression' should include enumerated constants.
2276 constant_expression ::=
2279 ParseNode pn = new ParseNode("constant_expression");
2286 genreach_statement ::=
2287 GENREACH IDENTIFIER:graphName SEMICOLON {:
2288 ParseNode pn=new ParseNode("genreach");
2289 pn.addChild("graphName").addChild(graphName);