This repository has been archived by the owner on Jul 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.info
839 lines (594 loc) · 23.2 KB
/
Parser.info
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
-----------------------------------------------------------------------------
Info file generated by Happy Version 1.19.5 from Parser.y
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Grammar
-----------------------------------------------------------------------------
%start_parse -> Program (0)
Program -> DeclarationList StatementList eof (1)
Type -> float (2)
Type -> string (3)
Type -> int (4)
Declaration -> var Id ":" Type ";" (5)
DeclarationList -> Declaration (6)
DeclarationList -> DeclarationList Declaration (7)
StatementList -> Statement (8)
StatementList -> StatementList Statement (9)
Statement -> if Exp then StatementList endif (10)
Statement -> if Exp then StatementList else StatementList endif (11)
Statement -> while Exp do StatementList done (12)
Statement -> print Exp ";" (13)
Statement -> read Id ";" (14)
Statement -> Id "=" Exp ";" (15)
Exp -> Exp "+" Term (16)
Exp -> Exp "-" Term (17)
Exp -> Term (18)
Term -> Term "*" Factor (19)
Term -> Term "/" Factor (20)
Term -> Factor (21)
Factor -> "(" Exp ")" (22)
Factor -> "-" Factor (23)
Factor -> Float_Literal (24)
Factor -> String_Literal (25)
Factor -> Integer_Literal (26)
Factor -> Id (27)
-----------------------------------------------------------------------------
Terminals
-----------------------------------------------------------------------------
int { TIntType _ }
float { TFloatType _ }
string { TStringType _ }
Integer_Literal{ TIntLit _ $$ }
Float_Literal { TFloatLit _ $$ }
String_Literal { TStringLit _ $$ }
var { TVar _ }
if { TIf _ }
then { TThen _ }
else { TElse _ }
endif { TEndif _ }
while { TWhile _ }
do { TDo _ }
done { TDone _ }
"=" { TEquals _ }
";" { TSemiColon _ }
":" { TColon _ }
"+" { TPlus _ }
"-" { TMinus _ }
"*" { TStar _ }
"/" { TSlash _ }
"(" { TLeftParen _ }
")" { TRightParen _ }
print { TPrint _ }
read { TRead _ }
Id { TId _ $$ }
eof { TEOF _ }
-----------------------------------------------------------------------------
Non-terminals
-----------------------------------------------------------------------------
%start_parse rule 0
Program rule 1
Type rules 2, 3, 4
Declaration rule 5
DeclarationList rules 6, 7
StatementList rules 8, 9
Statement rules 10, 11, 12, 13, 14, 15
Exp rules 16, 17, 18
Term rules 19, 20, 21
Factor rules 22, 23, 24, 25, 26, 27
-----------------------------------------------------------------------------
States
-----------------------------------------------------------------------------
State 0
var shift, and enter state 4
Program goto state 5
Declaration goto state 2
DeclarationListgoto state 3
State 1
var shift, and enter state 4
Declaration goto state 2
DeclarationListgoto state 3
State 2
DeclarationList -> Declaration . (rule 6)
var reduce using rule 6
if reduce using rule 6
while reduce using rule 6
print reduce using rule 6
read reduce using rule 6
Id reduce using rule 6
State 3
Program -> DeclarationList . StatementList eof (rule 1)
DeclarationList -> DeclarationList . Declaration (rule 7)
var shift, and enter state 4
if shift, and enter state 10
while shift, and enter state 11
print shift, and enter state 12
read shift, and enter state 13
Id shift, and enter state 14
Declaration goto state 7
StatementList goto state 8
Statement goto state 9
State 4
Declaration -> var . Id ":" Type ";" (rule 5)
Id shift, and enter state 6
State 5
%start_parse -> Program . (rule 0)
%eof accept
State 6
Declaration -> var Id . ":" Type ";" (rule 5)
":" shift, and enter state 30
State 7
DeclarationList -> DeclarationList Declaration . (rule 7)
var reduce using rule 7
if reduce using rule 7
while reduce using rule 7
print reduce using rule 7
read reduce using rule 7
Id reduce using rule 7
State 8
Program -> DeclarationList StatementList . eof (rule 1)
StatementList -> StatementList . Statement (rule 9)
if shift, and enter state 10
while shift, and enter state 11
print shift, and enter state 12
read shift, and enter state 13
Id shift, and enter state 14
eof shift, and enter state 29
Statement goto state 28
State 9
StatementList -> Statement . (rule 8)
if reduce using rule 8
else reduce using rule 8
endif reduce using rule 8
while reduce using rule 8
done reduce using rule 8
print reduce using rule 8
read reduce using rule 8
Id reduce using rule 8
eof reduce using rule 8
State 10
Statement -> if . Exp then StatementList endif (rule 10)
Statement -> if . Exp then StatementList else StatementList endif (rule 11)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Exp goto state 27
Term goto state 18
Factor goto state 19
State 11
Statement -> while . Exp do StatementList done (rule 12)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Exp goto state 26
Term goto state 18
Factor goto state 19
State 12
Statement -> print . Exp ";" (rule 13)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Exp goto state 17
Term goto state 18
Factor goto state 19
State 13
Statement -> read . Id ";" (rule 14)
Id shift, and enter state 16
State 14
Statement -> Id . "=" Exp ";" (rule 15)
"=" shift, and enter state 15
State 15
Statement -> Id "=" . Exp ";" (rule 15)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Exp goto state 45
Term goto state 18
Factor goto state 19
State 16
Statement -> read Id . ";" (rule 14)
";" shift, and enter state 44
State 17
Statement -> print Exp . ";" (rule 13)
Exp -> Exp . "+" Term (rule 16)
Exp -> Exp . "-" Term (rule 17)
";" shift, and enter state 43
"+" shift, and enter state 36
"-" shift, and enter state 37
State 18
Exp -> Term . (rule 18)
Term -> Term . "*" Factor (rule 19)
Term -> Term . "/" Factor (rule 20)
then reduce using rule 18
do reduce using rule 18
";" reduce using rule 18
"+" reduce using rule 18
"-" reduce using rule 18
"*" shift, and enter state 41
"/" shift, and enter state 42
")" reduce using rule 18
State 19
Term -> Factor . (rule 21)
then reduce using rule 21
do reduce using rule 21
";" reduce using rule 21
"+" reduce using rule 21
"-" reduce using rule 21
"*" reduce using rule 21
"/" reduce using rule 21
")" reduce using rule 21
State 20
Factor -> Integer_Literal . (rule 26)
then reduce using rule 26
do reduce using rule 26
";" reduce using rule 26
"+" reduce using rule 26
"-" reduce using rule 26
"*" reduce using rule 26
"/" reduce using rule 26
")" reduce using rule 26
State 21
Factor -> Float_Literal . (rule 24)
then reduce using rule 24
do reduce using rule 24
";" reduce using rule 24
"+" reduce using rule 24
"-" reduce using rule 24
"*" reduce using rule 24
"/" reduce using rule 24
")" reduce using rule 24
State 22
Factor -> String_Literal . (rule 25)
then reduce using rule 25
do reduce using rule 25
";" reduce using rule 25
"+" reduce using rule 25
"-" reduce using rule 25
"*" reduce using rule 25
"/" reduce using rule 25
")" reduce using rule 25
State 23
Factor -> "-" . Factor (rule 23)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Factor goto state 40
State 24
Factor -> "(" . Exp ")" (rule 22)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Exp goto state 39
Term goto state 18
Factor goto state 19
State 25
Factor -> Id . (rule 27)
then reduce using rule 27
do reduce using rule 27
";" reduce using rule 27
"+" reduce using rule 27
"-" reduce using rule 27
"*" reduce using rule 27
"/" reduce using rule 27
")" reduce using rule 27
State 26
Statement -> while Exp . do StatementList done (rule 12)
Exp -> Exp . "+" Term (rule 16)
Exp -> Exp . "-" Term (rule 17)
do shift, and enter state 38
"+" shift, and enter state 36
"-" shift, and enter state 37
State 27
Statement -> if Exp . then StatementList endif (rule 10)
Statement -> if Exp . then StatementList else StatementList endif (rule 11)
Exp -> Exp . "+" Term (rule 16)
Exp -> Exp . "-" Term (rule 17)
then shift, and enter state 35
"+" shift, and enter state 36
"-" shift, and enter state 37
State 28
StatementList -> StatementList Statement . (rule 9)
if reduce using rule 9
else reduce using rule 9
endif reduce using rule 9
while reduce using rule 9
done reduce using rule 9
print reduce using rule 9
read reduce using rule 9
Id reduce using rule 9
eof reduce using rule 9
State 29
Program -> DeclarationList StatementList eof . (rule 1)
%eof reduce using rule 1
State 30
Declaration -> var Id ":" . Type ";" (rule 5)
int shift, and enter state 32
float shift, and enter state 33
string shift, and enter state 34
Type goto state 31
State 31
Declaration -> var Id ":" Type . ";" (rule 5)
";" shift, and enter state 54
State 32
Type -> int . (rule 4)
";" reduce using rule 4
State 33
Type -> float . (rule 2)
";" reduce using rule 2
State 34
Type -> string . (rule 3)
";" reduce using rule 3
State 35
Statement -> if Exp then . StatementList endif (rule 10)
Statement -> if Exp then . StatementList else StatementList endif (rule 11)
if shift, and enter state 10
while shift, and enter state 11
print shift, and enter state 12
read shift, and enter state 13
Id shift, and enter state 14
StatementList goto state 53
Statement goto state 9
State 36
Exp -> Exp "+" . Term (rule 16)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Term goto state 52
Factor goto state 19
State 37
Exp -> Exp "-" . Term (rule 17)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Term goto state 51
Factor goto state 19
State 38
Statement -> while Exp do . StatementList done (rule 12)
if shift, and enter state 10
while shift, and enter state 11
print shift, and enter state 12
read shift, and enter state 13
Id shift, and enter state 14
StatementList goto state 50
Statement goto state 9
State 39
Exp -> Exp . "+" Term (rule 16)
Exp -> Exp . "-" Term (rule 17)
Factor -> "(" Exp . ")" (rule 22)
"+" shift, and enter state 36
"-" shift, and enter state 37
")" shift, and enter state 49
State 40
Factor -> "-" Factor . (rule 23)
then reduce using rule 23
do reduce using rule 23
";" reduce using rule 23
"+" reduce using rule 23
"-" reduce using rule 23
"*" reduce using rule 23
"/" reduce using rule 23
")" reduce using rule 23
State 41
Term -> Term "*" . Factor (rule 19)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Factor goto state 48
State 42
Term -> Term "/" . Factor (rule 20)
Integer_Literalshift, and enter state 20
Float_Literal shift, and enter state 21
String_Literal shift, and enter state 22
"-" shift, and enter state 23
"(" shift, and enter state 24
Id shift, and enter state 25
Factor goto state 47
State 43
Statement -> print Exp ";" . (rule 13)
if reduce using rule 13
else reduce using rule 13
endif reduce using rule 13
while reduce using rule 13
done reduce using rule 13
print reduce using rule 13
read reduce using rule 13
Id reduce using rule 13
eof reduce using rule 13
State 44
Statement -> read Id ";" . (rule 14)
if reduce using rule 14
else reduce using rule 14
endif reduce using rule 14
while reduce using rule 14
done reduce using rule 14
print reduce using rule 14
read reduce using rule 14
Id reduce using rule 14
eof reduce using rule 14
State 45
Statement -> Id "=" Exp . ";" (rule 15)
Exp -> Exp . "+" Term (rule 16)
Exp -> Exp . "-" Term (rule 17)
";" shift, and enter state 46
"+" shift, and enter state 36
"-" shift, and enter state 37
State 46
Statement -> Id "=" Exp ";" . (rule 15)
if reduce using rule 15
else reduce using rule 15
endif reduce using rule 15
while reduce using rule 15
done reduce using rule 15
print reduce using rule 15
read reduce using rule 15
Id reduce using rule 15
eof reduce using rule 15
State 47
Term -> Term "/" Factor . (rule 20)
then reduce using rule 20
do reduce using rule 20
";" reduce using rule 20
"+" reduce using rule 20
"-" reduce using rule 20
"*" reduce using rule 20
"/" reduce using rule 20
")" reduce using rule 20
State 48
Term -> Term "*" Factor . (rule 19)
then reduce using rule 19
do reduce using rule 19
";" reduce using rule 19
"+" reduce using rule 19
"-" reduce using rule 19
"*" reduce using rule 19
"/" reduce using rule 19
")" reduce using rule 19
State 49
Factor -> "(" Exp ")" . (rule 22)
then reduce using rule 22
do reduce using rule 22
";" reduce using rule 22
"+" reduce using rule 22
"-" reduce using rule 22
"*" reduce using rule 22
"/" reduce using rule 22
")" reduce using rule 22
State 50
StatementList -> StatementList . Statement (rule 9)
Statement -> while Exp do StatementList . done (rule 12)
if shift, and enter state 10
while shift, and enter state 11
done shift, and enter state 57
print shift, and enter state 12
read shift, and enter state 13
Id shift, and enter state 14
Statement goto state 28
State 51
Exp -> Exp "-" Term . (rule 17)
Term -> Term . "*" Factor (rule 19)
Term -> Term . "/" Factor (rule 20)
then reduce using rule 17
do reduce using rule 17
";" reduce using rule 17
"+" reduce using rule 17
"-" reduce using rule 17
"*" shift, and enter state 41
"/" shift, and enter state 42
")" reduce using rule 17
State 52
Exp -> Exp "+" Term . (rule 16)
Term -> Term . "*" Factor (rule 19)
Term -> Term . "/" Factor (rule 20)
then reduce using rule 16
do reduce using rule 16
";" reduce using rule 16
"+" reduce using rule 16
"-" reduce using rule 16
"*" shift, and enter state 41
"/" shift, and enter state 42
")" reduce using rule 16
State 53
StatementList -> StatementList . Statement (rule 9)
Statement -> if Exp then StatementList . endif (rule 10)
Statement -> if Exp then StatementList . else StatementList endif (rule 11)
if shift, and enter state 10
else shift, and enter state 55
endif shift, and enter state 56
while shift, and enter state 11
print shift, and enter state 12
read shift, and enter state 13
Id shift, and enter state 14
Statement goto state 28
State 54
Declaration -> var Id ":" Type ";" . (rule 5)
var reduce using rule 5
if reduce using rule 5
while reduce using rule 5
print reduce using rule 5
read reduce using rule 5
Id reduce using rule 5
State 55
Statement -> if Exp then StatementList else . StatementList endif (rule 11)
if shift, and enter state 10
while shift, and enter state 11
print shift, and enter state 12
read shift, and enter state 13
Id shift, and enter state 14
StatementList goto state 58
Statement goto state 9
State 56
Statement -> if Exp then StatementList endif . (rule 10)
if reduce using rule 10
else reduce using rule 10
endif reduce using rule 10
while reduce using rule 10
done reduce using rule 10
print reduce using rule 10
read reduce using rule 10
Id reduce using rule 10
eof reduce using rule 10
State 57
Statement -> while Exp do StatementList done . (rule 12)
if reduce using rule 12
else reduce using rule 12
endif reduce using rule 12
while reduce using rule 12
done reduce using rule 12
print reduce using rule 12
read reduce using rule 12
Id reduce using rule 12
eof reduce using rule 12
State 58
StatementList -> StatementList . Statement (rule 9)
Statement -> if Exp then StatementList else StatementList . endif (rule 11)
if shift, and enter state 10
endif shift, and enter state 59
while shift, and enter state 11
print shift, and enter state 12
read shift, and enter state 13
Id shift, and enter state 14
Statement goto state 28
State 59
Statement -> if Exp then StatementList else StatementList endif . (rule 11)
if reduce using rule 11
else reduce using rule 11
endif reduce using rule 11
while reduce using rule 11
done reduce using rule 11
print reduce using rule 11
read reduce using rule 11
Id reduce using rule 11
eof reduce using rule 11
-----------------------------------------------------------------------------
Grammar Totals
-----------------------------------------------------------------------------
Number of rules: 28
Number of terminals: 27
Number of non-terminals: 10
Number of states: 60