-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathparser.cup
More file actions
1408 lines (1355 loc) · 49.5 KB
/
parser.cup
File metadata and controls
1408 lines (1355 loc) · 49.5 KB
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
// vim:syntax=yacc
/* Java 1.4 parser for CUP.
* Copyright (C) 2002 C. Scott Ananian <cananian@alumni.princeton.edu>
* This program is released under the terms of the GPL; see the file
* COPYING for more details. There is NO WARRANTY on this code.
*/
/**
* Modifications:
*
* This grammar has been modified to suit the purposes of the LBJ programming
* framework, which requires only the syntax of method bodies in addition to
* its novel syntax elements. In particular, references to the following
* declarations were removed:
* - class declarations
* - interface declarations
* - field declarations
* - constructor declarations
* This means that classes and interfaces may not be declared within method
* bodies, and anonymous classes cannot be instantiated.
*
* Modified by Christos Christodoulopoulos to be used inside Maven
**/
package edu.illinois.cs.cogcomp.lbjava.frontend;
import java.util.LinkedList;
import edu.illinois.cs.cogcomp.lbjava.IR.*;
parser code
{:
public void syntax_error(java_cup.runtime.Symbol current)
{
if (current.value != null)
{
TokenValue t = (TokenValue) current.value;
report_error("Syntax error in line " + (t.line + 1) + " near \""
+ t + "\".", current);
}
else report_error("Syntax error: " + current, current);
}
:}
terminal TokenValue
ABSTRACT, ALPHA, AND, ANDAND, ANDEQ, ARROW, ASSERT, AT, ATLEAST, ATMOST,
BANGCOLON, BITWISE_NOT, BOOLEAN, BREAK, BYTE, CACHED, CACHEDIN, CACHEDINMAP,
CASE, CATCH, CHAR, CLASS, COLON, COLONCOLON, COMMA, CONJUNCTION, CONST,
CONSTRAINT, CONTINUE, CVAL, DEFAULT, DISCRETE, DISJUNCTION, DIVEQ, DIVIDE,
DO, DOT, DOTDOT, DOUBLE, DOUBLEIMPLICATION, ELSE, ENCODING, END, EQ, EQEQ,
EVALUATE, EXISTS, EXTENDS, FINAL, FINALLY, FLOAT, FOR, FORALL, FROM, GOTO,
GT, GTEQ, HEAD, IDENTIFIER, IF, IMPLEMENTS, IMPLICATION, IMPORT, IN,
INFERENCE, INSTANCEOF, INT, INTERFACE, JAVADOC_COMMENT, JAVADOC_END_COMMENT,
LBRACE, LBRACEBRACE, LBRACK, LEARN, LITERAL, LONG, LPAREN, LSHIFT, LSHIFTEQ,
LT, LTEQ, MAXIMIZE, MINIMIZE, MINUS, MINUSEQ, MINUSMINUS, MIXED, MOD, MODEQ,
MULTEQ, NATIVE, NEW, NORMALIZEDBY, NOT, NOTEQ, OF, OR, OREQ, OROR, PACKAGE,
PLUS, PLUSEQ, PLUSPLUS, PREEXTRACT, PRIVATE, PROGRESSOUTPUT, PROTECTED,
PRUNE, PUBLIC, QUESTION, RARROW, RBRACE, RBRACEBRACE, RBRACK, REAL, RETURN,
ROUNDS, RPAREN, RSHIFT, RSHIFTEQ, SEMICOLON, SENSE, SENSEALL, SHORT, STATIC,
SUBJECTTO, SUPER, SWITCH, SYNCHRONIZED, TESTFROM, TESTINGMETRIC, THIS,
THROW, THROWS, TIMES, TRANSIENT, TRY, URSHIFT, URSHIFTEQ, USING, VOID,
VOLATILE, WHILE, WITH, XOR, XOREQ;
nonterminal AST program;
nonterminal ArrayType array_type;
nonterminal Integer dims;
nonterminal ImportDeclaration import_declaration;
nonterminal ImportList import_list;
nonterminal DeclarationList declaration_list;
nonterminal Constant literal;
nonterminal ConstantList literals;
nonterminal Name name;
nonterminal PackageDeclaration package_declaration;
nonterminal PrimitiveType primitive_type;
nonterminal Type reference_type;
nonterminal Type type;
nonterminal ClassifierExpression
classifier_atom, classifier_cast_expression, learner,
classifier_and_expression, classifier_expression;
nonterminal LinkedList learner_clauses;
nonterminal LearningClassifierExpression.Clause learner_clause;
nonterminal ClassifierAssignment classifier_assignment;
nonterminal Declaration declaration;
nonterminal VariableDeclaration variable_declarators, variable_declarator;
nonterminal Name variable_declarator_id;
nonterminal Expression variable_initializer;
nonterminal ArrayInitializer array_initializer;
nonterminal ExpressionList variable_initializers;
nonterminal Argument formal_parameter;
nonterminal Block block;
nonterminal StatementList block_statements;
nonterminal Statement block_statement;
nonterminal VariableDeclaration local_variable_declaration_statement,
local_variable_declaration;
nonterminal EmptyStatement empty_statement;
nonterminal LabeledStatement labeled_statement, labeled_statement_no_short_if;
nonterminal Statement statement, statement_no_short_if,
statement_without_trailing_substatement;
nonterminal ExpressionStatement expression_statement;
nonterminal StatementExpression statement_expression;
nonterminal ExpressionList statement_expression_list;
nonterminal Operator assignment_operator;
nonterminal ExpressionList argument_list, dim_exprs;
nonterminal Expression primary, primary_no_new_array, dim_expr;
nonterminal InstanceCreationExpression class_instance_creation_expression;
nonterminal ArrayCreationExpression array_creation_expression;
nonterminal FieldAccess field_access;
nonterminal MethodInvocation method_invocation;
nonterminal SubscriptVariable array_access;
nonterminal Expression expression, postfix_expression, left_hand_side;
nonterminal IncrementExpression
preincrement_expression, predecrement_expression,
postincrement_expression, postdecrement_expression;
nonterminal Expression unary_expression, unary_expression_not_plus_minus;
nonterminal CastExpression cast_expression;
nonterminal ExpressionList for_update;
nonterminal ForStatement for_statement, for_statement_no_short_if;
nonterminal Assignment assignment;
nonterminal BreakStatement break_statement;
nonterminal ContinueStatement continue_statement;
nonterminal ReturnStatement return_statement;
nonterminal SenseStatement sense_statement;
nonterminal ThrowStatement throw_statement;
nonterminal CatchList catches;
nonterminal CatchClause catch_clause;
nonterminal AssertStatement assert_statement;
nonterminal SynchronizedStatement synchronized_statement;
nonterminal TryStatement try_statement;
nonterminal Expression multiplicative_expression, additive_expression,
shift_expression, relational_expression,
equality_expression, and_expression,
exclusive_or_expression, inclusive_or_expression,
conditional_and_expression, conditional_or_expression,
conditional_expression;
nonterminal IfStatement if_then_statement, if_then_else_statement,
if_then_else_statement_no_short_if;
nonterminal SwitchLabel switch_label;
nonterminal SwitchLabelList switch_labels;
nonterminal SwitchStatement switch_statement;
nonterminal SwitchBlock switch_block;
nonterminal SwitchGroupList switch_block_statement_groups;
nonterminal SwitchGroup switch_block_statement_group;
nonterminal WhileStatement while_statement, while_statement_no_short_if;
nonterminal DoStatement do_statement;
nonterminal ClassifierReturnType classifier_return_type;
nonterminal ConstraintDeclaration constraint_declaration;
nonterminal InferenceDeclaration inference_declaration;
nonterminal InferenceDeclaration.Clause inference_clause;
nonterminal LinkedList inference_clauses;
nonterminal ConstraintExpression
constraint_expression, double_implication_expression,
implication_expression, disjunction_expression,
conjunction_expression, logic_atom;
nonterminal ParameterSet parameter_set;
start with program;
program ::= package_declaration:p import_list:l declaration_list:d
{:
RESULT = new AST(p, l, d);
:}
| import_list:l declaration_list:d {: RESULT = new AST(l, d); :}
| package_declaration:p declaration_list:d
{:
RESULT = new AST(p, d);
:}
| declaration_list:d {: RESULT = new AST(d); :}
;
package_declaration ::= PACKAGE:p name:n SEMICOLON
{:
RESULT = new PackageDeclaration(n, p.line, p.byteOffset);
:}
;
import_list ::= import_declaration:i {: RESULT = new ImportList(i); :}
| import_list:l import_declaration:i
{:
l.add(i);
RESULT = l;
:}
;
import_declaration ::= IMPORT:i name:n SEMICOLON
{:
RESULT = new ImportDeclaration(n, i.line, i.byteOffset);
:}
| IMPORT:i name:n DOT TIMES SEMICOLON
{:
RESULT =
new ImportDeclaration(new Name(n + ".*", n.line, n.byteOffset),
i.line, i.byteOffset);
:}
;
declaration_list ::= declaration:d {: RESULT = new DeclarationList(d); :}
| JAVADOC_COMMENT:c JAVADOC_END_COMMENT:e declaration:d
{:
d.comment = "/**" + c.text + e.text;
RESULT = new DeclarationList(d);
:}
| declaration_list:l declaration:d
{:
l.add(d);
RESULT = l;
:}
| declaration_list:l JAVADOC_COMMENT:c JAVADOC_END_COMMENT:e declaration:d
{:
d.comment = "/**" + c.text + e.text;
l.add(d);
RESULT = l;
:}
;
declaration ::= classifier_assignment:a {: RESULT = a; :}
| constraint_declaration:c {: RESULT = c; :}
| inference_declaration:i {: RESULT = i; :}
;
classifier_assignment ::= classifier_return_type:r IDENTIFIER:i LPAREN
formal_parameter:f RPAREN ARROW classifier_expression:e
{: RESULT = new ClassifierAssignment(r, i, f, e); :}
| classifier_return_type:r IDENTIFIER:i LPAREN formal_parameter:f RPAREN
CACHED ARROW classifier_expression:e
{: RESULT = new ClassifierAssignment(r, i, f, e, true); :}
| classifier_return_type:r IDENTIFIER:i LPAREN formal_parameter:f RPAREN
CACHEDIN name:n ARROW classifier_expression:e
{: RESULT = new ClassifierAssignment(r, i, f, e, n); :}
| classifier_return_type:r IDENTIFIER:i LPAREN formal_parameter:f RPAREN
CACHEDINMAP ARROW classifier_expression:e
{:
RESULT =
new ClassifierAssignment(r, i, f, e,
new Name(ClassifierAssignment.mapCache));
:}
| classifier_return_type:r IDENTIFIER:i LPAREN formal_parameter:f RPAREN
CACHED CACHEDIN name:n ARROW classifier_expression:e
{: RESULT = new ClassifierAssignment(r, i, f, e, n, true); :}
| classifier_return_type:r IDENTIFIER:i LPAREN formal_parameter:f RPAREN
CACHED CACHEDINMAP ARROW classifier_expression:e
{:
RESULT =
new ClassifierAssignment(r, i, f, e,
new Name(ClassifierAssignment.mapCache),
true);
:}
| classifier_return_type:r IDENTIFIER:i LPAREN formal_parameter:f RPAREN
CACHEDIN name:n CACHED ARROW classifier_expression:e
{: RESULT = new ClassifierAssignment(r, i, f, e, n, true); :}
| classifier_return_type:r IDENTIFIER:i LPAREN formal_parameter:f RPAREN
CACHEDINMAP CACHED ARROW classifier_expression:e
{:
RESULT =
new ClassifierAssignment(r, i, f, e,
new Name(ClassifierAssignment.mapCache),
true);
:}
;
classifier_expression ::=
classifier_expression:e COMMA classifier_and_expression:a
{: RESULT = new CompositeGenerator(e, a); :}
| classifier_and_expression:a {: RESULT = a; :}
;
classifier_and_expression ::=
classifier_and_expression:e ANDAND:o classifier_cast_expression:c
{: RESULT = new Conjunction(e, c, o.line, o.byteOffset); :}
| classifier_cast_expression:c {: RESULT = c; :}
;
classifier_cast_expression ::=
LPAREN classifier_return_type:t RPAREN classifier_atom:e
{: RESULT = new ClassifierCastExpression(t, e); :}
| classifier_atom:e {: RESULT = e; :}
;
classifier_atom ::= name:n {: RESULT = new ClassifierName(n); :}
| learner:l {: RESULT = l; :}
| block:b {: RESULT = new CodedClassifier(b); :}
| name:i LPAREN name:n RPAREN {: RESULT = new InferenceInvocation(i, n); :}
| LPAREN classifier_expression:e RPAREN
{:
e.parenthesized = true;
RESULT = e;
:}
;
learner ::= LEARN:l learner_clauses:c END
{: RESULT = new LearningClassifierExpression(c, l.line, l.byteOffset); :}
| LEARN:l classifier_expression:t learner_clauses:c END
{:
RESULT = new LearningClassifierExpression(t, c, l.line, l.byteOffset);
:}
;
learner_clauses ::= learner_clauses:l learner_clause:c
{:
l.add(c);
RESULT = l;
:}
| learner_clause:c
{:
RESULT = new LinkedList();
RESULT.add(c);
:}
;
learner_clause ::= USING classifier_expression:e
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.USING, e);
:}
| FROM class_instance_creation_expression:c
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.FROM, c);
:}
| FROM class_instance_creation_expression:c expression:l ROUNDS
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.FROM, c, l);
:}
| WITH class_instance_creation_expression:c
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.WITH, c);
:}
| WITH name:n block:b
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.WITH, n, b);
:}
| ENCODING literal:e
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.ENCODING, e);
:}
| TESTFROM class_instance_creation_expression:c
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.TESTFROM, c);
:}
| EVALUATE expression:e
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.EVALUATE, e);
:}
| CVAL literal:k literal:s
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.CVAL, k, s);
:}
| CVAL literal:k
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.CVAL, k);
:}
| PREEXTRACT literal:s
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.PREEXTRACT, s);
:}
| PRUNE literal:x literal:y literal:z
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.PRUNE, x, y, z);
:}
| PROGRESSOUTPUT literal:n
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.PROGRESSOUTPUT, n);
:}
| TESTINGMETRIC class_instance_creation_expression:c
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.TESTINGMETRIC, c);
:}
| ALPHA literal:a
{:
RESULT =
new LearningClassifierExpression.Clause(
LearningClassifierExpression.Clause.ALPHA, a);
:}
;
classifier_return_type ::= DISCRETE:d
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.DISCRETE, d.line,
d.byteOffset);
:}
| DISCRETE:d LBRACE literals:l RBRACE
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.DISCRETE, l,
d.line, d.byteOffset);
:}
| REAL:r
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.REAL, r.line,
r.byteOffset);
:}
| MIXED:m
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.MIXED, m.line,
m.byteOffset);
:}
| DISCRETE:d LBRACK RBRACK
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.DISCRETE_ARRAY,
d.line, d.byteOffset);
:}
| DISCRETE:d LBRACE literals:l RBRACE LBRACK RBRACK
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.DISCRETE_ARRAY,
l, d.line, d.byteOffset);
:}
| REAL:r LBRACK RBRACK
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.REAL_ARRAY,
r.line, r.byteOffset);
:}
| MIXED:m LBRACK RBRACK
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.MIXED_ARRAY,
m.line, m.byteOffset);
:}
| DISCRETE:d MOD
{:
RESULT =
new ClassifierReturnType(ClassifierReturnType.DISCRETE_GENERATOR,
d.line, d.byteOffset);
:}
| DISCRETE:d LBRACE literals:l RBRACE MOD
{:
RESULT =
new ClassifierReturnType(ClassifierReturnType.DISCRETE_GENERATOR, l,
d.line, d.byteOffset);
:}
| REAL:r MOD
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.REAL_GENERATOR,
r.line, r.byteOffset);
:}
| MIXED:m MOD
{:
RESULT = new ClassifierReturnType(ClassifierReturnType.MIXED_GENERATOR,
m.line, m.byteOffset);
:}
;
constraint_declaration ::= CONSTRAINT:t IDENTIFIER:i LPAREN formal_parameter:p
RPAREN block:b
{: RESULT = new ConstraintDeclaration(t, i, p, b); :}
;
inference_declaration ::= INFERENCE:t IDENTIFIER:i HEAD formal_parameter:p
LBRACE inference_clauses:c RBRACE
{: RESULT = new InferenceDeclaration(t, i, p, c); :}
;
inference_clause ::= formal_parameter:p block:b
{:
RESULT =
new InferenceDeclaration.Clause(
InferenceDeclaration.Clause.HEAD_FINDER,
new InferenceDeclaration.HeadFinder(p, b));
:}
| SUBJECTTO block:b
{:
RESULT =
new InferenceDeclaration.Clause(
InferenceDeclaration.Clause.SUBJECTTO, b);
:}
| WITH class_instance_creation_expression:c
{:
RESULT =
new InferenceDeclaration.Clause(InferenceDeclaration.Clause.WITH, c);
:}
| NORMALIZEDBY:t class_instance_creation_expression:c
{:
RESULT =
new InferenceDeclaration.Clause(
InferenceDeclaration.Clause.NORMALIZER_DECLARATION,
new InferenceDeclaration.NormalizerDeclaration(t, null, c));
:}
| name:n NORMALIZEDBY:t class_instance_creation_expression:c
{:
RESULT =
new InferenceDeclaration.Clause(
InferenceDeclaration.Clause.NORMALIZER_DECLARATION,
new InferenceDeclaration.NormalizerDeclaration(t, n, c));
:}
;
inference_clauses ::= inference_clause:l
{:
RESULT = new LinkedList();
RESULT.add(l);
:}
| inference_clauses:list inference_clause:l
{:
list.add(l);
RESULT = list;
:}
;
constraint_expression ::= double_implication_expression:e {: RESULT = e; :}
| FORALL:t LPAREN formal_parameter:p IN expression:c RPAREN
constraint_expression:e
{: RESULT = new UniversalQuantifierExpression(t, p, c, e); :}
| EXISTS:t LPAREN formal_parameter:p IN expression:c RPAREN
constraint_expression:e
{: RESULT = new ExistentialQuantifierExpression(t, p, c, e); :}
| ATLEAST:t expression:m OF LPAREN formal_parameter:p IN expression:c RPAREN
constraint_expression:e
{: RESULT = new AtLeastQuantifierExpression(t, m, p, c, e); :}
| ATMOST:t expression:m OF LPAREN formal_parameter:p IN expression:c RPAREN
constraint_expression:e
{: RESULT = new AtMostQuantifierExpression(t, m, p, c, e); :}
;
double_implication_expression ::= implication_expression:e {: RESULT = e; :}
| double_implication_expression:e1 DOUBLEIMPLICATION:o
implication_expression:e2
{:
RESULT =
new BinaryConstraintExpression(
new Operator(Operator.DOUBLE_IMPLICATION, o.line, o.byteOffset),
e1, e2);
:}
;
implication_expression ::= disjunction_expression:e {: RESULT = e; :}
| implication_expression:e1 IMPLICATION:o disjunction_expression:e2
{:
RESULT =
new BinaryConstraintExpression(
new Operator(Operator.IMPLICATION, o.line, o.byteOffset),
e1, e2);
:}
;
disjunction_expression ::= conjunction_expression:e {: RESULT = e; :}
| disjunction_expression:e1 DISJUNCTION:o conjunction_expression:e2
{:
RESULT =
new BinaryConstraintExpression(
new Operator(Operator.LOGICAL_DISJUNCTION, o.line, o.byteOffset),
e1, e2);
:}
;
conjunction_expression ::= logic_atom:e {: RESULT = e; :}
| conjunction_expression:e1 CONJUNCTION:o logic_atom:e2
{:
RESULT =
new BinaryConstraintExpression(
new Operator(Operator.LOGICAL_CONJUNCTION, o.line, o.byteOffset),
e1, e2);
:}
;
logic_atom ::=
AT:t method_invocation:m {: RESULT = new ConstraintInvocation(t, m); :}
| expression:e1 COLONCOLON:o expression:e2
{:
RESULT =
new ConstraintEqualityExpression(
new Operator(Operator.CONSTRAINT_EQUAL, o.line, o.byteOffset),
e1, e2);
:}
| expression:e1 BANGCOLON:o expression:e2
{:
RESULT =
new ConstraintEqualityExpression(
new Operator(Operator.CONSTRAINT_NOT_EQUAL, o.line, o.byteOffset),
e1, e2);
:}
| LPAREN constraint_expression:e RPAREN
{:
e.parenthesized = true;
RESULT = e;
:}
| NOT:t LPAREN constraint_expression:e RPAREN
{:
e.parenthesized = true;
RESULT = new NegatedConstraintExpression(t, e);
:}
;
literal ::= LITERAL:l {: RESULT = new Constant(l); :}
;
literals ::= literal:l {: RESULT = new ConstantList(l); :}
| literals:list COMMA literal:l
{:
list.add(l);
RESULT = list;
:}
;
type ::= primitive_type:p {: RESULT = p; :}
| reference_type:r {: RESULT = r; :}
;
primitive_type ::= BOOLEAN:p
{:
RESULT = new PrimitiveType(PrimitiveType.BOOLEAN, p.line, p.byteOffset);
:}
| BYTE:p
{:
RESULT = new PrimitiveType(PrimitiveType.BYTE, p.line, p.byteOffset);
:}
| CHAR:p
{:
RESULT = new PrimitiveType(PrimitiveType.CHAR, p.line, p.byteOffset);
:}
| SHORT:p
{:
RESULT = new PrimitiveType(PrimitiveType.SHORT, p.line, p.byteOffset);
:}
| INT:p
{:
RESULT = new PrimitiveType(PrimitiveType.INT, p.line, p.byteOffset);
:}
| LONG:p
{:
RESULT = new PrimitiveType(PrimitiveType.LONG, p.line, p.byteOffset);
:}
| FLOAT:p
{:
RESULT = new PrimitiveType(PrimitiveType.FLOAT, p.line, p.byteOffset);
:}
| DOUBLE:p
{:
RESULT = new PrimitiveType(PrimitiveType.DOUBLE, p.line, p.byteOffset);
:}
;
reference_type ::= name:n {: RESULT = new ReferenceType(n); :}
| array_type:a {: RESULT = a; :}
;
array_type ::= primitive_type:p dims:d
{:
RESULT = new ArrayType(p);
for (int i = 1; i < d.intValue(); ++i)
RESULT = new ArrayType(RESULT);
:}
| name:n dims:d
{:
RESULT = new ArrayType(new ReferenceType(n));
for (int i = 1; i < d.intValue(); ++i)
RESULT = new ArrayType(RESULT);
:}
;
name ::= IDENTIFIER:i {: RESULT = new Name(i); :}
| name:n DOT IDENTIFIER:i {: RESULT = new Name(n, i); :}
;
variable_declarators ::= variable_declarator:d {: RESULT = d; :}
| variable_declarators:v COMMA variable_declarator:d
{:
v.addVariables(d);
RESULT = v;
:}
;
variable_declarator ::= variable_declarator_id:n
{: RESULT = new VariableDeclaration(n); :}
| variable_declarator_id:n EQ variable_initializer:i
{: RESULT = new VariableDeclaration(n, i); :}
;
variable_declarator_id ::= IDENTIFIER:i {: RESULT = new Name(i); :}
| variable_declarator_id:n LBRACK RBRACK
{:
++n.dimensions;
RESULT = n;
:}
;
variable_initializer ::= expression:e {: RESULT = e; :}
| array_initializer:a {: RESULT = a; :}
;
formal_parameter ::= type:t variable_declarator_id:n
{:
Type parameterType = t;
while (n.dimensions-- > 0) parameterType = new ArrayType(parameterType);
RESULT = new Argument(parameterType, "" + n);
:}
| FINAL type:t variable_declarator_id:n
{:
Type parameterType = t;
while (n.dimensions-- > 0) parameterType = new ArrayType(parameterType);
RESULT = new Argument(parameterType, "" + n, true);
:}
;
array_initializer ::= LBRACE:b variable_initializers:l COMMA RBRACE
{: RESULT = new ArrayInitializer(l, b.line, b.byteOffset); :}
| LBRACE:b variable_initializers:l RBRACE
{: RESULT = new ArrayInitializer(l, b.line, b.byteOffset); :}
| LBRACE:b COMMA RBRACE
{: RESULT = new ArrayInitializer(b.line, b.byteOffset); :}
| LBRACE:b RBRACE
{: RESULT = new ArrayInitializer(b.line, b.byteOffset); :}
;
variable_initializers ::= variable_initializer:i
{: RESULT = new ExpressionList(i); :}
| variable_initializers:l COMMA variable_initializer:i
{:
l.add(i);
RESULT = l;
:}
;
block ::= LBRACE:l RBRACE {: RESULT = new Block(l.line, l.byteOffset); :}
| LBRACE block_statements:s RBRACE {: RESULT = new Block(s); :}
;
block_statements ::= block_statement:s {: RESULT = new StatementList(s); :}
| block_statements:l block_statement:s
{:
l.add(s);
RESULT = l;
:}
;
block_statement ::= local_variable_declaration_statement:l {: RESULT = l; :}
| statement:s {: RESULT = s; :}
;
local_variable_declaration_statement ::=
local_variable_declaration:l SEMICOLON {: RESULT = l; :}
;
local_variable_declaration ::= type:t variable_declarators:v
{:
v.setType(t);
RESULT = v;
:}
| FINAL type:t variable_declarators:v
{:
v.setType(t);
v.isFinal = true;
RESULT = v;
:}
;
statement ::= statement_without_trailing_substatement:s {: RESULT = s; :}
| labeled_statement:s {: RESULT = s; :}
| if_then_statement:s {: RESULT = s; :}
| if_then_else_statement:s {: RESULT = s; :}
| while_statement:s {: RESULT = s; :}
| for_statement:s {: RESULT = s; :}
;
statement_no_short_if ::=
statement_without_trailing_substatement:s {: RESULT = s; :}
| labeled_statement_no_short_if:s {: RESULT = s; :}
| if_then_else_statement_no_short_if:s {: RESULT = s; :}
| while_statement_no_short_if:s {: RESULT = s; :}
| for_statement_no_short_if:s {: RESULT = s; :}
;
statement_without_trailing_substatement ::= block:s {: RESULT = s; :}
| empty_statement:s {: RESULT = s; :}
| expression_statement:s {: RESULT = s; :}
| switch_statement:s {: RESULT = s; :}
| do_statement:s {: RESULT = s; :}
| break_statement:s {: RESULT = s; :}
| continue_statement:s {: RESULT = s; :}
| return_statement:s {: RESULT = s; :}
| sense_statement:s {: RESULT = s; :}
| synchronized_statement:s {: RESULT = s; :}
| throw_statement:s {: RESULT = s; :}
| try_statement:s {: RESULT = s; :}
| assert_statement:s {: RESULT = s; :}
;
empty_statement ::=
SEMICOLON:s {: RESULT = new EmptyStatement(s.line, s.byteOffset); :}
;
labeled_statement ::= IDENTIFIER:i COLON statement:s
{: RESULT = new LabeledStatement(i, s); :}
;
labeled_statement_no_short_if ::= IDENTIFIER:i COLON statement_no_short_if:s
{: RESULT = new LabeledStatement(i, s); :}
;
expression_statement ::= statement_expression:e SEMICOLON
{: RESULT = new ExpressionStatement(e); :}
;
statement_expression ::= assignment:e {: RESULT = e; :}
| preincrement_expression:e {: RESULT = e; :}
| predecrement_expression:e {: RESULT = e; :}
| postincrement_expression:e {: RESULT = e; :}
| postdecrement_expression:e {: RESULT = e; :}
| method_invocation:e {: RESULT = e; :}
| class_instance_creation_expression:e {: RESULT = e; :}
| constraint_expression:e
{: RESULT = new ConstraintStatementExpression(e); :}
;
if_then_statement ::= IF:i LPAREN expression:e RPAREN statement:s
{: RESULT = new IfStatement(e, s, i.line, i.byteOffset); :}
;
if_then_else_statement ::=
IF:i LPAREN expression:e RPAREN statement_no_short_if:s1 ELSE statement:s2
{: RESULT = new IfStatement(e, s1, s2, i.line, i.byteOffset); :}
;
if_then_else_statement_no_short_if ::=
IF:i LPAREN expression:e RPAREN statement_no_short_if:s1
ELSE statement_no_short_if:s2
{: RESULT = new IfStatement(e, s1, s2, i.line, i.byteOffset); :}
;
switch_statement ::= SWITCH:s LPAREN expression:e RPAREN switch_block:b
{: RESULT = new SwitchStatement(e, b, s.line, s.byteOffset); :}
;
switch_block ::= LBRACE switch_block_statement_groups:g switch_labels:l RBRACE
{: RESULT = new SwitchBlock(g, l); :}
| LBRACE switch_block_statement_groups:g RBRACE
{: RESULT = new SwitchBlock(g); :}
| LBRACE switch_labels:l RBRACE {: RESULT = new SwitchBlock(l); :}
| LBRACE:l RBRACE {: RESULT = new SwitchBlock(l.line, l.byteOffset); :}
;
switch_block_statement_groups ::=
switch_block_statement_group:g {: RESULT = new SwitchGroupList(g); :}
| switch_block_statement_groups:l switch_block_statement_group:g
{:
l.add(g);
RESULT = l;
:}
;
switch_block_statement_group ::= switch_labels:l block_statements:s
{: RESULT = new SwitchGroup(l, s); :}
;
switch_labels ::= switch_label:s {: RESULT = new SwitchLabelList(s); :}
| switch_labels:l switch_label:s
{:
l.add(s);
RESULT = l;
:}
;
switch_label ::= CASE:c expression:e COLON
{: RESULT = new SwitchLabel(e, c.line, c.byteOffset); :}
| DEFAULT:d COLON
{: RESULT = new SwitchLabel(null, d.line, d.byteOffset); :}
;
while_statement ::= WHILE:w LPAREN expression:e RPAREN statement:s
{: RESULT = new WhileStatement(e, s, w.line, w.byteOffset); :}
;
while_statement_no_short_if ::=
WHILE:w LPAREN expression:e RPAREN statement_no_short_if:s
{: RESULT = new WhileStatement(e, s, w.line, w.byteOffset); :}
;
do_statement ::= DO:d statement:s WHILE LPAREN expression:e RPAREN SEMICOLON
{: RESULT = new DoStatement(s, e, d.line, d.byteOffset); :}
;
for_statement ::= FOR:f LPAREN SEMICOLON SEMICOLON RPAREN statement:s
{:
RESULT = new ForStatement((ExpressionList) null, null, null, s, f.line,
f.byteOffset);
:}
| FOR:f LPAREN SEMICOLON SEMICOLON for_update:u RPAREN statement:s
{:
RESULT = new ForStatement((ExpressionList) null, null, u, s, f.line,
f.byteOffset);
:}
| FOR:f LPAREN SEMICOLON expression:e SEMICOLON RPAREN statement:s
{:
RESULT = new ForStatement((ExpressionList) null, e, null, s, f.line,
f.byteOffset);
:}
| FOR:f LPAREN SEMICOLON expression:e SEMICOLON for_update:u RPAREN
statement:s
{:
RESULT = new ForStatement((ExpressionList) null, e, u, s, f.line,
f.byteOffset);
:}
| FOR:f LPAREN statement_expression_list:i SEMICOLON SEMICOLON RPAREN
statement:s
{: RESULT = new ForStatement(i, null, null, s, f.line, f.byteOffset); :}
| FOR:f LPAREN statement_expression_list:i SEMICOLON SEMICOLON for_update:u
RPAREN statement:s
{: RESULT = new ForStatement(i, null, u, s, f.line, f.byteOffset); :}
| FOR:f LPAREN statement_expression_list:i SEMICOLON expression:e SEMICOLON
RPAREN statement:s
{: RESULT = new ForStatement(i, e, null, s, f.line, f.byteOffset); :}
| FOR:f LPAREN statement_expression_list:i SEMICOLON expression:e SEMICOLON
for_update:u RPAREN statement:s
{: RESULT = new ForStatement(i, e, u, s, f.line, f.byteOffset); :}
| FOR:f LPAREN local_variable_declaration:v SEMICOLON SEMICOLON RPAREN
statement:s
{: RESULT = new ForStatement(v, null, null, s, f.line, f.byteOffset); :}
| FOR:f LPAREN local_variable_declaration:v SEMICOLON SEMICOLON for_update:u
RPAREN statement:s
{: RESULT = new ForStatement(v, null, u, s, f.line, f.byteOffset); :}
| FOR:f LPAREN local_variable_declaration:v SEMICOLON expression:e SEMICOLON
RPAREN statement:s
{: RESULT = new ForStatement(v, e, null, s, f.line, f.byteOffset); :}
| FOR:f LPAREN local_variable_declaration:v SEMICOLON expression:e SEMICOLON
for_update:u RPAREN statement:s
{: RESULT = new ForStatement(v, e, u, s, f.line, f.byteOffset); :}
;
for_statement_no_short_if ::=
FOR:f LPAREN SEMICOLON SEMICOLON RPAREN statement_no_short_if:s
{:
RESULT = new ForStatement((ExpressionList) null, null, null, s, f.line,
f.byteOffset);
:}
| FOR:f LPAREN SEMICOLON SEMICOLON for_update:u RPAREN
statement_no_short_if:s
{:
RESULT = new ForStatement((ExpressionList) null, null, u, s, f.line,
f.byteOffset);
:}
| FOR:f LPAREN SEMICOLON expression:e SEMICOLON RPAREN
statement_no_short_if:s
{:
RESULT = new ForStatement((ExpressionList) null, e, null, s, f.line,
f.byteOffset);
:}
| FOR:f LPAREN SEMICOLON expression:e SEMICOLON for_update:u RPAREN
statement_no_short_if:s
{:
RESULT = new ForStatement((ExpressionList) null, e, u, s, f.line,
f.byteOffset);
:}
| FOR:f LPAREN statement_expression_list:i SEMICOLON SEMICOLON RPAREN
statement_no_short_if:s
{: RESULT = new ForStatement(i, null, null, s, f.line, f.byteOffset); :}
| FOR:f LPAREN statement_expression_list:i SEMICOLON SEMICOLON for_update:u
RPAREN statement_no_short_if:s
{: RESULT = new ForStatement(i, null, u, s, f.line, f.byteOffset); :}
| FOR:f LPAREN statement_expression_list:i SEMICOLON expression:e SEMICOLON
RPAREN statement_no_short_if:s
{: RESULT = new ForStatement(i, e, null, s, f.line, f.byteOffset); :}
| FOR:f LPAREN statement_expression_list:i SEMICOLON expression:e SEMICOLON
for_update:u RPAREN statement_no_short_if:s
{: RESULT = new ForStatement(i, e, u, s, f.line, f.byteOffset); :}
| FOR:f LPAREN local_variable_declaration:v SEMICOLON SEMICOLON RPAREN
statement_no_short_if:s
{: RESULT = new ForStatement(v, null, null, s, f.line, f.byteOffset); :}
| FOR:f LPAREN local_variable_declaration:v SEMICOLON SEMICOLON for_update:u
RPAREN statement_no_short_if:s
{: RESULT = new ForStatement(v, null, u, s, f.line, f.byteOffset); :}
| FOR:f LPAREN local_variable_declaration:v SEMICOLON expression:e SEMICOLON
RPAREN statement_no_short_if:s
{: RESULT = new ForStatement(v, e, null, s, f.line, f.byteOffset); :}
| FOR:f LPAREN local_variable_declaration:v SEMICOLON expression:e SEMICOLON
for_update:u RPAREN statement_no_short_if:s
{: RESULT = new ForStatement(v, e, u, s, f.line, f.byteOffset); :}
;
for_update ::= statement_expression_list:l {: RESULT = l; :}
;
statement_expression_list ::= statement_expression:e
{: RESULT = new ExpressionList(e); :}
| statement_expression_list:l COMMA statement_expression:e
{:
l.add(e);
RESULT = l;
:}
;
break_statement ::= BREAK:b SEMICOLON
{: RESULT = new BreakStatement(null, b.line, b.byteOffset); :}
| BREAK:b IDENTIFIER:i SEMICOLON
{: RESULT = new BreakStatement("" + i, b.line, b.byteOffset); :}
;
continue_statement ::= CONTINUE:c SEMICOLON
{: RESULT = new ContinueStatement(null, c.line, c.byteOffset); :}
| CONTINUE:c IDENTIFIER:i SEMICOLON
{: RESULT = new ContinueStatement("" + i, c.line, c.byteOffset); :}
;
return_statement ::= RETURN:r expression:e SEMICOLON
{: RESULT = new ReturnStatement(e, r.line, r.byteOffset); :}
;
sense_statement ::= SENSE:s expression:e SEMICOLON
{: RESULT = new SenseStatement(e, s.line, s.byteOffset); :}
| SENSE:s expression:e1 COLON expression:e2 SEMICOLON
{: RESULT = new SenseStatement(e1, e2, s.line, s.byteOffset); :}
| SENSEALL:s expression:e SEMICOLON
{: RESULT = new SenseStatement(e, true, s.line, s.byteOffset); :}
;
throw_statement ::= THROW:t expression:e SEMICOLON
{: RESULT = new ThrowStatement(e, t.line, t.byteOffset); :}
;
synchronized_statement ::= SYNCHRONIZED:s LPAREN expression:e RPAREN block:b
{: RESULT = new SynchronizedStatement(e, b, s.line, s.byteOffset); :}