Check in first version
[IRC.git] / Robust / src / Parse / java14.cup
1 package Parse;
2
3 import java_cup.runtime.*;
4 import Lex.Lexer;
5 import Tree.*;
6
7 /* Java 1.4 parser for CUP.  
8  * Copyright (C) 2002-2003 C. Scott Ananian <cananian@alumni.princeton.edu>
9  * This program is released under the terms of the GPL; see the file
10  * COPYING for more details.  There is NO WARRANTY on this code.
11  */
12
13 /*
14 JDK 1.4 Features added:
15   assertion statement.
16   statement_without_trailing_substatement ::= ...
17      |          assert_statement ;
18   assert_statement ::=
19                 ASSERT expression SEMICOLON
20         |       ASSERT expression COLON expression SEMICOLON
21         ;
22 */
23 parser code  {: 
24   Lexer lexer;
25
26   public Parser(Lexer l) {
27     this();
28     lexer=l;
29   }
30
31   public void syntax_error(java_cup.runtime.Symbol current) {
32     report_error("Syntax error (" + current.sym + ")", current);
33   }
34   public void report_error(String message, java_cup.runtime.Symbol info) {
35     lexer.errorMsg(message, info);
36   }
37 :};
38
39 scan with {: return lexer.nextToken(); :};
40
41 terminal BOOLEAN; // primitive_type
42 terminal BYTE, SHORT, INT, LONG, CHAR; // integral_type
43 terminal FLOAT, DOUBLE; // floating_point_type
44 terminal LBRACK, RBRACK; // array_type
45 terminal java.lang.String IDENTIFIER; // name
46 terminal DOT; // qualified_name
47 terminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;
48 terminal PACKAGE; // package_declaration
49 terminal IMPORT; // import_declaration
50 terminal PUBLIC, PROTECTED, PRIVATE; // modifier
51 terminal STATIC; // modifier
52 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
53 terminal CLASS; // class_declaration
54 terminal EXTENDS; // super
55 terminal IMPLEMENTS; // interfaces
56 terminal VOID; // method_header
57 terminal THROWS; // throws
58 terminal THIS, SUPER; // explicit_constructor_invocation
59 terminal INTERFACE; // interface_declaration
60 terminal IF, ELSE; // if_then_statement, if_then_else_statement
61 terminal SWITCH; // switch_statement
62 terminal CASE, DEFAULT; // switch_label
63 terminal DO, WHILE; // while_statement, do_statement
64 terminal FOR; // for_statement
65 terminal BREAK; // break_statement
66 terminal CONTINUE; // continue_statement
67 terminal RETURN; // return_statement
68 terminal THROW; // throw_statement
69 terminal TRY; // try_statement
70 terminal CATCH; // catch_clause
71 terminal FINALLY; // finally
72 terminal NEW; // class_instance_creation_expression
73 terminal PLUSPLUS; // postincrement_expression
74 terminal MINUSMINUS; // postdecrement_expression
75 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
76 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
77 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
78 terminal EQEQ, NOTEQ; // equality_expression
79 terminal AND; // and_expression
80 terminal XOR; // exclusive_or_expression
81 terminal OR;  // inclusive_or_expression
82 terminal ANDAND; // conditional_and_expression
83 terminal OROR; // conditional_or_expression
84 terminal QUESTION; // conditional_expression
85 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
86 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
87 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
88
89 terminal java.lang.Number INTEGER_LITERAL;
90 terminal java.lang.Number FLOATING_POINT_LITERAL;
91 terminal java.lang.Boolean BOOLEAN_LITERAL;
92 terminal java.lang.Character CHARACTER_LITERAL;
93 terminal java.lang.String STRING_LITERAL;
94 terminal NULL_LITERAL;
95
96 // Reserved but unused:
97 terminal CONST, GOTO;
98 // strictfp keyword, new in Java 1.2
99 terminal STRICTFP;
100 // assert keyword, new in Java 1.4
101 terminal ASSERT; // assert_statement
102 // lexer compatibility with Java 1.5
103 terminal ELLIPSIS;
104 terminal ENUM;
105
106 // 19.2) The Syntactic Grammar
107 non terminal goal;
108 // 19.3) Lexical Structure
109 non terminal literal;
110 // 19.4) Types, Values, and Variables
111 non terminal type, primitive_type, numeric_type;
112 non terminal integral_type, floating_point_type;
113 non terminal reference_type;
114 non terminal class_or_interface_type;
115 non terminal class_type, interface_type;
116 non terminal array_type;
117 // 19.5) Names
118 non terminal name, simple_name, qualified_name;
119 // 19.6) Packages
120 non terminal compilation_unit;
121 non terminal package_declaration_opt, package_declaration;
122 non terminal import_declarations_opt, import_declarations;
123 non terminal type_declarations_opt, type_declarations;
124 non terminal import_declaration;
125 non terminal single_type_import_declaration;
126 non terminal type_import_on_demand_declaration;
127 non terminal type_declaration;
128 // 19.7) Productions used only in the LALR(1) grammar
129 non terminal modifiers_opt, modifiers, modifier;
130 // 19.8.1) Class Declaration
131 non terminal class_declaration, super, super_opt;
132 non terminal interfaces, interfaces_opt, interface_type_list;
133 non terminal class_body;
134 non terminal class_body_declarations, class_body_declarations_opt;
135 non terminal class_body_declaration, class_member_declaration;
136 // 19.8.2) Field Declarations
137 non terminal field_declaration, variable_declarators, variable_declarator;
138 non terminal variable_declarator_id, variable_initializer;
139 // 19.8.3) Method Declarations
140 non terminal method_declaration, method_header, method_declarator;
141 non terminal formal_parameter_list_opt, formal_parameter_list;
142 non terminal formal_parameter;
143 non terminal throws_opt, throws;
144 non terminal class_type_list, method_body;
145 // 19.8.4) Static Initializers
146 non terminal static_initializer;
147 // 19.8.5) Constructor Declarations
148 non terminal constructor_declaration, constructor_declarator;
149 non terminal constructor_body;
150 non terminal explicit_constructor_invocation;
151 // 19.9.1) Interface Declarations
152 non terminal interface_declaration;
153 non terminal extends_interfaces_opt, extends_interfaces;
154 non terminal interface_body;
155 non terminal interface_member_declarations_opt, interface_member_declarations;
156 non terminal interface_member_declaration, constant_declaration;
157 non terminal abstract_method_declaration;
158 // 19.10) Arrays
159 non terminal array_initializer;
160 non terminal variable_initializers;
161 // 19.11) Blocks and Statements
162 non terminal block;
163 non terminal block_statements_opt, block_statements, block_statement;
164 non terminal local_variable_declaration_statement, local_variable_declaration;
165 non terminal statement, statement_no_short_if;
166 non terminal statement_without_trailing_substatement;
167 non terminal empty_statement;
168 non terminal labeled_statement, labeled_statement_no_short_if;
169 non terminal expression_statement, statement_expression;
170 non terminal if_then_statement;
171 non terminal if_then_else_statement, if_then_else_statement_no_short_if;
172 non terminal switch_statement, switch_block;
173 non terminal switch_block_statement_groups;
174 non terminal switch_block_statement_group;
175 non terminal switch_labels, switch_label;
176 non terminal while_statement, while_statement_no_short_if;
177 non terminal do_statement;
178 non terminal for_statement, for_statement_no_short_if;
179 non terminal for_init_opt, for_init;
180 non terminal for_update_opt, for_update;
181 non terminal statement_expression_list;
182 non terminal identifier_opt;
183 non terminal break_statement, continue_statement;
184 non terminal return_statement, throw_statement;
185 non terminal synchronized_statement, try_statement;
186 non terminal catches_opt, catches, catch_clause;
187 non terminal finally;
188 non terminal assert_statement;
189 // 19.12) Expressions
190 non terminal primary, primary_no_new_array;
191 non terminal class_instance_creation_expression;
192 non terminal argument_list_opt, argument_list;
193 non terminal array_creation_init, array_creation_uninit;
194 non terminal dim_exprs, dim_expr, dims_opt, dims;
195 non terminal field_access, method_invocation, array_access;
196 non terminal postfix_expression;
197 non terminal postincrement_expression, postdecrement_expression;
198 non terminal unary_expression, unary_expression_not_plus_minus;
199 non terminal preincrement_expression, predecrement_expression;
200 non terminal cast_expression;
201 non terminal multiplicative_expression, additive_expression;
202 non terminal shift_expression, relational_expression, equality_expression;
203 non terminal and_expression, exclusive_or_expression, inclusive_or_expression;
204 non terminal conditional_and_expression, conditional_or_expression;
205 non terminal conditional_expression, assignment_expression;
206 non terminal assignment;
207 non terminal assignment_operator;
208 non terminal expression_opt, expression;
209 non terminal constant_expression;
210
211 start with goal;
212
213 // 19.2) The Syntactic Grammar
214 goal ::=        compilation_unit
215         ;
216
217 // 19.3) Lexical Structure.
218 literal ::=     INTEGER_LITERAL
219         |       FLOATING_POINT_LITERAL
220         |       BOOLEAN_LITERAL
221         |       CHARACTER_LITERAL
222         |       STRING_LITERAL
223         |       NULL_LITERAL
224         ;
225
226 // 19.4) Types, Values, and Variables
227 type    ::=     primitive_type
228         |       reference_type
229         ;
230 primitive_type ::=
231                 numeric_type
232         |       BOOLEAN
233         ;
234 numeric_type::= integral_type
235         |       floating_point_type
236         ;
237 integral_type ::= 
238                 BYTE 
239         |       SHORT 
240         |       INT 
241         |       LONG 
242         |       CHAR 
243         ;
244 floating_point_type ::= 
245                 FLOAT 
246         |       DOUBLE
247         ;
248
249 reference_type ::=
250                 class_or_interface_type
251         |       array_type
252         ;
253 class_or_interface_type ::= name;
254
255 class_type ::=  class_or_interface_type;
256 interface_type ::= class_or_interface_type;             
257
258 array_type ::=  primitive_type dims
259         |       name dims
260         ;
261
262 // 19.5) Names
263 name    ::=     simple_name
264         |       qualified_name
265         ;
266 simple_name ::= IDENTIFIER
267         ;
268 qualified_name ::=
269                 name DOT IDENTIFIER
270         ;
271
272 // 19.6) Packages
273 compilation_unit ::=
274                 package_declaration_opt 
275                 import_declarations_opt
276                 type_declarations_opt
277                 ;
278 package_declaration_opt ::= package_declaration | ;
279 import_declarations_opt ::= import_declarations | ;
280 type_declarations_opt   ::= type_declarations   | ;
281
282 import_declarations ::= 
283                 import_declaration
284         |       import_declarations import_declaration
285         ;
286 type_declarations ::= 
287                 type_declaration
288         |       type_declarations type_declaration
289         ;
290 package_declaration ::= 
291                 PACKAGE name SEMICOLON
292         ;
293 import_declaration ::= 
294                 single_type_import_declaration
295         |       type_import_on_demand_declaration
296         ;
297 single_type_import_declaration ::= 
298                 IMPORT name SEMICOLON
299         ;
300 type_import_on_demand_declaration ::=
301                 IMPORT name DOT MULT SEMICOLON
302         ;
303 type_declaration ::=
304                 class_declaration
305         |       interface_declaration
306         |       SEMICOLON
307         ;
308
309 // 19.7) Productions used only in the LALR(1) grammar
310 modifiers_opt::=
311         |       modifiers
312         ;
313 modifiers ::=   modifier
314         |       modifiers modifier
315         ;
316 modifier ::=    PUBLIC | PROTECTED | PRIVATE
317         |       STATIC
318         |       ABSTRACT | FINAL | NATIVE | SYNCHRONIZED | TRANSIENT | VOLATILE
319         |       STRICTFP // note that semantic analysis must check that the
320                          // context of the modifier allows strictfp.
321         ;
322
323 // 19.8) Classes
324
325 // 19.8.1) Class Declaration:
326 class_declaration ::= 
327         modifiers_opt CLASS IDENTIFIER super_opt interfaces_opt class_body
328         ;
329 super ::=       EXTENDS class_type
330         ;
331 super_opt ::=   
332         |       super
333         ;
334 interfaces ::=  IMPLEMENTS interface_type_list
335         ;
336 interfaces_opt::=
337         |       interfaces 
338         ;
339 interface_type_list ::= 
340                 interface_type
341         |       interface_type_list COMMA interface_type
342         ;
343 class_body ::=  LBRACE class_body_declarations_opt RBRACE 
344         ;
345 class_body_declarations_opt ::= 
346         |       class_body_declarations ;
347 class_body_declarations ::= 
348                 class_body_declaration
349         |       class_body_declarations class_body_declaration
350         ;
351 class_body_declaration ::=
352                 class_member_declaration
353         |       static_initializer
354         |       constructor_declaration
355         |       block
356         ;
357 class_member_declaration ::=
358                 field_declaration
359         |       method_declaration
360         /* repeat the prod for 'class_declaration' here: */
361         |       modifiers_opt CLASS IDENTIFIER super_opt interfaces_opt class_body
362         |       interface_declaration
363         |       SEMICOLON
364         ;
365
366 // 19.8.2) Field Declarations
367 field_declaration ::= 
368                 modifiers_opt type variable_declarators SEMICOLON
369         ;
370 variable_declarators ::=
371                 variable_declarator
372         |       variable_declarators COMMA variable_declarator
373         ;
374 variable_declarator ::=
375                 variable_declarator_id
376         |       variable_declarator_id EQ variable_initializer
377         ;
378 variable_declarator_id ::=
379                 IDENTIFIER
380         |       variable_declarator_id LBRACK RBRACK
381         ;
382 variable_initializer ::=
383                 expression
384         |       array_initializer
385         ;
386
387 // 19.8.3) Method Declarations
388 method_declaration ::=
389                 method_header method_body
390         ;
391 method_header ::=
392                 modifiers_opt type method_declarator throws_opt
393         |       modifiers_opt VOID method_declarator throws_opt
394         ;
395 method_declarator ::=
396                 IDENTIFIER LPAREN formal_parameter_list_opt RPAREN
397         |       method_declarator LBRACK RBRACK // deprecated
398         // be careful; the above production also allows 'void foo() []'
399         ;
400 formal_parameter_list_opt ::=
401         |       formal_parameter_list
402         ;
403 formal_parameter_list ::=
404                 formal_parameter
405         |       formal_parameter_list COMMA formal_parameter
406         ;
407 formal_parameter ::=
408                 type variable_declarator_id
409         |       FINAL type variable_declarator_id
410         ;
411 throws_opt ::=  
412         |       throws
413         ;
414 throws ::=      THROWS class_type_list
415         ;
416 class_type_list ::=
417                 class_type
418         |       class_type_list COMMA class_type
419         ;
420 method_body ::= block
421         |       SEMICOLON
422         ;
423
424 // 19.8.4) Static Initializers
425 static_initializer ::=
426                 STATIC block
427         ;
428
429 // 19.8.5) Constructor Declarations
430 constructor_declaration ::=
431                 modifiers_opt constructor_declarator throws_opt 
432                         constructor_body
433         ;
434 constructor_declarator ::=
435                 simple_name LPAREN formal_parameter_list_opt RPAREN
436         ;
437 constructor_body ::=
438                 LBRACE explicit_constructor_invocation
439                         block_statements RBRACE
440         |       LBRACE explicit_constructor_invocation RBRACE
441         |       LBRACE block_statements RBRACE
442         |       LBRACE RBRACE
443         ;
444 explicit_constructor_invocation ::=
445                 THIS LPAREN argument_list_opt RPAREN SEMICOLON
446         |       SUPER LPAREN argument_list_opt RPAREN SEMICOLON
447         |       primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON
448         |       primary DOT SUPER LPAREN argument_list_opt RPAREN SEMICOLON
449         ;
450
451 // 19.9) Interfaces
452
453 // 19.9.1) Interface Declarations
454 interface_declaration ::=
455                 modifiers_opt INTERFACE IDENTIFIER extends_interfaces_opt 
456                         interface_body
457         ;
458 extends_interfaces_opt ::=
459         |       extends_interfaces
460         ;
461 extends_interfaces ::=
462                 EXTENDS interface_type
463         |       extends_interfaces COMMA interface_type
464         ;
465 interface_body ::=
466                 LBRACE interface_member_declarations_opt RBRACE
467         ;
468 interface_member_declarations_opt ::=
469         |       interface_member_declarations
470         ;
471 interface_member_declarations ::=
472                 interface_member_declaration
473         |       interface_member_declarations interface_member_declaration
474         ;
475 interface_member_declaration ::=
476                 constant_declaration
477         |       abstract_method_declaration
478         |       class_declaration
479         |       interface_declaration
480         |       SEMICOLON
481         ;
482 constant_declaration ::=
483                 field_declaration
484         // need to semantically check that modifiers of field declaration
485         // include only PUBLIC, STATIC, or FINAL.  Other modifiers are
486         // disallowed.
487         ;
488 abstract_method_declaration ::=
489                 method_header SEMICOLON
490         ;
491
492 // 19.10) Arrays
493 array_initializer ::=
494                 LBRACE variable_initializers COMMA RBRACE
495         |       LBRACE variable_initializers RBRACE
496         |       LBRACE COMMA RBRACE
497         |       LBRACE RBRACE
498         ;
499 variable_initializers ::=
500                 variable_initializer
501         |       variable_initializers COMMA variable_initializer
502         ;
503
504 // 19.11) Blocks and Statements
505 block ::=       LBRACE block_statements_opt RBRACE
506         ;
507 block_statements_opt ::=
508         |       block_statements
509         ;
510 block_statements ::=
511                 block_statement
512         |       block_statements block_statement
513         ;
514 block_statement ::=
515                 local_variable_declaration_statement
516         |       statement
517         |       class_declaration
518         |       interface_declaration
519         ;
520 local_variable_declaration_statement ::=
521                 local_variable_declaration SEMICOLON
522         ;
523 local_variable_declaration ::=
524                 type variable_declarators
525         |       FINAL type variable_declarators
526         ;
527 statement ::=   statement_without_trailing_substatement
528         |       labeled_statement
529         |       if_then_statement
530         |       if_then_else_statement
531         |       while_statement
532         |       for_statement
533         ;
534 statement_no_short_if ::=
535                 statement_without_trailing_substatement
536         |       labeled_statement_no_short_if
537         |       if_then_else_statement_no_short_if
538         |       while_statement_no_short_if
539         |       for_statement_no_short_if
540         ;
541 statement_without_trailing_substatement ::=
542                 block
543         |       empty_statement
544         |       expression_statement
545         |       switch_statement
546         |       do_statement
547         |       break_statement
548         |       continue_statement
549         |       return_statement
550         |       synchronized_statement
551         |       throw_statement
552         |       try_statement
553         |       assert_statement
554         ;
555 empty_statement ::=
556                 SEMICOLON
557         ;
558 labeled_statement ::=
559                 IDENTIFIER COLON statement
560         ;
561 labeled_statement_no_short_if ::=
562                 IDENTIFIER COLON statement_no_short_if
563         ;
564 expression_statement ::=
565                 statement_expression SEMICOLON
566         ;
567 statement_expression ::=
568                 assignment
569         |       preincrement_expression
570         |       predecrement_expression
571         |       postincrement_expression
572         |       postdecrement_expression
573         |       method_invocation
574         |       class_instance_creation_expression
575         ;
576 if_then_statement ::=
577                 IF LPAREN expression RPAREN statement
578         ;
579 if_then_else_statement ::=
580                 IF LPAREN expression RPAREN statement_no_short_if 
581                         ELSE statement
582         ;
583 if_then_else_statement_no_short_if ::=
584                 IF LPAREN expression RPAREN statement_no_short_if
585                         ELSE statement_no_short_if
586         ;
587 switch_statement ::=
588                 SWITCH LPAREN expression RPAREN switch_block
589         ;
590 switch_block ::=
591                 LBRACE switch_block_statement_groups switch_labels RBRACE
592         |       LBRACE switch_block_statement_groups RBRACE
593         |       LBRACE switch_labels RBRACE
594         |       LBRACE RBRACE
595         ;
596 switch_block_statement_groups ::=
597                 switch_block_statement_group
598         |       switch_block_statement_groups switch_block_statement_group
599         ;
600 switch_block_statement_group ::=
601                 switch_labels block_statements
602         ;
603 switch_labels ::=
604                 switch_label
605         |       switch_labels switch_label
606         ;
607 switch_label ::=
608                 CASE constant_expression COLON
609         |       DEFAULT COLON
610         ;
611
612 while_statement ::=
613                 WHILE LPAREN expression RPAREN statement
614         ;
615 while_statement_no_short_if ::=
616                 WHILE LPAREN expression RPAREN statement_no_short_if
617         ;
618 do_statement ::=
619                 DO statement WHILE LPAREN expression RPAREN SEMICOLON
620         ;
621 for_statement ::=
622                 FOR LPAREN for_init_opt SEMICOLON expression_opt SEMICOLON
623                         for_update_opt RPAREN statement
624         ;
625 for_statement_no_short_if ::=
626                 FOR LPAREN for_init_opt SEMICOLON expression_opt SEMICOLON
627                         for_update_opt RPAREN statement_no_short_if
628         ;
629 for_init_opt ::=
630         |       for_init
631         ;
632 for_init ::=    statement_expression_list
633         |       local_variable_declaration
634         ;
635 for_update_opt ::=
636         |       for_update
637         ;
638 for_update ::=  statement_expression_list
639         ;
640 statement_expression_list ::=
641                 statement_expression
642         |       statement_expression_list COMMA statement_expression
643         ;
644
645 identifier_opt ::= 
646         |       IDENTIFIER
647         ;
648
649 break_statement ::=
650                 BREAK identifier_opt SEMICOLON
651         ;
652
653 continue_statement ::=
654                 CONTINUE identifier_opt SEMICOLON
655         ;
656 return_statement ::=
657                 RETURN expression_opt SEMICOLON
658         ;
659 throw_statement ::=
660                 THROW expression SEMICOLON
661         ;
662 synchronized_statement ::=
663                 SYNCHRONIZED LPAREN expression RPAREN block
664         ;
665 try_statement ::=
666                 TRY block catches
667         |       TRY block catches_opt finally
668         ;
669 catches_opt ::=
670         |       catches
671         ;
672 catches ::=     catch_clause
673         |       catches catch_clause
674         ;
675 catch_clause ::=
676                 CATCH LPAREN formal_parameter RPAREN block
677         ;
678 finally ::=     FINALLY block
679         ;
680 assert_statement ::=
681                 ASSERT expression SEMICOLON
682         |       ASSERT expression COLON expression SEMICOLON
683         ;
684
685 // 19.12) Expressions
686 primary ::=     primary_no_new_array
687         |       array_creation_init
688         |       array_creation_uninit
689         ;
690 primary_no_new_array ::=
691                 literal
692         |       THIS
693         |       LPAREN expression RPAREN
694         |       class_instance_creation_expression
695         |       field_access
696         |       method_invocation
697         |       array_access
698         |       primitive_type DOT CLASS
699         |       VOID DOT CLASS
700         |       array_type DOT CLASS
701         |       name DOT CLASS
702         |       name DOT THIS
703         ;
704 class_instance_creation_expression ::=
705                 NEW class_or_interface_type LPAREN argument_list_opt RPAREN
706         |       NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
707         |       primary DOT NEW IDENTIFIER
708                         LPAREN argument_list_opt RPAREN
709         |       primary DOT NEW IDENTIFIER
710                         LPAREN argument_list_opt RPAREN class_body
711         |       name DOT NEW IDENTIFIER
712                         LPAREN argument_list_opt RPAREN
713         |       name DOT NEW IDENTIFIER
714                         LPAREN argument_list_opt RPAREN class_body
715         ;
716 argument_list_opt ::=
717         |       argument_list
718         ;
719 argument_list ::=
720                 expression
721         |       argument_list COMMA expression
722         ;
723 array_creation_uninit ::=
724                 NEW primitive_type dim_exprs dims_opt
725         |       NEW class_or_interface_type dim_exprs dims_opt
726         ;
727 array_creation_init ::=
728                 NEW primitive_type dims array_initializer
729         |       NEW class_or_interface_type dims array_initializer
730         ;
731 dim_exprs ::=   dim_expr
732         |       dim_exprs dim_expr
733         ;
734 dim_expr ::=    LBRACK expression RBRACK
735         ;
736 dims_opt ::=
737         |       dims
738         ;
739 dims ::=        LBRACK RBRACK
740         |       dims LBRACK RBRACK
741         ;
742 field_access ::=
743                 primary DOT IDENTIFIER
744         |       SUPER DOT IDENTIFIER
745         |       name DOT SUPER DOT IDENTIFIER
746         ;
747 method_invocation ::=
748                 name LPAREN argument_list_opt RPAREN
749         |       primary DOT IDENTIFIER LPAREN argument_list_opt RPAREN
750         |       SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
751         |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
752         ;
753 array_access ::=
754                 name LBRACK expression RBRACK
755         |       primary_no_new_array LBRACK expression RBRACK
756         |       array_creation_init LBRACK expression RBRACK
757         ;
758 postfix_expression ::=
759                 primary
760         |       name
761         |       postincrement_expression
762         |       postdecrement_expression
763         ;
764 postincrement_expression ::=
765                 postfix_expression PLUSPLUS
766         ;
767 postdecrement_expression ::=
768                 postfix_expression MINUSMINUS
769         ;
770 unary_expression ::=
771                 preincrement_expression
772         |       predecrement_expression
773         |       PLUS unary_expression
774         |       MINUS unary_expression
775         |       unary_expression_not_plus_minus
776         ;
777 preincrement_expression ::=
778                 PLUSPLUS unary_expression
779         ;
780 predecrement_expression ::=
781                 MINUSMINUS unary_expression
782         ;
783 unary_expression_not_plus_minus ::=
784                 postfix_expression
785         |       COMP unary_expression
786         |       NOT unary_expression
787         |       cast_expression
788         ;
789 cast_expression ::=
790                 LPAREN primitive_type dims_opt RPAREN unary_expression
791         |       LPAREN expression RPAREN unary_expression_not_plus_minus
792         |       LPAREN name dims RPAREN unary_expression_not_plus_minus
793         ;
794 multiplicative_expression ::=
795                 unary_expression
796         |       multiplicative_expression MULT unary_expression
797         |       multiplicative_expression DIV unary_expression
798         |       multiplicative_expression MOD unary_expression
799         ;
800 additive_expression ::=
801                 multiplicative_expression
802         |       additive_expression PLUS multiplicative_expression
803         |       additive_expression MINUS multiplicative_expression
804         ;
805 shift_expression ::=
806                 additive_expression
807         |       shift_expression LSHIFT additive_expression
808         |       shift_expression RSHIFT additive_expression
809         |       shift_expression URSHIFT additive_expression
810         ;
811 relational_expression ::=
812                 shift_expression
813         |       relational_expression LT shift_expression
814         |       relational_expression GT shift_expression
815         |       relational_expression LTEQ shift_expression
816         |       relational_expression GTEQ shift_expression
817         |       relational_expression INSTANCEOF reference_type
818         ;
819 equality_expression ::=
820                 relational_expression
821         |       equality_expression EQEQ relational_expression
822         |       equality_expression NOTEQ relational_expression
823         ;
824 and_expression ::=
825                 equality_expression
826         |       and_expression AND equality_expression
827         ;
828 exclusive_or_expression ::=
829                 and_expression
830         |       exclusive_or_expression XOR and_expression
831         ;
832 inclusive_or_expression ::=
833                 exclusive_or_expression
834         |       inclusive_or_expression OR exclusive_or_expression
835         ;
836 conditional_and_expression ::=
837                 inclusive_or_expression
838         |       conditional_and_expression ANDAND inclusive_or_expression
839         ;
840 conditional_or_expression ::=
841                 conditional_and_expression
842         |       conditional_or_expression OROR conditional_and_expression
843         ;
844 conditional_expression ::=
845                 conditional_or_expression
846         |       conditional_or_expression QUESTION expression 
847                         COLON conditional_expression
848         ;
849 assignment_expression ::=
850                 conditional_expression
851         |       assignment
852         ;
853 // semantic check necessary here to ensure a valid left-hand side.
854 // allowing a parenthesized variable here on the lhs was introduced in
855 // JLS 2; thanks to Eric Blake for pointing this out.
856 assignment ::=  postfix_expression assignment_operator assignment_expression
857         ;
858 assignment_operator ::=
859                 EQ
860         |       MULTEQ
861         |       DIVEQ
862         |       MODEQ
863         |       PLUSEQ
864         |       MINUSEQ
865         |       LSHIFTEQ
866         |       RSHIFTEQ
867         |       URSHIFTEQ
868         |       ANDEQ
869         |       XOREQ
870         |       OREQ
871         ;
872 expression_opt ::=
873         |       expression
874         ;
875 expression ::=  assignment_expression
876         ;
877 constant_expression ::=
878                 expression
879         ;