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