forked from halbekanne/osu-sgl
/
SGLParser.cs
3467 lines (2796 loc) · 138 KB
/
SGLParser.cs
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
// $ANTLR 3.2 Sep 23, 2009 12:02:23 C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g 2011-08-08 16:17:03
// The variable 'variable' is assigned but its value is never used.
#pragma warning disable 168, 219
// Unreachable code detected.
#pragma warning disable 162
//using SGLParserTester;
using System;
using Antlr.Runtime;
using IList = System.Collections.IList;
using ArrayList = System.Collections.ArrayList;
using Stack = Antlr.Runtime.Collections.StackList;
using Antlr.Runtime.Tree;
namespace SGL.AntlrParser
{
public partial class SGLParser : Parser
{
public static readonly string[] tokenNames = new string[]
{
"<invalid>",
"<EOR>",
"<DOWN>",
"<UP>",
"VARDEF",
"ASSIGN",
"NEGATE",
"LIBMETHOD",
"STRING",
"Identifier",
"IntType",
"BooleanType",
"StringType",
"FloatType",
"ObjectType",
"IntegerAtom",
"FloatAtom",
"BooleanAtom",
"SpriteAnimation",
"StringAtom",
"EscapeSequence",
"Letter",
"SGLIDDigit",
"UnicodeEscape",
"OctalEscape",
"HEX_DIGIT",
"WS",
"COMMENT",
"','",
"'='",
"'while'",
"'('",
"')'",
"'{'",
"'}'",
"'?'",
"':'",
"'||'",
"'&&'",
"'=='",
"'!='",
"'<'",
"'>'",
"'<='",
"'>='",
"'+'",
"'-'",
"'*'",
"'/'",
"'%'",
"'++'",
"'--'",
"'!'",
"'new'",
"'null'"
};
public const int T__29 = 29;
public const int T__28 = 28;
public const int SGLIDDigit = 22;
public const int IntType = 10;
public const int EOF = -1;
public const int Identifier = 9;
public const int T__51 = 51;
public const int T__52 = 52;
public const int T__53 = 53;
public const int T__54 = 54;
public const int StringType = 12;
public const int SpriteAnimation = 18;
public const int COMMENT = 27;
public const int VARDEF = 4;
public const int T__50 = 50;
public const int BooleanType = 11;
public const int T__42 = 42;
public const int T__43 = 43;
public const int T__40 = 40;
public const int T__41 = 41;
public const int T__46 = 46;
public const int T__47 = 47;
public const int T__44 = 44;
public const int T__45 = 45;
public const int T__48 = 48;
public const int T__49 = 49;
public const int LIBMETHOD = 7;
public const int IntegerAtom = 15;
public const int FloatType = 13;
public const int StringAtom = 19;
public const int HEX_DIGIT = 25;
public const int NEGATE = 6;
public const int BooleanAtom = 17;
public const int T__30 = 30;
public const int T__31 = 31;
public const int T__32 = 32;
public const int WS = 26;
public const int T__33 = 33;
public const int T__34 = 34;
public const int T__35 = 35;
public const int T__36 = 36;
public const int T__37 = 37;
public const int T__38 = 38;
public const int T__39 = 39;
public const int UnicodeEscape = 23;
public const int ASSIGN = 5;
public const int ObjectType = 14;
public const int FloatAtom = 16;
public const int OctalEscape = 24;
public const int Letter = 21;
public const int EscapeSequence = 20;
public const int STRING = 8;
// delegates
// delegators
public SGLParser(ITokenStream input)
: this(input, new RecognizerSharedState()) {
}
public SGLParser(ITokenStream input, RecognizerSharedState state)
: base(input, state) {
InitializeCyclicDFAs();
}
protected ITreeAdaptor adaptor = new CommonTreeAdaptor();
public ITreeAdaptor TreeAdaptor
{
get { return this.adaptor; }
set {
this.adaptor = value;
}
}
override public string[] TokenNames {
get { return SGLParser.tokenNames; }
}
override public string GrammarFileName {
get { return "C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g"; }
}
// Error reporting
/*
private StdErrReporter errorReporter = new StdErrReporter();
public override void EmitErrorMessage(String msg)
{
errorReporter.ReportError(msg);
}
*/
// For global variables (accessable anywhere)
//NullableDictionnary globalVariables = new NullableDictionnary();
// For main variables (accessable anywhere but methods)
//Stack<NullableDictionnary> localVariables = new Stack<NullableDictionnary>();
//NullableDictionnary mainVariables = new NullableDictionnary();
// This should tell the statements where they have to look up variables
//NullableDictionnary variableAccess = mainVariables;
//String output;
//public String GetOutput() {
// return output;
//}
public class compilationUnit_return : ParserRuleReturnScope
{
private object tree;
override public object Tree
{
get { return tree; }
set { tree = (object) value; }
}
};
// $ANTLR start "compilationUnit"
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:72:1: compilationUnit : ( mainStatement )+ EOF ;
public SGLParser.compilationUnit_return compilationUnit() // throws RecognitionException [1]
{
SGLParser.compilationUnit_return retval = new SGLParser.compilationUnit_return();
retval.Start = input.LT(1);
object root_0 = null;
IToken EOF2 = null;
SGLParser.mainStatement_return mainStatement1 = default(SGLParser.mainStatement_return);
object EOF2_tree=null;
try
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:73:2: ( ( mainStatement )+ EOF )
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:73:4: ( mainStatement )+ EOF
{
root_0 = (object)adaptor.GetNilNode();
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:73:4: ( mainStatement )+
int cnt1 = 0;
do
{
int alt1 = 2;
int LA1_0 = input.LA(1);
if ( ((LA1_0 >= Identifier && LA1_0 <= ObjectType) || LA1_0 == 30) )
{
alt1 = 1;
}
switch (alt1)
{
case 1 :
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:73:4: mainStatement
{
PushFollow(FOLLOW_mainStatement_in_compilationUnit99);
mainStatement1 = mainStatement();
state.followingStackPointer--;
adaptor.AddChild(root_0, mainStatement1.Tree);
}
break;
default:
if ( cnt1 >= 1 ) goto loop1;
EarlyExitException eee1 =
new EarlyExitException(1, input);
throw eee1;
}
cnt1++;
} while (true);
loop1:
; // Stops C# compiler whining that label 'loop1' has no statements
EOF2=(IToken)Match(input,EOF,FOLLOW_EOF_in_compilationUnit102);
EOF2_tree = (object)adaptor.Create(EOF2);
adaptor.AddChild(root_0, EOF2_tree);
}
retval.Stop = input.LT(-1);
retval.Tree = (object)adaptor.RulePostProcessing(root_0);
adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
}
catch (RecognitionException re)
{
ReportError(re);
Recover(input,re);
// Conversion of the second argument necessary, but harmless
retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);
}
finally
{
}
return retval;
}
// $ANTLR end "compilationUnit"
public class mainStatement_return : ParserRuleReturnScope
{
private object tree;
override public object Tree
{
get { return tree; }
set { tree = (object) value; }
}
};
// $ANTLR start "mainStatement"
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:76:1: mainStatement : statement ;
public SGLParser.mainStatement_return mainStatement() // throws RecognitionException [1]
{
SGLParser.mainStatement_return retval = new SGLParser.mainStatement_return();
retval.Start = input.LT(1);
object root_0 = null;
SGLParser.statement_return statement3 = default(SGLParser.statement_return);
try
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:77:2: ( statement )
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:77:4: statement
{
root_0 = (object)adaptor.GetNilNode();
PushFollow(FOLLOW_statement_in_mainStatement114);
statement3 = statement();
state.followingStackPointer--;
adaptor.AddChild(root_0, statement3.Tree);
}
retval.Stop = input.LT(-1);
retval.Tree = (object)adaptor.RulePostProcessing(root_0);
adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
}
catch (RecognitionException re)
{
ReportError(re);
Recover(input,re);
// Conversion of the second argument necessary, but harmless
retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);
}
finally
{
}
return retval;
}
// $ANTLR end "mainStatement"
public class statement_return : ParserRuleReturnScope
{
private object tree;
override public object Tree
{
get { return tree; }
set { tree = (object) value; }
}
};
// $ANTLR start "statement"
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:81:1: statement : ( variableDeclarationList | variableAssignment -> ^( ASSIGN variableAssignment ) | whileLoop );
public SGLParser.statement_return statement() // throws RecognitionException [1]
{
SGLParser.statement_return retval = new SGLParser.statement_return();
retval.Start = input.LT(1);
object root_0 = null;
SGLParser.variableDeclarationList_return variableDeclarationList4 = default(SGLParser.variableDeclarationList_return);
SGLParser.variableAssignment_return variableAssignment5 = default(SGLParser.variableAssignment_return);
SGLParser.whileLoop_return whileLoop6 = default(SGLParser.whileLoop_return);
RewriteRuleSubtreeStream stream_variableAssignment = new RewriteRuleSubtreeStream(adaptor,"rule variableAssignment");
try
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:83:2: ( variableDeclarationList | variableAssignment -> ^( ASSIGN variableAssignment ) | whileLoop )
int alt2 = 3;
switch ( input.LA(1) )
{
case IntType:
case BooleanType:
case StringType:
case FloatType:
case ObjectType:
{
alt2 = 1;
}
break;
case Identifier:
{
alt2 = 2;
}
break;
case 30:
{
alt2 = 3;
}
break;
default:
NoViableAltException nvae_d2s0 =
new NoViableAltException("", 2, 0, input);
throw nvae_d2s0;
}
switch (alt2)
{
case 1 :
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:83:4: variableDeclarationList
{
root_0 = (object)adaptor.GetNilNode();
PushFollow(FOLLOW_variableDeclarationList_in_statement129);
variableDeclarationList4 = variableDeclarationList();
state.followingStackPointer--;
adaptor.AddChild(root_0, variableDeclarationList4.Tree);
}
break;
case 2 :
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:84:4: variableAssignment
{
PushFollow(FOLLOW_variableAssignment_in_statement135);
variableAssignment5 = variableAssignment();
state.followingStackPointer--;
stream_variableAssignment.Add(variableAssignment5.Tree);
// AST REWRITE
// elements: variableAssignment
// token labels:
// rule labels: retval
// token list labels:
// rule list labels:
// wildcard labels:
retval.Tree = root_0;
RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);
root_0 = (object)adaptor.GetNilNode();
// 84:23: -> ^( ASSIGN variableAssignment )
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:84:26: ^( ASSIGN variableAssignment )
{
object root_1 = (object)adaptor.GetNilNode();
root_1 = (object)adaptor.BecomeRoot((object)adaptor.Create(ASSIGN, "ASSIGN"), root_1);
adaptor.AddChild(root_1, stream_variableAssignment.NextTree());
adaptor.AddChild(root_0, root_1);
}
}
retval.Tree = root_0;retval.Tree = root_0;
}
break;
case 3 :
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:85:4: whileLoop
{
root_0 = (object)adaptor.GetNilNode();
PushFollow(FOLLOW_whileLoop_in_statement148);
whileLoop6 = whileLoop();
state.followingStackPointer--;
adaptor.AddChild(root_0, whileLoop6.Tree);
}
break;
}
retval.Stop = input.LT(-1);
retval.Tree = (object)adaptor.RulePostProcessing(root_0);
adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
}
catch (RecognitionException re)
{
ReportError(re);
Recover(input,re);
// Conversion of the second argument necessary, but harmless
retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);
}
finally
{
}
return retval;
}
// $ANTLR end "statement"
public class variableDeclarationList_return : ParserRuleReturnScope
{
private object tree;
override public object Tree
{
get { return tree; }
set { tree = (object) value; }
}
};
// $ANTLR start "variableDeclarationList"
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:92:1: variableDeclarationList : variableType variableAssignment ( ',' variableAssignment )* -> ( ^( VARDEF variableType variableAssignment ) )+ ;
public SGLParser.variableDeclarationList_return variableDeclarationList() // throws RecognitionException [1]
{
SGLParser.variableDeclarationList_return retval = new SGLParser.variableDeclarationList_return();
retval.Start = input.LT(1);
object root_0 = null;
IToken char_literal9 = null;
SGLParser.variableType_return variableType7 = default(SGLParser.variableType_return);
SGLParser.variableAssignment_return variableAssignment8 = default(SGLParser.variableAssignment_return);
SGLParser.variableAssignment_return variableAssignment10 = default(SGLParser.variableAssignment_return);
object char_literal9_tree=null;
RewriteRuleTokenStream stream_28 = new RewriteRuleTokenStream(adaptor,"token 28");
RewriteRuleSubtreeStream stream_variableType = new RewriteRuleSubtreeStream(adaptor,"rule variableType");
RewriteRuleSubtreeStream stream_variableAssignment = new RewriteRuleSubtreeStream(adaptor,"rule variableAssignment");
try
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:93:2: ( variableType variableAssignment ( ',' variableAssignment )* -> ( ^( VARDEF variableType variableAssignment ) )+ )
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:93:4: variableType variableAssignment ( ',' variableAssignment )*
{
PushFollow(FOLLOW_variableType_in_variableDeclarationList164);
variableType7 = variableType();
state.followingStackPointer--;
stream_variableType.Add(variableType7.Tree);
PushFollow(FOLLOW_variableAssignment_in_variableDeclarationList166);
variableAssignment8 = variableAssignment();
state.followingStackPointer--;
stream_variableAssignment.Add(variableAssignment8.Tree);
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:93:36: ( ',' variableAssignment )*
do
{
int alt3 = 2;
int LA3_0 = input.LA(1);
if ( (LA3_0 == 28) )
{
alt3 = 1;
}
switch (alt3)
{
case 1 :
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:93:37: ',' variableAssignment
{
char_literal9=(IToken)Match(input,28,FOLLOW_28_in_variableDeclarationList169);
stream_28.Add(char_literal9);
PushFollow(FOLLOW_variableAssignment_in_variableDeclarationList171);
variableAssignment10 = variableAssignment();
state.followingStackPointer--;
stream_variableAssignment.Add(variableAssignment10.Tree);
}
break;
default:
goto loop3;
}
} while (true);
loop3:
; // Stops C# compiler whining that label 'loop3' has no statements
// AST REWRITE
// elements: variableAssignment, variableType
// token labels:
// rule labels: retval
// token list labels:
// rule list labels:
// wildcard labels:
retval.Tree = root_0;
RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);
root_0 = (object)adaptor.GetNilNode();
// 93:62: -> ( ^( VARDEF variableType variableAssignment ) )+
{
if ( !(stream_variableAssignment.HasNext() || stream_variableType.HasNext()) ) {
throw new RewriteEarlyExitException();
}
while ( stream_variableAssignment.HasNext() || stream_variableType.HasNext() )
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:93:65: ^( VARDEF variableType variableAssignment )
{
object root_1 = (object)adaptor.GetNilNode();
root_1 = (object)adaptor.BecomeRoot((object)adaptor.Create(VARDEF, "VARDEF"), root_1);
adaptor.AddChild(root_1, stream_variableType.NextTree());
adaptor.AddChild(root_1, stream_variableAssignment.NextTree());
adaptor.AddChild(root_0, root_1);
}
}
stream_variableAssignment.Reset();
stream_variableType.Reset();
}
retval.Tree = root_0;retval.Tree = root_0;
}
retval.Stop = input.LT(-1);
retval.Tree = (object)adaptor.RulePostProcessing(root_0);
adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
}
catch (RecognitionException re)
{
ReportError(re);
Recover(input,re);
// Conversion of the second argument necessary, but harmless
retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);
}
finally
{
}
return retval;
}
// $ANTLR end "variableDeclarationList"
public class variableAssignment_return : ParserRuleReturnScope
{
private object tree;
override public object Tree
{
get { return tree; }
set { tree = (object) value; }
}
};
// $ANTLR start "variableAssignment"
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:96:1: variableAssignment : variableName ( '=' expression )? -> variableName ( expression )? ;
public SGLParser.variableAssignment_return variableAssignment() // throws RecognitionException [1]
{
SGLParser.variableAssignment_return retval = new SGLParser.variableAssignment_return();
retval.Start = input.LT(1);
object root_0 = null;
IToken char_literal12 = null;
SGLParser.variableName_return variableName11 = default(SGLParser.variableName_return);
SGLParser.expression_return expression13 = default(SGLParser.expression_return);
object char_literal12_tree=null;
RewriteRuleTokenStream stream_29 = new RewriteRuleTokenStream(adaptor,"token 29");
RewriteRuleSubtreeStream stream_expression = new RewriteRuleSubtreeStream(adaptor,"rule expression");
RewriteRuleSubtreeStream stream_variableName = new RewriteRuleSubtreeStream(adaptor,"rule variableName");
try
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:97:2: ( variableName ( '=' expression )? -> variableName ( expression )? )
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:97:4: variableName ( '=' expression )?
{
PushFollow(FOLLOW_variableName_in_variableAssignment195);
variableName11 = variableName();
state.followingStackPointer--;
stream_variableName.Add(variableName11.Tree);
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:97:17: ( '=' expression )?
int alt4 = 2;
int LA4_0 = input.LA(1);
if ( (LA4_0 == 29) )
{
alt4 = 1;
}
switch (alt4)
{
case 1 :
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:97:18: '=' expression
{
char_literal12=(IToken)Match(input,29,FOLLOW_29_in_variableAssignment198);
stream_29.Add(char_literal12);
PushFollow(FOLLOW_expression_in_variableAssignment200);
expression13 = expression();
state.followingStackPointer--;
stream_expression.Add(expression13.Tree);
}
break;
}
// AST REWRITE
// elements: expression, variableName
// token labels:
// rule labels: retval
// token list labels:
// rule list labels:
// wildcard labels:
retval.Tree = root_0;
RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);
root_0 = (object)adaptor.GetNilNode();
// 97:36: -> variableName ( expression )?
{
adaptor.AddChild(root_0, stream_variableName.NextTree());
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:97:52: ( expression )?
if ( stream_expression.HasNext() )
{
adaptor.AddChild(root_0, stream_expression.NextTree());
}
stream_expression.Reset();
}
retval.Tree = root_0;retval.Tree = root_0;
}
retval.Stop = input.LT(-1);
retval.Tree = (object)adaptor.RulePostProcessing(root_0);
adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
}
catch (RecognitionException re)
{
ReportError(re);
Recover(input,re);
// Conversion of the second argument necessary, but harmless
retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);
}
finally
{
}
return retval;
}
// $ANTLR end "variableAssignment"
public class variableName_return : ParserRuleReturnScope
{
private object tree;
override public object Tree
{
get { return tree; }
set { tree = (object) value; }
}
};
// $ANTLR start "variableName"
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:103:1: variableName : Identifier ;
public SGLParser.variableName_return variableName() // throws RecognitionException [1]
{
SGLParser.variableName_return retval = new SGLParser.variableName_return();
retval.Start = input.LT(1);
object root_0 = null;
IToken Identifier14 = null;
object Identifier14_tree=null;
try
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:104:2: ( Identifier )
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:104:4: Identifier
{
root_0 = (object)adaptor.GetNilNode();
Identifier14=(IToken)Match(input,Identifier,FOLLOW_Identifier_in_variableName228);
Identifier14_tree = (object)adaptor.Create(Identifier14);
adaptor.AddChild(root_0, Identifier14_tree);
}
retval.Stop = input.LT(-1);
retval.Tree = (object)adaptor.RulePostProcessing(root_0);
adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
}
catch (RecognitionException re)
{
ReportError(re);
Recover(input,re);
// Conversion of the second argument necessary, but harmless
retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);
}
finally
{
}
return retval;
}
// $ANTLR end "variableName"
public class variableType_return : ParserRuleReturnScope
{
private object tree;
override public object Tree
{
get { return tree; }
set { tree = (object) value; }
}
};
// $ANTLR start "variableType"
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:107:1: variableType : ( IntType | BooleanType | StringType | FloatType | ObjectType );
public SGLParser.variableType_return variableType() // throws RecognitionException [1]
{
SGLParser.variableType_return retval = new SGLParser.variableType_return();
retval.Start = input.LT(1);
object root_0 = null;
IToken set15 = null;
object set15_tree=null;
try
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:108:2: ( IntType | BooleanType | StringType | FloatType | ObjectType )
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:
{
root_0 = (object)adaptor.GetNilNode();
set15 = (IToken)input.LT(1);
if ( (input.LA(1) >= IntType && input.LA(1) <= ObjectType) )
{
input.Consume();
adaptor.AddChild(root_0, (object)adaptor.Create(set15));
state.errorRecovery = false;
}
else
{
MismatchedSetException mse = new MismatchedSetException(null,input);
throw mse;
}
}
retval.Stop = input.LT(-1);
retval.Tree = (object)adaptor.RulePostProcessing(root_0);
adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
}
catch (RecognitionException re)
{
ReportError(re);
Recover(input,re);
// Conversion of the second argument necessary, but harmless
retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);
}
finally
{
}
return retval;
}
// $ANTLR end "variableType"
public class whileLoop_return : ParserRuleReturnScope
{
private object tree;
override public object Tree
{
get { return tree; }
set { tree = (object) value; }
}
};
// $ANTLR start "whileLoop"
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:116:1: whileLoop : 'while' '(' expression ')' ( statement -> ^( 'while' expression statement ) | block -> ^( 'while' expression block ) ) ;
public SGLParser.whileLoop_return whileLoop() // throws RecognitionException [1]
{
SGLParser.whileLoop_return retval = new SGLParser.whileLoop_return();
retval.Start = input.LT(1);
object root_0 = null;
IToken string_literal16 = null;
IToken char_literal17 = null;
IToken char_literal19 = null;
SGLParser.expression_return expression18 = default(SGLParser.expression_return);
SGLParser.statement_return statement20 = default(SGLParser.statement_return);
SGLParser.block_return block21 = default(SGLParser.block_return);
object string_literal16_tree=null;
object char_literal17_tree=null;
object char_literal19_tree=null;
RewriteRuleTokenStream stream_30 = new RewriteRuleTokenStream(adaptor,"token 30");
RewriteRuleTokenStream stream_32 = new RewriteRuleTokenStream(adaptor,"token 32");
RewriteRuleTokenStream stream_31 = new RewriteRuleTokenStream(adaptor,"token 31");
RewriteRuleSubtreeStream stream_expression = new RewriteRuleSubtreeStream(adaptor,"rule expression");
RewriteRuleSubtreeStream stream_statement = new RewriteRuleSubtreeStream(adaptor,"rule statement");
RewriteRuleSubtreeStream stream_block = new RewriteRuleSubtreeStream(adaptor,"rule block");
try
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:117:2: ( 'while' '(' expression ')' ( statement -> ^( 'while' expression statement ) | block -> ^( 'while' expression block ) ) )
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:117:4: 'while' '(' expression ')' ( statement -> ^( 'while' expression statement ) | block -> ^( 'while' expression block ) )
{
string_literal16=(IToken)Match(input,30,FOLLOW_30_in_whileLoop272);
stream_30.Add(string_literal16);
char_literal17=(IToken)Match(input,31,FOLLOW_31_in_whileLoop274);
stream_31.Add(char_literal17);
PushFollow(FOLLOW_expression_in_whileLoop276);
expression18 = expression();
state.followingStackPointer--;
stream_expression.Add(expression18.Tree);
char_literal19=(IToken)Match(input,32,FOLLOW_32_in_whileLoop278);
stream_32.Add(char_literal19);
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:118:2: ( statement -> ^( 'while' expression statement ) | block -> ^( 'while' expression block ) )
int alt5 = 2;
int LA5_0 = input.LA(1);
if ( ((LA5_0 >= Identifier && LA5_0 <= ObjectType) || LA5_0 == 30) )
{
alt5 = 1;
}
else if ( (LA5_0 == 33) )
{
alt5 = 2;
}
else
{
NoViableAltException nvae_d5s0 =
new NoViableAltException("", 5, 0, input);
throw nvae_d5s0;
}
switch (alt5)
{
case 1 :
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:118:4: statement
{
PushFollow(FOLLOW_statement_in_whileLoop284);
statement20 = statement();
state.followingStackPointer--;
stream_statement.Add(statement20.Tree);
// AST REWRITE
// elements: statement, expression, 30
// token labels:
// rule labels: retval
// token list labels:
// rule list labels:
// wildcard labels:
retval.Tree = root_0;
RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "rule retval", retval!=null ? retval.Tree : null);
root_0 = (object)adaptor.GetNilNode();
// 118:14: -> ^( 'while' expression statement )
{
// C:\\Users\\Dominik Halfkann\\Documents\\Visual Studio 2010\\Projects\\SGLParserTester\\SGL\\SGL.g:118:17: ^( 'while' expression statement )
{
object root_1 = (object)adaptor.GetNilNode();
root_1 = (object)adaptor.BecomeRoot(stream_30.NextNode(), root_1);
adaptor.AddChild(root_1, stream_expression.NextTree());
adaptor.AddChild(root_1, stream_statement.NextTree());
adaptor.AddChild(root_0, root_1);
}
}
retval.Tree = root_0;retval.Tree = root_0;
}
break;
case 2 :