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