-
Notifications
You must be signed in to change notification settings - Fork 0
/
toy.output
1046 lines (636 loc) · 19.5 KB
/
toy.output
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
Terminals unused in grammar
TRUE
FALSE
MOD
AND
OR
NOT
COMMENT
EQU
LTE
GTE
NEQ
NEGATE
ADD
SUB
MUL
DIV
LT
GT
Rules useless in parser due to conflicts
3 line: ε
State 1 conflicts: 7 shift/reduce
State 14 conflicts: 6 shift/reduce
State 19 conflicts: 6 shift/reduce
State 20 conflicts: 6 shift/reduce
State 32 conflicts: 1 shift/reduce
State 74 conflicts: 1 shift/reduce
Grammar
0 $accept: input $end
1 input: ε
2 | input line
3 line: ε
4 | pgm
5 pgm2: ε
6 | proc pgm2
7 | struct_ pgm2
8 pgm: proc pgm2
9 | struct_
10 exp: ε
11 | int_literal
12 int_literal: NUMBER
13 type: INT
14 | BOOL
15 | STRING
16 | ID
17 declaration: type ID
18 | declaration COMMA declaration
19 return_type: type
20 | VOID
21 struct_: STRUCT Name OB declaration CB
22 l_exp: ID
23 | ID DOT l_exp
24 intern_scope_then: THEN
25 intern_scope_else: ELSE
26 FOR_LOOP: FOR
27 stmt: FOR_LOOP OP ID ASSIGN exp SEMICOLON exp SEMICOLON stmt CP stmt
28 | IF OP exp CP intern_scope_then stmt
29 | IF OP exp CP intern_scope_then stmt intern_scope_else stmt
30 | PRINTF OP STRING CP SEMICOLON
31 | RETURN exp SEMICOLON
32 | OB stmt_seq CB
33 | type ID SEMICOLON
34 | l_exp ASSIGN exp SEMICOLON
35 stmt_seq: ε
36 | stmt stmt_seq
37 Name: ID
38 proc: return_type Name OP declaration CP OB stmt_seq CB
Terminals, with rules where they appear
$end (0) 0
error (256)
BOOL (258) 14
TRUE (259)
FALSE (260)
VOID (261) 20
PRINTF (262) 30
STRUCT (263) 21
IF (264) 28 29
THEN (265) 24
ELSE (266) 25
FOR (267) 26
RETURN (268) 31
MOD (269)
INT (270) 13
AND (271)
OR (272)
NOT (273)
ID <str> (274) 16 17 22 23 27 33 37
NUMBER <val> (275) 12
STRING (276) 15 30
COMMENT (277)
EQU (278)
LTE (279)
GTE (280)
NEQ (281)
OB (282) 21 32 38
CB (283) 21 32 38
SEMICOLON (284) 27 30 31 33 34
NEGATE (285)
OP (286) 27 28 29 30 38
CP (287) 27 28 29 30 38
ADD (288)
SUB (289)
MUL (290)
DIV (291)
DOT (292) 23
COMMA (293) 18
ASSIGN (294) 27 34
LT (295)
GT (296)
Nonterminals, with rules where they appear
$accept (42)
on left: 0
input (43)
on left: 1 2
on right: 0 2
line (44)
on left: 3 4
on right: 2
pgm2 (45)
on left: 5 6 7
on right: 6 7 8
pgm (46)
on left: 8 9
on right: 4
exp <val> (47)
on left: 10 11
on right: 27 28 29 31 34
int_literal <val> (48)
on left: 12
on right: 11
type <val> (49)
on left: 13 14 15 16
on right: 17 19 33
declaration <val> (50)
on left: 17 18
on right: 18 21 38
return_type (51)
on left: 19 20
on right: 38
struct_ <val> (52)
on left: 21
on right: 7 9
l_exp <val> (53)
on left: 22 23
on right: 23 34
intern_scope_then (54)
on left: 24
on right: 28 29
intern_scope_else (55)
on left: 25
on right: 29
FOR_LOOP (56)
on left: 26
on right: 27
stmt <val> (57)
on left: 27 28 29 30 31 32 33 34
on right: 27 28 29 36
stmt_seq <val> (58)
on left: 35 36
on right: 32 36 38
Name <val> (59)
on left: 37
on right: 21 38
proc <val> (60)
on left: 38
on right: 6 8
State 0
0 $accept: • input $end
$default reduce using rule 1 (input)
input go to state 1
State 1
0 $accept: input • $end
2 input: input • line
$end shift, and go to state 2
BOOL shift, and go to state 3
VOID shift, and go to state 4
STRUCT shift, and go to state 5
INT shift, and go to state 6
ID shift, and go to state 7
STRING shift, and go to state 8
$end [reduce using rule 3 (line)]
BOOL [reduce using rule 3 (line)]
VOID [reduce using rule 3 (line)]
STRUCT [reduce using rule 3 (line)]
INT [reduce using rule 3 (line)]
ID [reduce using rule 3 (line)]
STRING [reduce using rule 3 (line)]
line go to state 9
pgm go to state 10
type go to state 11
return_type go to state 12
struct_ go to state 13
proc go to state 14
State 2
0 $accept: input $end •
$default accept
State 3
14 type: BOOL •
$default reduce using rule 14 (type)
State 4
20 return_type: VOID •
$default reduce using rule 20 (return_type)
State 5
21 struct_: STRUCT • Name OB declaration CB
ID shift, and go to state 15
Name go to state 16
State 6
13 type: INT •
$default reduce using rule 13 (type)
State 7
16 type: ID •
$default reduce using rule 16 (type)
State 8
15 type: STRING •
$default reduce using rule 15 (type)
State 9
2 input: input line •
$default reduce using rule 2 (input)
State 10
4 line: pgm •
$default reduce using rule 4 (line)
State 11
19 return_type: type •
$default reduce using rule 19 (return_type)
State 12
38 proc: return_type • Name OP declaration CP OB stmt_seq CB
ID shift, and go to state 15
Name go to state 17
State 13
9 pgm: struct_ •
$default reduce using rule 9 (pgm)
State 14
8 pgm: proc • pgm2
BOOL shift, and go to state 3
VOID shift, and go to state 4
STRUCT shift, and go to state 5
INT shift, and go to state 6
ID shift, and go to state 7
STRING shift, and go to state 8
BOOL [reduce using rule 5 (pgm2)]
VOID [reduce using rule 5 (pgm2)]
STRUCT [reduce using rule 5 (pgm2)]
INT [reduce using rule 5 (pgm2)]
ID [reduce using rule 5 (pgm2)]
STRING [reduce using rule 5 (pgm2)]
$default reduce using rule 5 (pgm2)
pgm2 go to state 18
type go to state 11
return_type go to state 12
struct_ go to state 19
proc go to state 20
State 15
37 Name: ID •
$default reduce using rule 37 (Name)
State 16
21 struct_: STRUCT Name • OB declaration CB
OB shift, and go to state 21
State 17
38 proc: return_type Name • OP declaration CP OB stmt_seq CB
OP shift, and go to state 22
State 18
8 pgm: proc pgm2 •
$default reduce using rule 8 (pgm)
State 19
7 pgm2: struct_ • pgm2
BOOL shift, and go to state 3
VOID shift, and go to state 4
STRUCT shift, and go to state 5
INT shift, and go to state 6
ID shift, and go to state 7
STRING shift, and go to state 8
BOOL [reduce using rule 5 (pgm2)]
VOID [reduce using rule 5 (pgm2)]
STRUCT [reduce using rule 5 (pgm2)]
INT [reduce using rule 5 (pgm2)]
ID [reduce using rule 5 (pgm2)]
STRING [reduce using rule 5 (pgm2)]
$default reduce using rule 5 (pgm2)
pgm2 go to state 23
type go to state 11
return_type go to state 12
struct_ go to state 19
proc go to state 20
State 20
6 pgm2: proc • pgm2
BOOL shift, and go to state 3
VOID shift, and go to state 4
STRUCT shift, and go to state 5
INT shift, and go to state 6
ID shift, and go to state 7
STRING shift, and go to state 8
BOOL [reduce using rule 5 (pgm2)]
VOID [reduce using rule 5 (pgm2)]
STRUCT [reduce using rule 5 (pgm2)]
INT [reduce using rule 5 (pgm2)]
ID [reduce using rule 5 (pgm2)]
STRING [reduce using rule 5 (pgm2)]
$default reduce using rule 5 (pgm2)
pgm2 go to state 24
type go to state 11
return_type go to state 12
struct_ go to state 19
proc go to state 20
State 21
21 struct_: STRUCT Name OB • declaration CB
BOOL shift, and go to state 3
INT shift, and go to state 6
ID shift, and go to state 7
STRING shift, and go to state 8
type go to state 25
declaration go to state 26
State 22
38 proc: return_type Name OP • declaration CP OB stmt_seq CB
BOOL shift, and go to state 3
INT shift, and go to state 6
ID shift, and go to state 7
STRING shift, and go to state 8
type go to state 25
declaration go to state 27
State 23
7 pgm2: struct_ pgm2 •
$default reduce using rule 7 (pgm2)
State 24
6 pgm2: proc pgm2 •
$default reduce using rule 6 (pgm2)
State 25
17 declaration: type • ID
ID shift, and go to state 28
State 26
18 declaration: declaration • COMMA declaration
21 struct_: STRUCT Name OB declaration • CB
CB shift, and go to state 29
COMMA shift, and go to state 30
State 27
18 declaration: declaration • COMMA declaration
38 proc: return_type Name OP declaration • CP OB stmt_seq CB
CP shift, and go to state 31
COMMA shift, and go to state 30
State 28
17 declaration: type ID •
$default reduce using rule 17 (declaration)
State 29
21 struct_: STRUCT Name OB declaration CB •
$default reduce using rule 21 (struct_)
State 30
18 declaration: declaration COMMA • declaration
BOOL shift, and go to state 3
INT shift, and go to state 6
ID shift, and go to state 7
STRING shift, and go to state 8
type go to state 25
declaration go to state 32
State 31
38 proc: return_type Name OP declaration CP • OB stmt_seq CB
OB shift, and go to state 33
State 32
18 declaration: declaration • COMMA declaration
18 | declaration COMMA declaration •
COMMA shift, and go to state 30
COMMA [reduce using rule 18 (declaration)]
$default reduce using rule 18 (declaration)
State 33
38 proc: return_type Name OP declaration CP OB • stmt_seq CB
BOOL shift, and go to state 3
PRINTF shift, and go to state 34
IF shift, and go to state 35
FOR shift, and go to state 36
RETURN shift, and go to state 37
INT shift, and go to state 6
ID shift, and go to state 38
STRING shift, and go to state 8
OB shift, and go to state 39
$default reduce using rule 35 (stmt_seq)
type go to state 40
l_exp go to state 41
FOR_LOOP go to state 42
stmt go to state 43
stmt_seq go to state 44
State 34
30 stmt: PRINTF • OP STRING CP SEMICOLON
OP shift, and go to state 45
State 35
28 stmt: IF • OP exp CP intern_scope_then stmt
29 | IF • OP exp CP intern_scope_then stmt intern_scope_else stmt
OP shift, and go to state 46
State 36
26 FOR_LOOP: FOR •
$default reduce using rule 26 (FOR_LOOP)
State 37
31 stmt: RETURN • exp SEMICOLON
NUMBER shift, and go to state 47
$default reduce using rule 10 (exp)
exp go to state 48
int_literal go to state 49
State 38
16 type: ID •
22 l_exp: ID •
23 | ID • DOT l_exp
DOT shift, and go to state 50
ASSIGN reduce using rule 22 (l_exp)
$default reduce using rule 16 (type)
State 39
32 stmt: OB • stmt_seq CB
BOOL shift, and go to state 3
PRINTF shift, and go to state 34
IF shift, and go to state 35
FOR shift, and go to state 36
RETURN shift, and go to state 37
INT shift, and go to state 6
ID shift, and go to state 38
STRING shift, and go to state 8
OB shift, and go to state 39
$default reduce using rule 35 (stmt_seq)
type go to state 40
l_exp go to state 41
FOR_LOOP go to state 42
stmt go to state 43
stmt_seq go to state 51
State 40
33 stmt: type • ID SEMICOLON
ID shift, and go to state 52
State 41
34 stmt: l_exp • ASSIGN exp SEMICOLON
ASSIGN shift, and go to state 53
State 42
27 stmt: FOR_LOOP • OP ID ASSIGN exp SEMICOLON exp SEMICOLON stmt CP stmt
OP shift, and go to state 54
State 43
36 stmt_seq: stmt • stmt_seq
BOOL shift, and go to state 3
PRINTF shift, and go to state 34
IF shift, and go to state 35
FOR shift, and go to state 36
RETURN shift, and go to state 37
INT shift, and go to state 6
ID shift, and go to state 38
STRING shift, and go to state 8
OB shift, and go to state 39
$default reduce using rule 35 (stmt_seq)
type go to state 40
l_exp go to state 41
FOR_LOOP go to state 42
stmt go to state 43
stmt_seq go to state 55
State 44
38 proc: return_type Name OP declaration CP OB stmt_seq • CB
CB shift, and go to state 56
State 45
30 stmt: PRINTF OP • STRING CP SEMICOLON
STRING shift, and go to state 57
State 46
28 stmt: IF OP • exp CP intern_scope_then stmt
29 | IF OP • exp CP intern_scope_then stmt intern_scope_else stmt
NUMBER shift, and go to state 47
$default reduce using rule 10 (exp)
exp go to state 58
int_literal go to state 49
State 47
12 int_literal: NUMBER •
$default reduce using rule 12 (int_literal)
State 48
31 stmt: RETURN exp • SEMICOLON
SEMICOLON shift, and go to state 59
State 49
11 exp: int_literal •
$default reduce using rule 11 (exp)
State 50
23 l_exp: ID DOT • l_exp
ID shift, and go to state 60
l_exp go to state 61
State 51
32 stmt: OB stmt_seq • CB
CB shift, and go to state 62
State 52
33 stmt: type ID • SEMICOLON
SEMICOLON shift, and go to state 63
State 53
34 stmt: l_exp ASSIGN • exp SEMICOLON
NUMBER shift, and go to state 47
$default reduce using rule 10 (exp)
exp go to state 64
int_literal go to state 49
State 54
27 stmt: FOR_LOOP OP • ID ASSIGN exp SEMICOLON exp SEMICOLON stmt CP stmt
ID shift, and go to state 65
State 55
36 stmt_seq: stmt stmt_seq •
$default reduce using rule 36 (stmt_seq)
State 56
38 proc: return_type Name OP declaration CP OB stmt_seq CB •
$default reduce using rule 38 (proc)
State 57
30 stmt: PRINTF OP STRING • CP SEMICOLON
CP shift, and go to state 66
State 58
28 stmt: IF OP exp • CP intern_scope_then stmt
29 | IF OP exp • CP intern_scope_then stmt intern_scope_else stmt
CP shift, and go to state 67
State 59
31 stmt: RETURN exp SEMICOLON •
$default reduce using rule 31 (stmt)
State 60
22 l_exp: ID •
23 | ID • DOT l_exp
DOT shift, and go to state 50
$default reduce using rule 22 (l_exp)
State 61
23 l_exp: ID DOT l_exp •
$default reduce using rule 23 (l_exp)
State 62
32 stmt: OB stmt_seq CB •
$default reduce using rule 32 (stmt)
State 63
33 stmt: type ID SEMICOLON •
$default reduce using rule 33 (stmt)
State 64
34 stmt: l_exp ASSIGN exp • SEMICOLON
SEMICOLON shift, and go to state 68
State 65
27 stmt: FOR_LOOP OP ID • ASSIGN exp SEMICOLON exp SEMICOLON stmt CP stmt
ASSIGN shift, and go to state 69
State 66
30 stmt: PRINTF OP STRING CP • SEMICOLON
SEMICOLON shift, and go to state 70
State 67
28 stmt: IF OP exp CP • intern_scope_then stmt
29 | IF OP exp CP • intern_scope_then stmt intern_scope_else stmt
THEN shift, and go to state 71
intern_scope_then go to state 72
State 68
34 stmt: l_exp ASSIGN exp SEMICOLON •
$default reduce using rule 34 (stmt)
State 69
27 stmt: FOR_LOOP OP ID ASSIGN • exp SEMICOLON exp SEMICOLON stmt CP stmt
NUMBER shift, and go to state 47
$default reduce using rule 10 (exp)
exp go to state 73
int_literal go to state 49
State 70
30 stmt: PRINTF OP STRING CP SEMICOLON •
$default reduce using rule 30 (stmt)
State 71
24 intern_scope_then: THEN •
$default reduce using rule 24 (intern_scope_then)
State 72
28 stmt: IF OP exp CP intern_scope_then • stmt
29 | IF OP exp CP intern_scope_then • stmt intern_scope_else stmt
BOOL shift, and go to state 3
PRINTF shift, and go to state 34
IF shift, and go to state 35
FOR shift, and go to state 36
RETURN shift, and go to state 37
INT shift, and go to state 6
ID shift, and go to state 38
STRING shift, and go to state 8
OB shift, and go to state 39
type go to state 40
l_exp go to state 41
FOR_LOOP go to state 42
stmt go to state 74
State 73
27 stmt: FOR_LOOP OP ID ASSIGN exp • SEMICOLON exp SEMICOLON stmt CP stmt
SEMICOLON shift, and go to state 75
State 74
28 stmt: IF OP exp CP intern_scope_then stmt •
29 | IF OP exp CP intern_scope_then stmt • intern_scope_else stmt
ELSE shift, and go to state 76
ELSE [reduce using rule 28 (stmt)]
$default reduce using rule 28 (stmt)
intern_scope_else go to state 77
State 75
27 stmt: FOR_LOOP OP ID ASSIGN exp SEMICOLON • exp SEMICOLON stmt CP stmt
NUMBER shift, and go to state 47
$default reduce using rule 10 (exp)
exp go to state 78
int_literal go to state 49
State 76
25 intern_scope_else: ELSE •
$default reduce using rule 25 (intern_scope_else)
State 77
29 stmt: IF OP exp CP intern_scope_then stmt intern_scope_else • stmt
BOOL shift, and go to state 3
PRINTF shift, and go to state 34
IF shift, and go to state 35
FOR shift, and go to state 36
RETURN shift, and go to state 37
INT shift, and go to state 6
ID shift, and go to state 38
STRING shift, and go to state 8
OB shift, and go to state 39
type go to state 40
l_exp go to state 41
FOR_LOOP go to state 42
stmt go to state 79
State 78
27 stmt: FOR_LOOP OP ID ASSIGN exp SEMICOLON exp • SEMICOLON stmt CP stmt
SEMICOLON shift, and go to state 80
State 79
29 stmt: IF OP exp CP intern_scope_then stmt intern_scope_else stmt •
$default reduce using rule 29 (stmt)
State 80
27 stmt: FOR_LOOP OP ID ASSIGN exp SEMICOLON exp SEMICOLON • stmt CP stmt
BOOL shift, and go to state 3
PRINTF shift, and go to state 34