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