-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathy.output
1323 lines (811 loc) · 27.1 KB
/
y.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
AND
OR
State 46 conflicts: 9 shift/reduce
State 62 conflicts: 2 reduce/reduce
State 93 conflicts: 4 shift/reduce
Grammar
0 $accept: program $end
1 program: declaration
2 | program declaration
3 declaration: function_definition
4 function_definition: datatype ID '(' arguments_definition ')' '{' body return '}'
5 arguments_definition: argument_definition
6 | arguments_definition ',' argument_definition
7 argument_definition: datatype ID
8 datatype: INT
9 | FLOAT
10 | CHAR
11 | VOID
12 body: FOR '(' statement ';' condition ';' statement ')' '{' body '}'
13 | WHILE '(' statement ')' '{' body '}'
14 | IF '(' condition ')' '{' body '}' else
15 | statement ';'
16 | body body
17 | predefined_function ';'
18 | defined_function ';'
19 predefined_function: PUTCHAR '(' STRING ')'
20 defined_function: ID '(' arguments_expression ')'
21 arguments_expression: argument_expression
22 | argument_expression ',' arguments_expression
23 argument_expression: ID
24 | value
25 else: ELSE '{' body '}'
26 | ε
27 condition: value relop value
28 | TRUE
29 | FALSE
30 statement: datatype ID init
31 | ID '=' expression
32 | ID relop expression
33 init: '=' value
34 | ε
35 expression: expression arithmetic expression
36 | value
37 arithmetic: ADD
38 | SUB
39 | MUL
40 | DIV
41 relop: LT
42 | GT
43 | LE
44 | GE
45 | EQ
46 | NE
47 value: NUMBER
48 | FLOAT_NUM
49 | CHARACTER
50 | ID
51 return: RETURN value ';'
52 | ε
Terminals, with rules where they appear
$end (0) 0
'(' (40) 4 12 13 14 19 20
')' (41) 4 12 13 14 19 20
',' (44) 6 22
';' (59) 12 15 17 18 51
'=' (61) 31 33
'{' (123) 4 12 13 14 25
'}' (125) 4 12 13 14 25
error (256)
INT (258) 8
FLOAT (259) 9
CHAR (260) 10
VOID (261) 11
RETURN (262) 51
FOR (263) 12
WHILE (264) 13
IF (265) 14
ELSE (266) 25
LT (267) 41
GT (268) 42
LE (269) 43
GE (270) 44
EQ (271) 45
NE (272) 46
AND (273)
OR (274)
ADD (275) 37
SUB (276) 38
DIV (277) 40
MUL (278) 39
TRUE (279) 28
FALSE (280) 29
NUMBER (281) 47
FLOAT_NUM (282) 48
ID (283) 4 7 20 23 30 31 32 50
STRING (284) 19
CHARACTER (285) 49
PUTCHAR (286) 19
Nonterminals, with rules where they appear
$accept (39)
on left: 0
program (40)
on left: 1 2
on right: 0 2
declaration (41)
on left: 3
on right: 1 2
function_definition (42)
on left: 4
on right: 3
arguments_definition (43)
on left: 5 6
on right: 4 6
argument_definition (44)
on left: 7
on right: 5 6
datatype (45)
on left: 8 9 10 11
on right: 4 7 30
body (46)
on left: 12 13 14 15 16 17 18
on right: 4 12 13 14 16 25
predefined_function (47)
on left: 19
on right: 17
defined_function (48)
on left: 20
on right: 18
arguments_expression (49)
on left: 21 22
on right: 20 22
argument_expression (50)
on left: 23 24
on right: 21 22
else (51)
on left: 25 26
on right: 14
condition (52)
on left: 27 28 29
on right: 12 14
statement (53)
on left: 30 31 32
on right: 12 13 15
init (54)
on left: 33 34
on right: 30
expression (55)
on left: 35 36
on right: 31 32 35
arithmetic (56)
on left: 37 38 39 40
on right: 35
relop (57)
on left: 41 42 43 44 45 46
on right: 27 32
value (58)
on left: 47 48 49 50
on right: 24 27 33 36 51
return (59)
on left: 51 52
on right: 4
State 0
0 $accept: • program $end
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
program go to state 5
declaration go to state 6
function_definition go to state 7
datatype go to state 8
State 1
8 datatype: INT •
$default reduce using rule 8 (datatype)
State 2
9 datatype: FLOAT •
$default reduce using rule 9 (datatype)
State 3
10 datatype: CHAR •
$default reduce using rule 10 (datatype)
State 4
11 datatype: VOID •
$default reduce using rule 11 (datatype)
State 5
0 $accept: program • $end
2 program: program • declaration
$end shift, and go to state 9
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
declaration go to state 10
function_definition go to state 7
datatype go to state 8
State 6
1 program: declaration •
$default reduce using rule 1 (program)
State 7
3 declaration: function_definition •
$default reduce using rule 3 (declaration)
State 8
4 function_definition: datatype • ID '(' arguments_definition ')' '{' body return '}'
ID shift, and go to state 11
State 9
0 $accept: program $end •
$default accept
State 10
2 program: program declaration •
$default reduce using rule 2 (program)
State 11
4 function_definition: datatype ID • '(' arguments_definition ')' '{' body return '}'
'(' shift, and go to state 12
State 12
4 function_definition: datatype ID '(' • arguments_definition ')' '{' body return '}'
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
arguments_definition go to state 13
argument_definition go to state 14
datatype go to state 15
State 13
4 function_definition: datatype ID '(' arguments_definition • ')' '{' body return '}'
6 arguments_definition: arguments_definition • ',' argument_definition
')' shift, and go to state 16
',' shift, and go to state 17
State 14
5 arguments_definition: argument_definition •
$default reduce using rule 5 (arguments_definition)
State 15
7 argument_definition: datatype • ID
ID shift, and go to state 18
State 16
4 function_definition: datatype ID '(' arguments_definition ')' • '{' body return '}'
'{' shift, and go to state 19
State 17
6 arguments_definition: arguments_definition ',' • argument_definition
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
argument_definition go to state 20
datatype go to state 15
State 18
7 argument_definition: datatype ID •
$default reduce using rule 7 (argument_definition)
State 19
4 function_definition: datatype ID '(' arguments_definition ')' '{' • body return '}'
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
FOR shift, and go to state 21
WHILE shift, and go to state 22
IF shift, and go to state 23
ID shift, and go to state 24
PUTCHAR shift, and go to state 25
datatype go to state 26
body go to state 27
predefined_function go to state 28
defined_function go to state 29
statement go to state 30
State 20
6 arguments_definition: arguments_definition ',' argument_definition •
$default reduce using rule 6 (arguments_definition)
State 21
12 body: FOR • '(' statement ';' condition ';' statement ')' '{' body '}'
'(' shift, and go to state 31
State 22
13 body: WHILE • '(' statement ')' '{' body '}'
'(' shift, and go to state 32
State 23
14 body: IF • '(' condition ')' '{' body '}' else
'(' shift, and go to state 33
State 24
20 defined_function: ID • '(' arguments_expression ')'
31 statement: ID • '=' expression
32 | ID • relop expression
LT shift, and go to state 34
GT shift, and go to state 35
LE shift, and go to state 36
GE shift, and go to state 37
EQ shift, and go to state 38
NE shift, and go to state 39
'(' shift, and go to state 40
'=' shift, and go to state 41
relop go to state 42
State 25
19 predefined_function: PUTCHAR • '(' STRING ')'
'(' shift, and go to state 43
State 26
30 statement: datatype • ID init
ID shift, and go to state 44
State 27
4 function_definition: datatype ID '(' arguments_definition ')' '{' body • return '}'
16 body: body • body
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
RETURN shift, and go to state 45
FOR shift, and go to state 21
WHILE shift, and go to state 22
IF shift, and go to state 23
ID shift, and go to state 24
PUTCHAR shift, and go to state 25
$default reduce using rule 52 (return)
datatype go to state 26
body go to state 46
predefined_function go to state 28
defined_function go to state 29
statement go to state 30
return go to state 47
State 28
17 body: predefined_function • ';'
';' shift, and go to state 48
State 29
18 body: defined_function • ';'
';' shift, and go to state 49
State 30
15 body: statement • ';'
';' shift, and go to state 50
State 31
12 body: FOR '(' • statement ';' condition ';' statement ')' '{' body '}'
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
ID shift, and go to state 51
datatype go to state 26
statement go to state 52
State 32
13 body: WHILE '(' • statement ')' '{' body '}'
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
ID shift, and go to state 51
datatype go to state 26
statement go to state 53
State 33
14 body: IF '(' • condition ')' '{' body '}' else
TRUE shift, and go to state 54
FALSE shift, and go to state 55
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 58
CHARACTER shift, and go to state 59
condition go to state 60
value go to state 61
State 34
41 relop: LT •
$default reduce using rule 41 (relop)
State 35
42 relop: GT •
$default reduce using rule 42 (relop)
State 36
43 relop: LE •
$default reduce using rule 43 (relop)
State 37
44 relop: GE •
$default reduce using rule 44 (relop)
State 38
45 relop: EQ •
$default reduce using rule 45 (relop)
State 39
46 relop: NE •
$default reduce using rule 46 (relop)
State 40
20 defined_function: ID '(' • arguments_expression ')'
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 62
CHARACTER shift, and go to state 59
arguments_expression go to state 63
argument_expression go to state 64
value go to state 65
State 41
31 statement: ID '=' • expression
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 58
CHARACTER shift, and go to state 59
expression go to state 66
value go to state 67
State 42
32 statement: ID relop • expression
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 58
CHARACTER shift, and go to state 59
expression go to state 68
value go to state 67
State 43
19 predefined_function: PUTCHAR '(' • STRING ')'
STRING shift, and go to state 69
State 44
30 statement: datatype ID • init
'=' shift, and go to state 70
$default reduce using rule 34 (init)
init go to state 71
State 45
51 return: RETURN • value ';'
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 58
CHARACTER shift, and go to state 59
value go to state 72
State 46
16 body: body • body
16 | body body •
INT shift, and go to state 1
FLOAT shift, and go to state 2
CHAR shift, and go to state 3
VOID shift, and go to state 4
FOR shift, and go to state 21
WHILE shift, and go to state 22
IF shift, and go to state 23
ID shift, and go to state 24
PUTCHAR shift, and go to state 25
INT [reduce using rule 16 (body)]
FLOAT [reduce using rule 16 (body)]
CHAR [reduce using rule 16 (body)]
VOID [reduce using rule 16 (body)]
FOR [reduce using rule 16 (body)]
WHILE [reduce using rule 16 (body)]
IF [reduce using rule 16 (body)]
ID [reduce using rule 16 (body)]
PUTCHAR [reduce using rule 16 (body)]
$default reduce using rule 16 (body)
datatype go to state 26
body go to state 46
predefined_function go to state 28
defined_function go to state 29
statement go to state 30
State 47
4 function_definition: datatype ID '(' arguments_definition ')' '{' body return • '}'
'}' shift, and go to state 73
State 48
17 body: predefined_function ';' •
$default reduce using rule 17 (body)
State 49
18 body: defined_function ';' •
$default reduce using rule 18 (body)
State 50
15 body: statement ';' •
$default reduce using rule 15 (body)
State 51
31 statement: ID • '=' expression
32 | ID • relop expression
LT shift, and go to state 34
GT shift, and go to state 35
LE shift, and go to state 36
GE shift, and go to state 37
EQ shift, and go to state 38
NE shift, and go to state 39
'=' shift, and go to state 41
relop go to state 42
State 52
12 body: FOR '(' statement • ';' condition ';' statement ')' '{' body '}'
';' shift, and go to state 74
State 53
13 body: WHILE '(' statement • ')' '{' body '}'
')' shift, and go to state 75
State 54
28 condition: TRUE •
$default reduce using rule 28 (condition)
State 55
29 condition: FALSE •
$default reduce using rule 29 (condition)
State 56
47 value: NUMBER •
$default reduce using rule 47 (value)
State 57
48 value: FLOAT_NUM •
$default reduce using rule 48 (value)
State 58
50 value: ID •
$default reduce using rule 50 (value)
State 59
49 value: CHARACTER •
$default reduce using rule 49 (value)
State 60
14 body: IF '(' condition • ')' '{' body '}' else
')' shift, and go to state 76
State 61
27 condition: value • relop value
LT shift, and go to state 34
GT shift, and go to state 35
LE shift, and go to state 36
GE shift, and go to state 37
EQ shift, and go to state 38
NE shift, and go to state 39
relop go to state 77
State 62
23 argument_expression: ID •
50 value: ID •
')' reduce using rule 23 (argument_expression)
')' [reduce using rule 50 (value)]
',' reduce using rule 23 (argument_expression)
',' [reduce using rule 50 (value)]
$default reduce using rule 23 (argument_expression)
State 63
20 defined_function: ID '(' arguments_expression • ')'
')' shift, and go to state 78
State 64
21 arguments_expression: argument_expression •
22 | argument_expression • ',' arguments_expression
',' shift, and go to state 79
$default reduce using rule 21 (arguments_expression)
State 65
24 argument_expression: value •
$default reduce using rule 24 (argument_expression)
State 66
31 statement: ID '=' expression •
35 expression: expression • arithmetic expression
ADD shift, and go to state 80
SUB shift, and go to state 81
DIV shift, and go to state 82
MUL shift, and go to state 83
$default reduce using rule 31 (statement)
arithmetic go to state 84
State 67
36 expression: value •
$default reduce using rule 36 (expression)
State 68
32 statement: ID relop expression •
35 expression: expression • arithmetic expression
ADD shift, and go to state 80
SUB shift, and go to state 81
DIV shift, and go to state 82
MUL shift, and go to state 83
$default reduce using rule 32 (statement)
arithmetic go to state 84
State 69
19 predefined_function: PUTCHAR '(' STRING • ')'
')' shift, and go to state 85
State 70
33 init: '=' • value
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 58
CHARACTER shift, and go to state 59
value go to state 86
State 71
30 statement: datatype ID init •
$default reduce using rule 30 (statement)
State 72
51 return: RETURN value • ';'
';' shift, and go to state 87
State 73
4 function_definition: datatype ID '(' arguments_definition ')' '{' body return '}' •
$default reduce using rule 4 (function_definition)
State 74
12 body: FOR '(' statement ';' • condition ';' statement ')' '{' body '}'
TRUE shift, and go to state 54
FALSE shift, and go to state 55
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 58
CHARACTER shift, and go to state 59
condition go to state 88
value go to state 61
State 75
13 body: WHILE '(' statement ')' • '{' body '}'
'{' shift, and go to state 89
State 76
14 body: IF '(' condition ')' • '{' body '}' else
'{' shift, and go to state 90
State 77
27 condition: value relop • value
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 58
CHARACTER shift, and go to state 59
value go to state 91
State 78
20 defined_function: ID '(' arguments_expression ')' •
$default reduce using rule 20 (defined_function)
State 79
22 arguments_expression: argument_expression ',' • arguments_expression
NUMBER shift, and go to state 56
FLOAT_NUM shift, and go to state 57
ID shift, and go to state 62
CHARACTER shift, and go to state 59
arguments_expression go to state 92
argument_expression go to state 64
value go to state 65
State 80
37 arithmetic: ADD •
$default reduce using rule 37 (arithmetic)
State 81
38 arithmetic: SUB •
$default reduce using rule 38 (arithmetic)
State 82
40 arithmetic: DIV •
$default reduce using rule 40 (arithmetic)
State 83
39 arithmetic: MUL •
$default reduce using rule 39 (arithmetic)