bug fixes
[IRC.git] / Robust / JavaGrammar / Parse / java12.cup
1 package Parse;
2
3 import java_cup.runtime.*;
4
5 /* Java 1.2 parser for CUP.  
6  * Copyright (C) 1998-2003 C. Scott Ananian <cananian@alumni.princeton.edu>
7  * This program is released under the terms of the GPL; see the file
8  * COPYING for more details.  There is NO WARRANTY on this code.
9  */
10
11 /*
12 JDK 1.2 Features added:
13   strictfp modifier.
14   explicit_constructor_invocation ::= ...
15         | primary DOT THIS LPAREN argument_list_opt RPAREN SEMICOLON ;
16   field_access ::= ...
17         |       name DOT SUPER DOT IDENTIFIER ;
18   method_invocation ::= ...
19         |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN ;
20   parenthesized expression, plain identifiers qualifying instance
21   creation and explicit constructors, and array creation expression
22   fixes from JLS2 (thanks to Eric Blake for pointing these out)
23 */
24 parser code  {: 
25   Lexer lexer;
26
27   public Grm12(Lexer l) {
28     this();
29     lexer=l;
30   }
31
32   public void syntax_error(java_cup.runtime.Symbol current) {
33     report_error("Syntax error (" + current.sym + ")", current);
34   }
35   public void report_error(String message, java_cup.runtime.Symbol info) {
36     lexer.errorMsg(message, info);
37   }
38 :};
39
40 scan with {: return lexer.nextToken(); :};
41
42 terminal BOOLEAN; // primitive_type
43 terminal BYTE, SHORT, INT, LONG, CHAR; // integral_type
44 terminal FLOAT, DOUBLE; // floating_point_type
45 terminal LBRACK, RBRACK; // array_type
46 terminal java.lang.String IDENTIFIER; // name
47 terminal DOT; // qualified_name
48 terminal SEMICOLON, MULT, COMMA, LBRACE, RBRACE, EQ, LPAREN, RPAREN, COLON;
49 terminal PACKAGE; // package_declaration
50 terminal IMPORT; // import_declaration
51 terminal PUBLIC, PROTECTED, PRIVATE; // modifier
52 terminal STATIC; // modifier
53 terminal ABSTRACT, FINAL, NATIVE, SYNCHRONIZED, TRANSIENT, VOLATILE;
54 terminal CLASS; // class_declaration
55 terminal EXTENDS; // super
56 terminal IMPLEMENTS; // interfaces
57 terminal VOID; // method_header
58 terminal THROWS; // throws
59 terminal THIS, SUPER; // explicit_constructor_invocation
60 terminal INTERFACE; // interface_declaration
61 terminal IF, ELSE; // if_then_statement, if_then_else_statement
62 terminal SWITCH; // switch_statement
63 terminal CASE, DEFAULT; // switch_label
64 terminal DO, WHILE; // while_statement, do_statement
65 terminal FOR; // for_statement
66 terminal BREAK; // break_statement
67 terminal CONTINUE; // continue_statement
68 terminal RETURN; // return_statement
69 terminal THROW; // throw_statement
70 terminal TRY; // try_statement
71 terminal CATCH; // catch_clause
72 terminal FINALLY; // finally
73 terminal NEW; // class_instance_creation_expression
74 terminal PLUSPLUS; // postincrement_expression
75 terminal MINUSMINUS; // postdecrement_expression
76 terminal PLUS, MINUS, COMP, NOT, DIV, MOD;
77 terminal LSHIFT, RSHIFT, URSHIFT; // shift_expression
78 terminal LT, GT, LTEQ, GTEQ, INSTANCEOF; // relational_expression
79 terminal EQEQ, NOTEQ; // equality_expression
80 terminal AND; // and_expression
81 terminal XOR; // exclusive_or_expression
82 terminal OR;  // inclusive_or_expression
83 terminal ANDAND; // conditional_and_expression
84 terminal OROR; // conditional_or_expression
85 terminal QUESTION; // conditional_expression
86 terminal MULTEQ, DIVEQ, MODEQ, PLUSEQ, MINUSEQ; // assignment_operator
87 terminal LSHIFTEQ, RSHIFTEQ, URSHIFTEQ; // assignment_operator
88 terminal ANDEQ, XOREQ, OREQ; // assignment_operator
89
90 terminal java.lang.Number INTEGER_LITERAL;
91 terminal java.lang.Number FLOATING_POINT_LITERAL;
92 terminal java.lang.Boolean BOOLEAN_LITERAL;
93 terminal java.lang.Character CHARACTER_LITERAL;
94 terminal java.lang.String STRING_LITERAL;
95 terminal NULL_LITERAL;
96
97 // Reserved but unused:
98 terminal CONST, GOTO;
99 // strictfp keyword, new in Java 1.2
100 terminal STRICTFP;
101 // lexer compatibility with Java 1.4
102 terminal ASSERT;
103 // lexer compatibility with Java 1.5
104 terminal ELLIPSIS;
105 terminal ENUM;
106
107 // 19.2) The Syntactic Grammar
108 non terminal goal;
109 // 19.3) Lexical Structure
110 non terminal literal;
111 // 19.4) Types, Values, and Variables
112 non terminal type, primitive_type, numeric_type;
113 non terminal integral_type, floating_point_type;
114 non terminal reference_type;
115 non terminal class_or_interface_type;
116 non terminal class_type, interface_type;
117 non terminal array_type;
118 // 19.5) Names
119 non terminal name, simple_name, qualified_name;
120 // 19.6) Packages
121 non terminal compilation_unit;
122 non terminal package_declaration_opt, package_declaration;
123 non terminal import_declarations_opt, import_declarations;
124 non terminal type_declarations_opt, type_declarations;
125 non terminal import_declaration;
126 non terminal single_type_import_declaration;
127 non terminal type_import_on_demand_declaration;
128 non terminal type_declaration;
129 // 19.7) Productions used only in the LALR(1) grammar
130 non terminal modifiers_opt, modifiers, modifier;
131 // 19.8.1) Class Declaration
132 non terminal class_declaration, super, super_opt;
133 non terminal interfaces, interfaces_opt, interface_type_list;
134 non terminal class_body;
135 non terminal class_body_declarations, class_body_declarations_opt;
136 non terminal class_body_declaration, class_member_declaration;
137 // 19.8.2) Field Declarations
138 non terminal field_declaration, variable_declarators, variable_declarator;
139 non terminal variable_declarator_id, variable_initializer;
140 // 19.8.3) Method Declarations
141 non terminal method_declaration, method_header, method_declarator;
142 non terminal formal_parameter_list_opt, formal_parameter_list;
143 non terminal formal_parameter;
144 non terminal throws_opt, throws;
145 non terminal class_type_list, method_body;
146 // 19.8.4) Static Initializers
147 non terminal static_initializer;
148 // 19.8.5) Constructor Declarations
149 non terminal constructor_declaration, constructor_declarator;
150 non terminal constructor_body;
151 non terminal explicit_constructor_invocation;
152 // 19.9.1) Interface Declarations
153 non terminal interface_declaration;
154 non terminal extends_interfaces_opt, extends_interfaces;
155 non terminal interface_body;
156 non terminal interface_member_declarations_opt, interface_member_declarations;
157 non terminal interface_member_declaration, constant_declaration;
158 non terminal abstract_method_declaration;
159 // 19.10) Arrays
160 non terminal array_initializer;
161 non terminal variable_initializers;
162 // 19.11) Blocks and Statements
163 non terminal block;
164 non terminal block_statements_opt, block_statements, block_statement;
165 non terminal local_variable_declaration_statement, local_variable_declaration;
166 non terminal statement, statement_no_short_if;
167 non terminal statement_without_trailing_substatement;
168 non terminal empty_statement;
169 non terminal labeled_statement, labeled_statement_no_short_if;
170 non terminal expression_statement, statement_expression;
171 non terminal if_then_statement;
172 non terminal if_then_else_statement, if_then_else_statement_no_short_if;
173 non terminal switch_statement, switch_block;
174 non terminal switch_block_statement_groups;
175 non terminal switch_block_statement_group;
176 non terminal switch_labels, switch_label;
177 non terminal while_statement, while_statement_no_short_if;
178 non terminal do_statement;
179 non terminal for_statement, for_statement_no_short_if;
180 non terminal for_init_opt, for_init;
181 non terminal for_update_opt, for_update;
182 non terminal statement_expression_list;
183 non terminal identifier_opt;
184 non terminal break_statement, continue_statement;
185 non terminal return_statement, throw_statement;
186 non terminal synchronized_statement, try_statement;
187 non terminal catches_opt, catches, catch_clause;
188 non terminal finally;
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 SUPER LPAREN argument_list_opt RPAREN SEMICOLON
448         |       name 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         ;
554 empty_statement ::=
555                 SEMICOLON
556         ;
557 labeled_statement ::=
558                 IDENTIFIER COLON statement
559         ;
560 labeled_statement_no_short_if ::=
561                 IDENTIFIER COLON statement_no_short_if
562         ;
563 expression_statement ::=
564                 statement_expression SEMICOLON
565         ;
566 statement_expression ::=
567                 assignment
568         |       preincrement_expression
569         |       predecrement_expression
570         |       postincrement_expression
571         |       postdecrement_expression
572         |       method_invocation
573         |       class_instance_creation_expression
574         ;
575 if_then_statement ::=
576                 IF LPAREN expression RPAREN statement
577         ;
578 if_then_else_statement ::=
579                 IF LPAREN expression RPAREN statement_no_short_if 
580                         ELSE statement
581         ;
582 if_then_else_statement_no_short_if ::=
583                 IF LPAREN expression RPAREN statement_no_short_if
584                         ELSE statement_no_short_if
585         ;
586 switch_statement ::=
587                 SWITCH LPAREN expression RPAREN switch_block
588         ;
589 switch_block ::=
590                 LBRACE switch_block_statement_groups switch_labels RBRACE
591         |       LBRACE switch_block_statement_groups RBRACE
592         |       LBRACE switch_labels RBRACE
593         |       LBRACE RBRACE
594         ;
595 switch_block_statement_groups ::=
596                 switch_block_statement_group
597         |       switch_block_statement_groups switch_block_statement_group
598         ;
599 switch_block_statement_group ::=
600                 switch_labels block_statements
601         ;
602 switch_labels ::=
603                 switch_label
604         |       switch_labels switch_label
605         ;
606 switch_label ::=
607                 CASE constant_expression COLON
608         |       DEFAULT COLON
609         ;
610
611 while_statement ::=
612                 WHILE LPAREN expression RPAREN statement
613         ;
614 while_statement_no_short_if ::=
615                 WHILE LPAREN expression RPAREN statement_no_short_if
616         ;
617 do_statement ::=
618                 DO statement WHILE LPAREN expression RPAREN SEMICOLON
619         ;
620 for_statement ::=
621                 FOR LPAREN for_init_opt SEMICOLON expression_opt SEMICOLON
622                         for_update_opt RPAREN statement
623         ;
624 for_statement_no_short_if ::=
625                 FOR LPAREN for_init_opt SEMICOLON expression_opt SEMICOLON
626                         for_update_opt RPAREN statement_no_short_if
627         ;
628 for_init_opt ::=
629         |       for_init
630         ;
631 for_init ::=    statement_expression_list
632         |       local_variable_declaration
633         ;
634 for_update_opt ::=
635         |       for_update
636         ;
637 for_update ::=  statement_expression_list
638         ;
639 statement_expression_list ::=
640                 statement_expression
641         |       statement_expression_list COMMA statement_expression
642         ;
643
644 identifier_opt ::= 
645         |       IDENTIFIER
646         ;
647
648 break_statement ::=
649                 BREAK identifier_opt SEMICOLON
650         ;
651
652 continue_statement ::=
653                 CONTINUE identifier_opt SEMICOLON
654         ;
655 return_statement ::=
656                 RETURN expression_opt SEMICOLON
657         ;
658 throw_statement ::=
659                 THROW expression SEMICOLON
660         ;
661 synchronized_statement ::=
662                 SYNCHRONIZED LPAREN expression RPAREN block
663         ;
664 try_statement ::=
665                 TRY block catches
666         |       TRY block catches_opt finally
667         ;
668 catches_opt ::=
669         |       catches
670         ;
671 catches ::=     catch_clause
672         |       catches catch_clause
673         ;
674 catch_clause ::=
675                 CATCH LPAREN formal_parameter RPAREN block
676         ;
677 finally ::=     FINALLY block
678         ;
679
680 // 19.12) Expressions
681 primary ::=     primary_no_new_array
682         |       array_creation_init
683         |       array_creation_uninit
684         ;
685 primary_no_new_array ::=
686                 literal
687         |       THIS
688         |       LPAREN expression RPAREN
689         |       class_instance_creation_expression
690         |       field_access
691         |       method_invocation
692         |       array_access
693         |       primitive_type DOT CLASS
694         |       VOID DOT CLASS
695         |       array_type DOT CLASS
696         |       name DOT CLASS
697         |       name DOT THIS
698         ;
699 class_instance_creation_expression ::=
700                 NEW class_or_interface_type LPAREN argument_list_opt RPAREN
701         |       NEW class_or_interface_type LPAREN argument_list_opt RPAREN class_body
702         |       primary DOT NEW IDENTIFIER
703                         LPAREN argument_list_opt RPAREN
704         |       primary DOT NEW IDENTIFIER
705                         LPAREN argument_list_opt RPAREN class_body
706         |       name DOT NEW IDENTIFIER
707                         LPAREN argument_list_opt RPAREN
708         |       name DOT NEW IDENTIFIER
709                         LPAREN argument_list_opt RPAREN class_body
710         ;
711 argument_list_opt ::=
712         |       argument_list
713         ;
714 argument_list ::=
715                 expression
716         |       argument_list COMMA expression
717         ;
718 array_creation_uninit ::=
719                 NEW primitive_type dim_exprs dims_opt
720         |       NEW class_or_interface_type dim_exprs dims_opt
721         ;
722 array_creation_init ::=
723                 NEW primitive_type dims array_initializer
724         |       NEW class_or_interface_type dims array_initializer
725         ;
726 dim_exprs ::=   dim_expr
727         |       dim_exprs dim_expr
728         ;
729 dim_expr ::=    LBRACK expression RBRACK
730         ;
731 dims_opt ::=
732         |       dims
733         ;
734 dims ::=        LBRACK RBRACK
735         |       dims LBRACK RBRACK
736         ;
737 field_access ::=
738                 primary DOT IDENTIFIER
739         |       SUPER DOT IDENTIFIER
740         |       name DOT SUPER DOT IDENTIFIER
741         ;
742 method_invocation ::=
743                 name LPAREN argument_list_opt RPAREN
744         |       primary DOT IDENTIFIER LPAREN argument_list_opt RPAREN
745         |       SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
746         |       name DOT SUPER DOT IDENTIFIER LPAREN argument_list_opt RPAREN
747         ;
748 array_access ::=
749                 name LBRACK expression RBRACK
750         |       primary_no_new_array LBRACK expression RBRACK
751         |       array_creation_init LBRACK expression RBRACK
752         ;
753 postfix_expression ::=
754                 primary
755         |       name
756         |       postincrement_expression
757         |       postdecrement_expression
758         ;
759 postincrement_expression ::=
760                 postfix_expression PLUSPLUS
761         ;
762 postdecrement_expression ::=
763                 postfix_expression MINUSMINUS
764         ;
765 unary_expression ::=
766                 preincrement_expression
767         |       predecrement_expression
768         |       PLUS unary_expression
769         |       MINUS unary_expression
770         |       unary_expression_not_plus_minus
771         ;
772 preincrement_expression ::=
773                 PLUSPLUS unary_expression
774         ;
775 predecrement_expression ::=
776                 MINUSMINUS unary_expression
777         ;
778 unary_expression_not_plus_minus ::=
779                 postfix_expression
780         |       COMP unary_expression
781         |       NOT unary_expression
782         |       cast_expression
783         ;
784 cast_expression ::=
785                 LPAREN primitive_type dims_opt RPAREN unary_expression
786         |       LPAREN expression RPAREN unary_expression_not_plus_minus
787         |       LPAREN name dims RPAREN unary_expression_not_plus_minus
788         ;
789 multiplicative_expression ::=
790                 unary_expression
791         |       multiplicative_expression MULT unary_expression
792         |       multiplicative_expression DIV unary_expression
793         |       multiplicative_expression MOD unary_expression
794         ;
795 additive_expression ::=
796                 multiplicative_expression
797         |       additive_expression PLUS multiplicative_expression
798         |       additive_expression MINUS multiplicative_expression
799         ;
800 shift_expression ::=
801                 additive_expression
802         |       shift_expression LSHIFT additive_expression
803         |       shift_expression RSHIFT additive_expression
804         |       shift_expression URSHIFT additive_expression
805         ;
806 relational_expression ::=
807                 shift_expression
808         |       relational_expression LT shift_expression
809         |       relational_expression GT shift_expression
810         |       relational_expression LTEQ shift_expression
811         |       relational_expression GTEQ shift_expression
812         |       relational_expression INSTANCEOF reference_type
813         ;
814 equality_expression ::=
815                 relational_expression
816         |       equality_expression EQEQ relational_expression
817         |       equality_expression NOTEQ relational_expression
818         ;
819 and_expression ::=
820                 equality_expression
821         |       and_expression AND equality_expression
822         ;
823 exclusive_or_expression ::=
824                 and_expression
825         |       exclusive_or_expression XOR and_expression
826         ;
827 inclusive_or_expression ::=
828                 exclusive_or_expression
829         |       inclusive_or_expression OR exclusive_or_expression
830         ;
831 conditional_and_expression ::=
832                 inclusive_or_expression
833         |       conditional_and_expression ANDAND inclusive_or_expression
834         ;
835 conditional_or_expression ::=
836                 conditional_and_expression
837         |       conditional_or_expression OROR conditional_and_expression
838         ;
839 conditional_expression ::=
840                 conditional_or_expression
841         |       conditional_or_expression QUESTION expression 
842                         COLON conditional_expression
843         ;
844 assignment_expression ::=
845                 conditional_expression
846         |       assignment
847         ;
848 // semantic check necessary here to ensure a valid left-hand side.
849 // allowing a parenthesized variable here on the lhs was introduced in
850 // JLS 2; thanks to Eric Blake for pointing this out.
851 assignment ::=  postfix_expression assignment_operator assignment_expression
852         ;
853 assignment_operator ::=
854                 EQ
855         |       MULTEQ
856         |       DIVEQ
857         |       MODEQ
858         |       PLUSEQ
859         |       MINUSEQ
860         |       LSHIFTEQ
861         |       RSHIFTEQ
862         |       URSHIFTEQ
863         |       ANDEQ
864         |       XOREQ
865         |       OREQ
866         ;
867 expression_opt ::=
868         |       expression
869         ;
870 expression ::=  assignment_expression
871         ;
872 constant_expression ::=
873                 expression
874         ;