-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjtb.out.jj
792 lines (680 loc) · 13.9 KB
/
jtb.out.jj
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
//
// Generated by JTB 1.3.2
//
options {
JAVA_UNICODE_ESCAPE = true;
}
PARSER_BEGIN(KangaParser)
import syntaxtree.*;
import java.util.Vector;
public class KangaParser
{
}
class JTBToolkit {
static NodeToken makeNodeToken(Token t) {
return new NodeToken(t.image.intern(), t.kind, t.beginLine, t.beginColumn, t.endLine, t.endColumn);
}
}
PARSER_END(KangaParser)
SKIP :
{
" "
| "\t"
| "\n"
| "\r"
| "\f"
}
SPECIAL_TOKEN :
{
<SINGLE_LINE_COMMENT: "//" (~["\n", "\r"])* ("\n" | "\r" | "\r\n")>
| <FORMAL_COMMENT: "/**" (~["*"])* "*" ("*" | (~["*", "/"] (~["*"])* "*"))* "/">
| <MULTI_LINE_COMMENT: "/*" (~["*"])* "*" ("*" | (~["*", "/"] (~["*"])* "*"))* "/">
}
TOKEN :
{
<LPAREN: "(">
| <RPAREN: ")">
| <LBRACE: "{">
| <RBRACE: "}">
| <LSQPAREN: "[">
| <RSQPAREN: "]">
| <DOT: ".">
| <LT: "LT">
| <LE: "LE">
| <GT: "GT">
| <GE: "GE">
| <NE: "NE">
| <EQ: "EQ">
| <PLUS: "PLUS">
| <MINUS: "MINUS">
| <AND: "AND">
| <OR: "OR">
| <NOT: "NOT">
| <TIMES: "TIMES">
| <MAIN: "MAIN">
| <CODE: "CODE">
| <HALLOCATE: "HALLOCATE">
| <SPILLEDARG: "SPILLEDARG">
| <END: "END">
| <NOOP: "NOOP">
| <MOVE: "MOVE">
| <CALL: "CALL">
| <ERROR: "ERROR">
| <PRINT: "PRINT">
| <BEGIN: "BEGIN">
| <RETURN: "RETURN">
| <JUMP: "JUMP">
| <CJUMP: "CJUMP">
| <HSTORE: "HSTORE">
| <HLOAD: "HLOAD">
| <ALOAD: "ALOAD">
| <ASTORE: "ASTORE">
| <PASSARG: "PASSARG">
| <MEM: "MEM">
| <TEMP: "TEMP">
| <ARG: "ARG">
| <ZERO: "zero">
| <at: "at">
| <v0: "v0">
| <v1: "v1">
| <a0: "a0">
| <a1: "a1">
| <a2: "a2">
| <a3: "a3">
| <t0: "t0">
| <t1: "t1">
| <t2: "t2">
| <t3: "t3">
| <t4: "t4">
| <t5: "t5">
| <t6: "t6">
| <t7: "t7">
| <s0: "s0">
| <s1: "s1">
| <s2: "s2">
| <s3: "s3">
| <s4: "s4">
| <s5: "s5">
| <s6: "s6">
| <s7: "s7">
| <t8: "t8">
| <t9: "t9">
| <k0: "k0">
| <k1: "k1">
| <gp: "gp">
| <sp: "sp">
| <fp: "fp">
| <ra: "ra">
}
TOKEN :
{
<INTEGER_LITERAL: (["1"-"9"] (["0"-"9"])* | "0")>
}
TOKEN :
{
<IDENTIFIER: <LETTER> (<LETTER> | <DIGIT>)*>
| <#LETTER: ["$", "A"-"Z", "_", "a"-"z", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff", "\u0100"-"\u1fff", "\u3040"-"\u318f", "\u3300"-"\u337f", "\u3400"-"\u3d2d", "\u4e00"-"\u9fff", "\uf900"-"\ufaff"]>
| <#DIGIT: ["0"-"9", "\u0660"-"\u0669", "\u06f0"-"\u06f9", "\u0966"-"\u096f", "\u09e6"-"\u09ef", "\u0a66"-"\u0a6f", "\u0ae6"-"\u0aef", "\u0b66"-"\u0b6f", "\u0be7"-"\u0bef", "\u0c66"-"\u0c6f", "\u0ce6"-"\u0cef", "\u0d66"-"\u0d6f", "\u0e50"-"\u0e59", "\u0ed0"-"\u0ed9", "\u1040"-"\u1049"]>
}
Goal Goal() :
{
NodeToken n0;
Token n1;
NodeToken n2;
Token n3;
IntegerLiteral n4;
NodeToken n5;
Token n6;
NodeToken n7;
Token n8;
IntegerLiteral n9;
NodeToken n10;
Token n11;
NodeToken n12;
Token n13;
IntegerLiteral n14;
NodeToken n15;
Token n16;
StmtList n17;
NodeToken n18;
Token n19;
NodeListOptional n20 = new NodeListOptional();
Procedure n21;
NodeToken n22;
Token n23;
}
{
n1="MAIN" { n0 = JTBToolkit.makeNodeToken(n1); }
n3="[" { n2 = JTBToolkit.makeNodeToken(n3); }
n4=IntegerLiteral()
n6="]" { n5 = JTBToolkit.makeNodeToken(n6); }
n8="[" { n7 = JTBToolkit.makeNodeToken(n8); }
n9=IntegerLiteral()
n11="]" { n10 = JTBToolkit.makeNodeToken(n11); }
n13="[" { n12 = JTBToolkit.makeNodeToken(n13); }
n14=IntegerLiteral()
n16="]" { n15 = JTBToolkit.makeNodeToken(n16); }
n17=StmtList()
n19="END" { n18 = JTBToolkit.makeNodeToken(n19); }
(
n21=Procedure()
{ n20.addNode(n21); }
)*
{ n20.nodes.trimToSize(); }
n23=<EOF> {
n23.beginColumn++; n23.endColumn++;
n22 = JTBToolkit.makeNodeToken(n23);
}
{ return new Goal(n0,n2,n4,n5,n7,n9,n10,n12,n14,n15,n17,n18,n20,n22); }
}
StmtList StmtList() :
{
NodeListOptional n0 = new NodeListOptional();
NodeSequence n1;
NodeOptional n2;
Label n3;
Stmt n4;
}
{
(
{ n2 = new NodeOptional(); }
{ n1 = new NodeSequence(2); }
(
n3=Label()
{ n2.addNode(n3); }
)?
{ n1.addNode(n2); }
n4=Stmt()
{ n1.addNode(n4); }
{ n0.addNode(n1); }
)*
{ n0.nodes.trimToSize(); }
{ return new StmtList(n0); }
}
Procedure Procedure() :
{
Label n0;
NodeToken n1;
Token n2;
IntegerLiteral n3;
NodeToken n4;
Token n5;
NodeToken n6;
Token n7;
IntegerLiteral n8;
NodeToken n9;
Token n10;
NodeToken n11;
Token n12;
IntegerLiteral n13;
NodeToken n14;
Token n15;
StmtList n16;
NodeToken n17;
Token n18;
}
{
n0=Label()
n2="[" { n1 = JTBToolkit.makeNodeToken(n2); }
n3=IntegerLiteral()
n5="]" { n4 = JTBToolkit.makeNodeToken(n5); }
n7="[" { n6 = JTBToolkit.makeNodeToken(n7); }
n8=IntegerLiteral()
n10="]" { n9 = JTBToolkit.makeNodeToken(n10); }
n12="[" { n11 = JTBToolkit.makeNodeToken(n12); }
n13=IntegerLiteral()
n15="]" { n14 = JTBToolkit.makeNodeToken(n15); }
n16=StmtList()
n18="END" { n17 = JTBToolkit.makeNodeToken(n18); }
{ return new Procedure(n0,n1,n3,n4,n6,n8,n9,n11,n13,n14,n16,n17); }
}
Stmt Stmt() :
{
NodeChoice n0;
NoOpStmt n1;
ErrorStmt n2;
CJumpStmt n3;
JumpStmt n4;
HStoreStmt n5;
HLoadStmt n6;
MoveStmt n7;
PrintStmt n8;
ALoadStmt n9;
AStoreStmt n10;
PassArgStmt n11;
CallStmt n12;
}
{
(
n1=NoOpStmt()
{ n0 = new NodeChoice(n1, 0); }
|
n2=ErrorStmt()
{ n0 = new NodeChoice(n2, 1); }
|
n3=CJumpStmt()
{ n0 = new NodeChoice(n3, 2); }
|
n4=JumpStmt()
{ n0 = new NodeChoice(n4, 3); }
|
n5=HStoreStmt()
{ n0 = new NodeChoice(n5, 4); }
|
n6=HLoadStmt()
{ n0 = new NodeChoice(n6, 5); }
|
n7=MoveStmt()
{ n0 = new NodeChoice(n7, 6); }
|
n8=PrintStmt()
{ n0 = new NodeChoice(n8, 7); }
|
n9=ALoadStmt()
{ n0 = new NodeChoice(n9, 8); }
|
n10=AStoreStmt()
{ n0 = new NodeChoice(n10, 9); }
|
n11=PassArgStmt()
{ n0 = new NodeChoice(n11, 10); }
|
n12=CallStmt()
{ n0 = new NodeChoice(n12, 11); }
)
{ return new Stmt(n0); }
}
NoOpStmt NoOpStmt() :
{
NodeToken n0;
Token n1;
}
{
n1="NOOP" { n0 = JTBToolkit.makeNodeToken(n1); }
{ return new NoOpStmt(n0); }
}
ErrorStmt ErrorStmt() :
{
NodeToken n0;
Token n1;
}
{
n1="ERROR" { n0 = JTBToolkit.makeNodeToken(n1); }
{ return new ErrorStmt(n0); }
}
CJumpStmt CJumpStmt() :
{
NodeToken n0;
Token n1;
Reg n2;
Label n3;
}
{
n1="CJUMP" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=Reg()
n3=Label()
{ return new CJumpStmt(n0,n2,n3); }
}
JumpStmt JumpStmt() :
{
NodeToken n0;
Token n1;
Label n2;
}
{
n1="JUMP" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=Label()
{ return new JumpStmt(n0,n2); }
}
HStoreStmt HStoreStmt() :
{
NodeToken n0;
Token n1;
Reg n2;
IntegerLiteral n3;
Reg n4;
}
{
n1="HSTORE" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=Reg()
n3=IntegerLiteral()
n4=Reg()
{ return new HStoreStmt(n0,n2,n3,n4); }
}
HLoadStmt HLoadStmt() :
{
NodeToken n0;
Token n1;
Reg n2;
Reg n3;
IntegerLiteral n4;
}
{
n1="HLOAD" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=Reg()
n3=Reg()
n4=IntegerLiteral()
{ return new HLoadStmt(n0,n2,n3,n4); }
}
MoveStmt MoveStmt() :
{
NodeToken n0;
Token n1;
Reg n2;
Exp n3;
}
{
n1="MOVE" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=Reg()
n3=Exp()
{ return new MoveStmt(n0,n2,n3); }
}
PrintStmt PrintStmt() :
{
NodeToken n0;
Token n1;
SimpleExp n2;
}
{
n1="PRINT" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=SimpleExp()
{ return new PrintStmt(n0,n2); }
}
ALoadStmt ALoadStmt() :
{
NodeToken n0;
Token n1;
Reg n2;
SpilledArg n3;
}
{
n1="ALOAD" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=Reg()
n3=SpilledArg()
{ return new ALoadStmt(n0,n2,n3); }
}
AStoreStmt AStoreStmt() :
{
NodeToken n0;
Token n1;
SpilledArg n2;
Reg n3;
}
{
n1="ASTORE" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=SpilledArg()
n3=Reg()
{ return new AStoreStmt(n0,n2,n3); }
}
PassArgStmt PassArgStmt() :
{
NodeToken n0;
Token n1;
IntegerLiteral n2;
Reg n3;
}
{
n1="PASSARG" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=IntegerLiteral()
n3=Reg()
{ return new PassArgStmt(n0,n2,n3); }
}
CallStmt CallStmt() :
{
NodeToken n0;
Token n1;
SimpleExp n2;
}
{
n1="CALL" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=SimpleExp()
{ return new CallStmt(n0,n2); }
}
Exp Exp() :
{
NodeChoice n0;
HAllocate n1;
BinOp n2;
SimpleExp n3;
}
{
(
n1=HAllocate()
{ n0 = new NodeChoice(n1, 0); }
|
n2=BinOp()
{ n0 = new NodeChoice(n2, 1); }
|
n3=SimpleExp()
{ n0 = new NodeChoice(n3, 2); }
)
{ return new Exp(n0); }
}
HAllocate HAllocate() :
{
NodeToken n0;
Token n1;
SimpleExp n2;
}
{
n1="HALLOCATE" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=SimpleExp()
{ return new HAllocate(n0,n2); }
}
BinOp BinOp() :
{
Operator n0;
Reg n1;
SimpleExp n2;
}
{
n0=Operator()
n1=Reg()
n2=SimpleExp()
{ return new BinOp(n0,n1,n2); }
}
Operator Operator() :
{
NodeChoice n0;
NodeToken n1;
Token n2;
NodeToken n3;
Token n4;
NodeToken n5;
Token n6;
NodeToken n7;
Token n8;
}
{
(
n2="LT" { n1 = JTBToolkit.makeNodeToken(n2); }
{ n0 = new NodeChoice(n1, 0); }
|
n4="PLUS" { n3 = JTBToolkit.makeNodeToken(n4); }
{ n0 = new NodeChoice(n3, 1); }
|
n6="MINUS" { n5 = JTBToolkit.makeNodeToken(n6); }
{ n0 = new NodeChoice(n5, 2); }
|
n8="TIMES" { n7 = JTBToolkit.makeNodeToken(n8); }
{ n0 = new NodeChoice(n7, 3); }
)
{ return new Operator(n0); }
}
SpilledArg SpilledArg() :
{
NodeToken n0;
Token n1;
IntegerLiteral n2;
}
{
n1="SPILLEDARG" { n0 = JTBToolkit.makeNodeToken(n1); }
n2=IntegerLiteral()
{ return new SpilledArg(n0,n2); }
}
SimpleExp SimpleExp() :
{
NodeChoice n0;
Reg n1;
IntegerLiteral n2;
Label n3;
}
{
(
n1=Reg()
{ n0 = new NodeChoice(n1, 0); }
|
n2=IntegerLiteral()
{ n0 = new NodeChoice(n2, 1); }
|
n3=Label()
{ n0 = new NodeChoice(n3, 2); }
)
{ return new SimpleExp(n0); }
}
Reg Reg() :
{
NodeChoice n0;
NodeToken n1;
Token n2;
NodeToken n3;
Token n4;
NodeToken n5;
Token n6;
NodeToken n7;
Token n8;
NodeToken n9;
Token n10;
NodeToken n11;
Token n12;
NodeToken n13;
Token n14;
NodeToken n15;
Token n16;
NodeToken n17;
Token n18;
NodeToken n19;
Token n20;
NodeToken n21;
Token n22;
NodeToken n23;
Token n24;
NodeToken n25;
Token n26;
NodeToken n27;
Token n28;
NodeToken n29;
Token n30;
NodeToken n31;
Token n32;
NodeToken n33;
Token n34;
NodeToken n35;
Token n36;
NodeToken n37;
Token n38;
NodeToken n39;
Token n40;
NodeToken n41;
Token n42;
NodeToken n43;
Token n44;
NodeToken n45;
Token n46;
NodeToken n47;
Token n48;
}
{
(
n2="a0" { n1 = JTBToolkit.makeNodeToken(n2); }
{ n0 = new NodeChoice(n1, 0); }
|
n4="a1" { n3 = JTBToolkit.makeNodeToken(n4); }
{ n0 = new NodeChoice(n3, 1); }
|
n6="a2" { n5 = JTBToolkit.makeNodeToken(n6); }
{ n0 = new NodeChoice(n5, 2); }
|
n8="a3" { n7 = JTBToolkit.makeNodeToken(n8); }
{ n0 = new NodeChoice(n7, 3); }
|
n10="t0" { n9 = JTBToolkit.makeNodeToken(n10); }
{ n0 = new NodeChoice(n9, 4); }
|
n12="t1" { n11 = JTBToolkit.makeNodeToken(n12); }
{ n0 = new NodeChoice(n11, 5); }
|
n14="t2" { n13 = JTBToolkit.makeNodeToken(n14); }
{ n0 = new NodeChoice(n13, 6); }
|
n16="t3" { n15 = JTBToolkit.makeNodeToken(n16); }
{ n0 = new NodeChoice(n15, 7); }
|
n18="t4" { n17 = JTBToolkit.makeNodeToken(n18); }
{ n0 = new NodeChoice(n17, 8); }
|
n20="t5" { n19 = JTBToolkit.makeNodeToken(n20); }
{ n0 = new NodeChoice(n19, 9); }
|
n22="t6" { n21 = JTBToolkit.makeNodeToken(n22); }
{ n0 = new NodeChoice(n21, 10); }
|
n24="t7" { n23 = JTBToolkit.makeNodeToken(n24); }
{ n0 = new NodeChoice(n23, 11); }
|
n26="s0" { n25 = JTBToolkit.makeNodeToken(n26); }
{ n0 = new NodeChoice(n25, 12); }
|
n28="s1" { n27 = JTBToolkit.makeNodeToken(n28); }
{ n0 = new NodeChoice(n27, 13); }
|
n30="s2" { n29 = JTBToolkit.makeNodeToken(n30); }
{ n0 = new NodeChoice(n29, 14); }
|
n32="s3" { n31 = JTBToolkit.makeNodeToken(n32); }
{ n0 = new NodeChoice(n31, 15); }
|
n34="s4" { n33 = JTBToolkit.makeNodeToken(n34); }
{ n0 = new NodeChoice(n33, 16); }
|
n36="s5" { n35 = JTBToolkit.makeNodeToken(n36); }
{ n0 = new NodeChoice(n35, 17); }
|
n38="s6" { n37 = JTBToolkit.makeNodeToken(n38); }
{ n0 = new NodeChoice(n37, 18); }
|
n40="s7" { n39 = JTBToolkit.makeNodeToken(n40); }
{ n0 = new NodeChoice(n39, 19); }
|
n42="t8" { n41 = JTBToolkit.makeNodeToken(n42); }
{ n0 = new NodeChoice(n41, 20); }
|
n44="t9" { n43 = JTBToolkit.makeNodeToken(n44); }
{ n0 = new NodeChoice(n43, 21); }
|
n46="v0" { n45 = JTBToolkit.makeNodeToken(n46); }
{ n0 = new NodeChoice(n45, 22); }
|
n48="v1" { n47 = JTBToolkit.makeNodeToken(n48); }
{ n0 = new NodeChoice(n47, 23); }
)
{ return new Reg(n0); }
}
IntegerLiteral IntegerLiteral() :
{
NodeToken n0;
Token n1;
}
{
n1=<INTEGER_LITERAL> { n0 = JTBToolkit.makeNodeToken(n1); }
{ return new IntegerLiteral(n0); }
}
Label Label() :
{
NodeToken n0;
Token n1;
}
{
n1=<IDENTIFIER> { n0 = JTBToolkit.makeNodeToken(n1); }
{ return new Label(n0); }
}