-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTigerLLKParser.java
More file actions
3193 lines (3085 loc) · 96 KB
/
TigerLLKParser.java
File metadata and controls
3193 lines (3085 loc) · 96 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
// Generated from TigerLLK.g4 by ANTLR 4.7.1
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class TigerLLKParser extends Parser {
static { RuntimeMetaData.checkVersion("4.7.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
INT=1, FLOAT=2, MAIN=3, COMMA=4, COLON=5, SEMI=6, LPAREN=7, RPAREN=8,
LBRACK=9, RBRACK=10, LBRACE=11, RBRACE=12, PERIOD=13, PLUS=14, MINUS=15,
MULT=16, DIV=17, EXP=18, EQ=19, NEQ=20, LESSER=21, GREATER=22, LESSEREQ=23,
GREATEREQ=24, AND=25, OR=26, ASSIGN=27, ARRAY=28, RECORD=29, BREAK=30,
DO=31, ELSE=32, FOR=33, FUNC=34, IF=35, IN=36, LET=37, OF=38, THEN=39,
TO=40, TYPE=41, VAR=42, WHILE=43, ENDIF=44, BEGIN=45, ENDDO=46, END=47,
RETURN=48, COMMENT=49, LINE_COMMENT=50, INTLIT=51, FLOATLIT=52, ID=53,
WS=54;
public static final int
RULE_hello = 0, RULE_tigerprogram = 1, RULE_declarationsegment = 2, RULE_typedeclarationlist = 3,
RULE_vardeclarationlist = 4, RULE_functdeclarationlist = 5, RULE_typedeclaration = 6,
RULE_type = 7, RULE_fieldlist = 8, RULE_typeid = 9, RULE_vardeclaration = 10,
RULE_idlist = 11, RULE_itail = 12, RULE_optionalinit = 13, RULE_functdeclaration = 14,
RULE_paramlist = 15, RULE_paramlisttail = 16, RULE_rettype = 17, RULE_param = 18,
RULE_statseq = 19, RULE_stail = 20, RULE_stat = 21, RULE_statail = 22,
RULE_more = 23, RULE_ltail = 24, RULE_expr = 25, RULE_and = 26, RULE_le = 27,
RULE_me = 28, RULE_lesser = 29, RULE_greater = 30, RULE_noteq = 31, RULE_equal = 32,
RULE_minus = 33, RULE_plus = 34, RULE_div = 35, RULE_mult = 36, RULE_exp = 37,
RULE_yeet = 38, RULE_consta = 39, RULE_exprlist = 40, RULE_exprlisttail = 41,
RULE_lvalue = 42, RULE_lvaluetail = 43;
public static final String[] ruleNames = {
"hello", "tigerprogram", "declarationsegment", "typedeclarationlist",
"vardeclarationlist", "functdeclarationlist", "typedeclaration", "type",
"fieldlist", "typeid", "vardeclaration", "idlist", "itail", "optionalinit",
"functdeclaration", "paramlist", "paramlisttail", "rettype", "param",
"statseq", "stail", "stat", "statail", "more", "ltail", "expr", "and",
"le", "me", "lesser", "greater", "noteq", "equal", "minus", "plus", "div",
"mult", "exp", "yeet", "consta", "exprlist", "exprlisttail", "lvalue",
"lvaluetail"
};
private static final String[] _LITERAL_NAMES = {
null, "'int'", "'float'", "'main'", "','", "':'", "';'", "'('", "')'",
"'['", "']'", "'{'", "'}'", "'.'", "'+'", "'-'", "'*'", "'/'", "'**'",
"'='", "'<>'", "'<'", "'>'", "'<='", "'>='", "'&'", "'|'", "':='", "'array'",
"'record'", "'break'", "'do'", "'else'", "'for'", "'function'", "'if'",
"'in'", "'let'", "'of'", "'then'", "'to'", "'type'", "'var'", "'while'",
"'endif'", "'begin'", "'enddo'", "'end'", "'return'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, "INT", "FLOAT", "MAIN", "COMMA", "COLON", "SEMI", "LPAREN", "RPAREN",
"LBRACK", "RBRACK", "LBRACE", "RBRACE", "PERIOD", "PLUS", "MINUS", "MULT",
"DIV", "EXP", "EQ", "NEQ", "LESSER", "GREATER", "LESSEREQ", "GREATEREQ",
"AND", "OR", "ASSIGN", "ARRAY", "RECORD", "BREAK", "DO", "ELSE", "FOR",
"FUNC", "IF", "IN", "LET", "OF", "THEN", "TO", "TYPE", "VAR", "WHILE",
"ENDIF", "BEGIN", "ENDDO", "END", "RETURN", "COMMENT", "LINE_COMMENT",
"INTLIT", "FLOATLIT", "ID", "WS"
};
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "TigerLLK.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public TigerLLKParser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
public static class HelloContext extends ParserRuleContext {
public TerminalNode PLUS() { return getToken(TigerLLKParser.PLUS, 0); }
public TerminalNode TYPE() { return getToken(TigerLLKParser.TYPE, 0); }
public TerminalNode VAR() { return getToken(TigerLLKParser.VAR, 0); }
public TerminalNode WHILE() { return getToken(TigerLLKParser.WHILE, 0); }
public TerminalNode END() { return getToken(TigerLLKParser.END, 0); }
public HelloContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_hello; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitHello(this);
else return visitor.visitChildren(this);
}
}
public final HelloContext hello() throws RecognitionException {
HelloContext _localctx = new HelloContext(_ctx, getState());
enterRule(_localctx, 0, RULE_hello);
try {
setState(96);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(88);
match(PLUS);
setState(89);
match(TYPE);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(90);
match(PLUS);
setState(91);
match(VAR);
}
break;
case 3:
enterOuterAlt(_localctx, 3);
{
setState(92);
match(PLUS);
setState(93);
match(WHILE);
}
break;
case 4:
enterOuterAlt(_localctx, 4);
{
setState(94);
match(PLUS);
setState(95);
match(END);
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class TigerprogramContext extends ParserRuleContext {
public TerminalNode MAIN() { return getToken(TigerLLKParser.MAIN, 0); }
public TerminalNode LET() { return getToken(TigerLLKParser.LET, 0); }
public DeclarationsegmentContext declarationsegment() {
return getRuleContext(DeclarationsegmentContext.class,0);
}
public TerminalNode IN() { return getToken(TigerLLKParser.IN, 0); }
public TerminalNode BEGIN() { return getToken(TigerLLKParser.BEGIN, 0); }
public StatseqContext statseq() {
return getRuleContext(StatseqContext.class,0);
}
public TerminalNode END() { return getToken(TigerLLKParser.END, 0); }
public TigerprogramContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_tigerprogram; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitTigerprogram(this);
else return visitor.visitChildren(this);
}
}
public final TigerprogramContext tigerprogram() throws RecognitionException {
TigerprogramContext _localctx = new TigerprogramContext(_ctx, getState());
enterRule(_localctx, 2, RULE_tigerprogram);
try {
enterOuterAlt(_localctx, 1);
{
setState(98);
match(MAIN);
setState(99);
match(LET);
setState(100);
declarationsegment();
setState(101);
match(IN);
setState(102);
match(BEGIN);
setState(103);
statseq();
setState(104);
match(END);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class DeclarationsegmentContext extends ParserRuleContext {
public TypedeclarationlistContext typedeclarationlist() {
return getRuleContext(TypedeclarationlistContext.class,0);
}
public VardeclarationlistContext vardeclarationlist() {
return getRuleContext(VardeclarationlistContext.class,0);
}
public FunctdeclarationlistContext functdeclarationlist() {
return getRuleContext(FunctdeclarationlistContext.class,0);
}
public DeclarationsegmentContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_declarationsegment; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitDeclarationsegment(this);
else return visitor.visitChildren(this);
}
}
public final DeclarationsegmentContext declarationsegment() throws RecognitionException {
DeclarationsegmentContext _localctx = new DeclarationsegmentContext(_ctx, getState());
enterRule(_localctx, 4, RULE_declarationsegment);
try {
enterOuterAlt(_localctx, 1);
{
setState(106);
typedeclarationlist();
setState(107);
vardeclarationlist();
setState(108);
functdeclarationlist();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class TypedeclarationlistContext extends ParserRuleContext {
public TypedeclarationContext typedeclaration() {
return getRuleContext(TypedeclarationContext.class,0);
}
public TypedeclarationlistContext typedeclarationlist() {
return getRuleContext(TypedeclarationlistContext.class,0);
}
public TypedeclarationlistContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_typedeclarationlist; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitTypedeclarationlist(this);
else return visitor.visitChildren(this);
}
}
public final TypedeclarationlistContext typedeclarationlist() throws RecognitionException {
TypedeclarationlistContext _localctx = new TypedeclarationlistContext(_ctx, getState());
enterRule(_localctx, 6, RULE_typedeclarationlist);
try {
setState(114);
_errHandler.sync(this);
switch (_input.LA(1)) {
case TYPE:
enterOuterAlt(_localctx, 1);
{
setState(110);
typedeclaration();
setState(111);
typedeclarationlist();
}
break;
case FUNC:
case IN:
case VAR:
enterOuterAlt(_localctx, 2);
{
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class VardeclarationlistContext extends ParserRuleContext {
public VardeclarationContext vardeclaration() {
return getRuleContext(VardeclarationContext.class,0);
}
public VardeclarationlistContext vardeclarationlist() {
return getRuleContext(VardeclarationlistContext.class,0);
}
public VardeclarationlistContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_vardeclarationlist; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitVardeclarationlist(this);
else return visitor.visitChildren(this);
}
}
public final VardeclarationlistContext vardeclarationlist() throws RecognitionException {
VardeclarationlistContext _localctx = new VardeclarationlistContext(_ctx, getState());
enterRule(_localctx, 8, RULE_vardeclarationlist);
try {
setState(120);
_errHandler.sync(this);
switch (_input.LA(1)) {
case VAR:
enterOuterAlt(_localctx, 1);
{
setState(116);
vardeclaration();
setState(117);
vardeclarationlist();
}
break;
case FUNC:
case IN:
enterOuterAlt(_localctx, 2);
{
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class FunctdeclarationlistContext extends ParserRuleContext {
public FunctdeclarationContext functdeclaration() {
return getRuleContext(FunctdeclarationContext.class,0);
}
public FunctdeclarationlistContext functdeclarationlist() {
return getRuleContext(FunctdeclarationlistContext.class,0);
}
public FunctdeclarationlistContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_functdeclarationlist; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitFunctdeclarationlist(this);
else return visitor.visitChildren(this);
}
}
public final FunctdeclarationlistContext functdeclarationlist() throws RecognitionException {
FunctdeclarationlistContext _localctx = new FunctdeclarationlistContext(_ctx, getState());
enterRule(_localctx, 10, RULE_functdeclarationlist);
try {
setState(126);
_errHandler.sync(this);
switch (_input.LA(1)) {
case FUNC:
enterOuterAlt(_localctx, 1);
{
setState(122);
functdeclaration();
setState(123);
functdeclarationlist();
}
break;
case IN:
enterOuterAlt(_localctx, 2);
{
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class TypedeclarationContext extends ParserRuleContext {
public TerminalNode TYPE() { return getToken(TigerLLKParser.TYPE, 0); }
public TerminalNode ID() { return getToken(TigerLLKParser.ID, 0); }
public TerminalNode EQ() { return getToken(TigerLLKParser.EQ, 0); }
public TypeContext type() {
return getRuleContext(TypeContext.class,0);
}
public TerminalNode SEMI() { return getToken(TigerLLKParser.SEMI, 0); }
public TypedeclarationContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_typedeclaration; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitTypedeclaration(this);
else return visitor.visitChildren(this);
}
}
public final TypedeclarationContext typedeclaration() throws RecognitionException {
TypedeclarationContext _localctx = new TypedeclarationContext(_ctx, getState());
enterRule(_localctx, 12, RULE_typedeclaration);
try {
enterOuterAlt(_localctx, 1);
{
setState(128);
match(TYPE);
setState(129);
match(ID);
setState(130);
match(EQ);
setState(131);
type();
setState(132);
match(SEMI);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class TypeContext extends ParserRuleContext {
public TypeContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_type; }
public TypeContext() { }
public void copyFrom(TypeContext ctx) {
super.copyFrom(ctx);
}
}
public static class ArrayTypeContext extends TypeContext {
public TerminalNode ARRAY() { return getToken(TigerLLKParser.ARRAY, 0); }
public TerminalNode LBRACK() { return getToken(TigerLLKParser.LBRACK, 0); }
public TerminalNode INTLIT() { return getToken(TigerLLKParser.INTLIT, 0); }
public TerminalNode RBRACK() { return getToken(TigerLLKParser.RBRACK, 0); }
public TerminalNode OF() { return getToken(TigerLLKParser.OF, 0); }
public TypeidContext typeid() {
return getRuleContext(TypeidContext.class,0);
}
public ArrayTypeContext(TypeContext ctx) { copyFrom(ctx); }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitArrayType(this);
else return visitor.visitChildren(this);
}
}
public static class IDtypeContext extends TypeContext {
public TypeidContext typeid() {
return getRuleContext(TypeidContext.class,0);
}
public IDtypeContext(TypeContext ctx) { copyFrom(ctx); }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitIDtype(this);
else return visitor.visitChildren(this);
}
}
public static class PointerTypeContext extends TypeContext {
public TerminalNode ID() { return getToken(TigerLLKParser.ID, 0); }
public PointerTypeContext(TypeContext ctx) { copyFrom(ctx); }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitPointerType(this);
else return visitor.visitChildren(this);
}
}
public static class RecordTypeContext extends TypeContext {
public TerminalNode RECORD() { return getToken(TigerLLKParser.RECORD, 0); }
public FieldlistContext fieldlist() {
return getRuleContext(FieldlistContext.class,0);
}
public TerminalNode END() { return getToken(TigerLLKParser.END, 0); }
public RecordTypeContext(TypeContext ctx) { copyFrom(ctx); }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitRecordType(this);
else return visitor.visitChildren(this);
}
}
public final TypeContext type() throws RecognitionException {
TypeContext _localctx = new TypeContext(_ctx, getState());
enterRule(_localctx, 14, RULE_type);
try {
setState(146);
_errHandler.sync(this);
switch (_input.LA(1)) {
case INT:
case FLOAT:
_localctx = new IDtypeContext(_localctx);
enterOuterAlt(_localctx, 1);
{
setState(134);
typeid();
}
break;
case ARRAY:
_localctx = new ArrayTypeContext(_localctx);
enterOuterAlt(_localctx, 2);
{
setState(135);
match(ARRAY);
setState(136);
match(LBRACK);
setState(137);
match(INTLIT);
setState(138);
match(RBRACK);
setState(139);
match(OF);
setState(140);
typeid();
}
break;
case RECORD:
_localctx = new RecordTypeContext(_localctx);
enterOuterAlt(_localctx, 3);
{
setState(141);
match(RECORD);
setState(142);
fieldlist();
setState(143);
match(END);
}
break;
case ID:
_localctx = new PointerTypeContext(_localctx);
enterOuterAlt(_localctx, 4);
{
setState(145);
match(ID);
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class FieldlistContext extends ParserRuleContext {
public TerminalNode ID() { return getToken(TigerLLKParser.ID, 0); }
public TerminalNode COLON() { return getToken(TigerLLKParser.COLON, 0); }
public TypeidContext typeid() {
return getRuleContext(TypeidContext.class,0);
}
public TerminalNode SEMI() { return getToken(TigerLLKParser.SEMI, 0); }
public FieldlistContext fieldlist() {
return getRuleContext(FieldlistContext.class,0);
}
public FieldlistContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_fieldlist; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitFieldlist(this);
else return visitor.visitChildren(this);
}
}
public final FieldlistContext fieldlist() throws RecognitionException {
FieldlistContext _localctx = new FieldlistContext(_ctx, getState());
enterRule(_localctx, 16, RULE_fieldlist);
try {
setState(155);
_errHandler.sync(this);
switch (_input.LA(1)) {
case ID:
enterOuterAlt(_localctx, 1);
{
setState(148);
match(ID);
setState(149);
match(COLON);
setState(150);
typeid();
setState(151);
match(SEMI);
setState(152);
fieldlist();
}
break;
case END:
enterOuterAlt(_localctx, 2);
{
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class TypeidContext extends ParserRuleContext {
public TerminalNode INT() { return getToken(TigerLLKParser.INT, 0); }
public TerminalNode FLOAT() { return getToken(TigerLLKParser.FLOAT, 0); }
public TypeidContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_typeid; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitTypeid(this);
else return visitor.visitChildren(this);
}
}
public final TypeidContext typeid() throws RecognitionException {
TypeidContext _localctx = new TypeidContext(_ctx, getState());
enterRule(_localctx, 18, RULE_typeid);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(157);
_la = _input.LA(1);
if ( !(_la==INT || _la==FLOAT) ) {
_errHandler.recoverInline(this);
}
else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
_errHandler.reportMatch(this);
consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class VardeclarationContext extends ParserRuleContext {
public TerminalNode VAR() { return getToken(TigerLLKParser.VAR, 0); }
public IdlistContext idlist() {
return getRuleContext(IdlistContext.class,0);
}
public TerminalNode COLON() { return getToken(TigerLLKParser.COLON, 0); }
public TypeContext type() {
return getRuleContext(TypeContext.class,0);
}
public OptionalinitContext optionalinit() {
return getRuleContext(OptionalinitContext.class,0);
}
public TerminalNode SEMI() { return getToken(TigerLLKParser.SEMI, 0); }
public VardeclarationContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_vardeclaration; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitVardeclaration(this);
else return visitor.visitChildren(this);
}
}
public final VardeclarationContext vardeclaration() throws RecognitionException {
VardeclarationContext _localctx = new VardeclarationContext(_ctx, getState());
enterRule(_localctx, 20, RULE_vardeclaration);
try {
enterOuterAlt(_localctx, 1);
{
setState(159);
match(VAR);
setState(160);
idlist();
setState(161);
match(COLON);
setState(162);
type();
setState(163);
optionalinit();
setState(164);
match(SEMI);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class IdlistContext extends ParserRuleContext {
public TerminalNode ID() { return getToken(TigerLLKParser.ID, 0); }
public ItailContext itail() {
return getRuleContext(ItailContext.class,0);
}
public IdlistContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_idlist; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitIdlist(this);
else return visitor.visitChildren(this);
}
}
public final IdlistContext idlist() throws RecognitionException {
IdlistContext _localctx = new IdlistContext(_ctx, getState());
enterRule(_localctx, 22, RULE_idlist);
try {
enterOuterAlt(_localctx, 1);
{
setState(166);
match(ID);
setState(167);
itail();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class ItailContext extends ParserRuleContext {
public TerminalNode COMMA() { return getToken(TigerLLKParser.COMMA, 0); }
public IdlistContext idlist() {
return getRuleContext(IdlistContext.class,0);
}
public ItailContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_itail; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitItail(this);
else return visitor.visitChildren(this);
}
}
public final ItailContext itail() throws RecognitionException {
ItailContext _localctx = new ItailContext(_ctx, getState());
enterRule(_localctx, 24, RULE_itail);
try {
setState(172);
_errHandler.sync(this);
switch (_input.LA(1)) {
case COMMA:
enterOuterAlt(_localctx, 1);
{
setState(169);
match(COMMA);
setState(170);
idlist();
}
break;
case COLON:
enterOuterAlt(_localctx, 2);
{
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class OptionalinitContext extends ParserRuleContext {
public TerminalNode ASSIGN() { return getToken(TigerLLKParser.ASSIGN, 0); }
public ConstaContext consta() {
return getRuleContext(ConstaContext.class,0);
}
public OptionalinitContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_optionalinit; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitOptionalinit(this);
else return visitor.visitChildren(this);
}
}
public final OptionalinitContext optionalinit() throws RecognitionException {
OptionalinitContext _localctx = new OptionalinitContext(_ctx, getState());
enterRule(_localctx, 26, RULE_optionalinit);
try {
setState(177);
_errHandler.sync(this);
switch (_input.LA(1)) {
case ASSIGN:
enterOuterAlt(_localctx, 1);
{
setState(174);
match(ASSIGN);
setState(175);
consta();
}
break;
case SEMI:
enterOuterAlt(_localctx, 2);
{
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class FunctdeclarationContext extends ParserRuleContext {
public TerminalNode FUNC() { return getToken(TigerLLKParser.FUNC, 0); }
public TerminalNode ID() { return getToken(TigerLLKParser.ID, 0); }
public TerminalNode LPAREN() { return getToken(TigerLLKParser.LPAREN, 0); }
public ParamlistContext paramlist() {
return getRuleContext(ParamlistContext.class,0);
}
public TerminalNode RPAREN() { return getToken(TigerLLKParser.RPAREN, 0); }
public RettypeContext rettype() {
return getRuleContext(RettypeContext.class,0);
}
public TerminalNode BEGIN() { return getToken(TigerLLKParser.BEGIN, 0); }
public StatseqContext statseq() {
return getRuleContext(StatseqContext.class,0);
}
public TerminalNode END() { return getToken(TigerLLKParser.END, 0); }
public TerminalNode SEMI() { return getToken(TigerLLKParser.SEMI, 0); }
public FunctdeclarationContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_functdeclaration; }
@Override
public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
if ( visitor instanceof TigerLLKVisitor ) return ((TigerLLKVisitor<? extends T>)visitor).visitFunctdeclaration(this);
else return visitor.visitChildren(this);
}
}
public final FunctdeclarationContext functdeclaration() throws RecognitionException {
FunctdeclarationContext _localctx = new FunctdeclarationContext(_ctx, getState());
enterRule(_localctx, 28, RULE_functdeclaration);
try {
enterOuterAlt(_localctx, 1);
{
setState(179);
match(FUNC);
setState(180);
match(ID);
setState(181);
match(LPAREN);
setState(182);
paramlist();
setState(183);
match(RPAREN);
setState(184);
rettype();
setState(185);
match(BEGIN);
setState(186);
statseq();
setState(187);
match(END);
setState(188);
match(SEMI);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {