-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.output
3271 lines (2091 loc) · 78.1 KB
/
syntax.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
Grammar
0 $accept: program "EOF"
1 $@1: %empty
2 program: header $@1 declarations subprograms comp_statement "."
3 header: "program" "id" ";"
4 | error "id" ";"
5 | "program" error ";"
6 | "program" "id" error
7 declarations: constdefs typedefs vardefs
8 constdefs: "const" constant_defs ";"
9 | %empty
10 constant_defs: constant_defs ";" "id" "=" expression
11 | "id" "=" expression
12 expression: expression "> or >= or < or <= or <>" expression
13 | expression "=" expression
14 | expression "in" expression
15 | expression "or" expression
16 | expression "+ or -" expression
17 | expression "* or / or div or mod or and" expression
18 | "+ or -" expression
19 | "not" expression
20 | variable
21 | "id" "(" expressions ")"
22 | constant
23 | "(" expression ")"
24 | setexpression
25 variable: "id"
26 | variable "." "id"
27 | variable "[" expressions "]"
28 expressions: expressions "," expression
29 | expression
30 constant: "iconst"
31 | "rconst"
32 | "bconst"
33 | "cconst"
34 setexpression: "[" elexpressions "]"
35 | "[" "]"
36 elexpressions: elexpressions "," elexpression
37 | elexpression
38 elexpression: expression ".." expression
39 | expression
40 typedefs: "type" type_defs ";"
41 | %empty
42 type_defs: type_defs ";" "id" "=" type_def
43 | "id" "=" type_def
44 type_def: "array" "[" dims "]" "of" typename
45 | "set" "of" typename
46 | "record" fields "end"
47 | "(" identifiers ")"
48 | limit ".." limit
49 dims: dims "," limits
50 | limits
51 limits: limit ".." limit
52 | "id"
53 limit: "+ or -" "iconst"
54 | "+ or -" "id"
55 | "iconst"
56 | "cconst"
57 | "bconst"
58 | "id"
59 typename: standard_type
60 | "id"
61 standard_type: "integer"
62 | "real"
63 | "boolean"
64 | "char"
65 fields: fields ";" field
66 | field
67 field: identifiers ":" typename
68 identifiers: identifiers "," "id"
69 | "id"
70 vardefs: "var" variable_defs ";"
71 | %empty
72 variable_defs: variable_defs ";" identifiers ":" typename
73 | identifiers ":" typename
74 subprograms: subprograms subprogram ";"
75 | %empty
76 subprogram: sub_header ";" "forward"
77 | sub_header ";" declarations subprograms comp_statement
78 sub_header: "function" "id" formal_parameters ":" standard_type
79 | "procedure" "id" formal_parameters
80 | "function" "id"
81 formal_parameters: "(" parameter_list ")"
82 | %empty
83 parameter_list: parameter_list ";" pass identifiers ":" typename
84 | pass identifiers ":" typename
85 pass: "var"
86 | %empty
87 $@2: %empty
88 comp_statement: "begin" $@2 statements "end"
89 statements: statements ";" statement
90 | statement
91 statement: assignment
92 | if_statement
93 | while_statement
94 | for_statement
95 | with_statement
96 | subprogram_call
97 | io_statement
98 | comp_statement
99 | %empty
100 assignment: variable ":=" expression
101 | variable ":=" "string"
102 | error ":=" expression
103 | variable error expression
104 | error ":=" "string"
105 | variable error "string"
106 | variable ":=" error
107 $@3: %empty
108 if_statement: "if" expression "then" $@3 statement if_tail
109 if_tail: "else" statement
110 | %empty
111 $@4: %empty
112 while_statement: "while" expression "do" $@4 statement
113 $@5: %empty
114 for_statement: "for" "id" ":=" iter_space "do" $@5 statement
115 iter_space: expression "to" expression
116 | expression "downto" expression
117 with_statement: "with" variable "do" statement
118 subprogram_call: "id"
119 | "id" "(" expressions ")"
120 io_statement: "read" "(" read_list ")"
121 | "write" "(" write_list ")"
122 read_list: read_list "," read_item
123 | read_item
124 read_item: variable
125 write_list: write_list "," write_item
126 | write_item
127 write_item: expression
128 | "string"
Terminals, with rules where they appear
"EOF" (0) 0
error (256) 4 5 6 102 103 104 105 106
"program" (258) 3 5 6
"const" (259) 8
"type" (260) 40
"array" (261) 44
"set" (262) 45
"of" (263) 44 45
"record" (264) 46
"var" (265) 70 85
"forward" (266) 76
"function" (267) 78 80
"procedure" (268) 79
"integer" (269) 61
"real" (270) 62
"boolean" (271) 63
"char" (272) 64
"begin" (273) 88
"end" (274) 46 88
"if" (275) 108
"then" (276) 108
"else" (277) 109
"while" (278) 112
"do" (279) 112 114 117
"for" (280) 114
"downto" (281) 116
"to" (282) 115
"with" (283) 117
"read" (284) 120
"write" (285) 121
"id" <strval> (286) 3 4 6 10 11 21 25 26 42 43 52 54 58 60 68 69 78 79 80 114 118 119
"iconst" <intval> (287) 30 53 55
"rconst" <floatval> (288) 31
"bconst" <boolean> (289) 32 57
"cconst" <charval> (290) 33 56
"> or >= or < or <= or <>" (291) 12
"+ or -" (292) 16 18 53 54
"or" (293) 15
"* or / or div or mod or and" (294) 17
"not" (295) 19
"in" (296) 14
"string" (297) 101 104 105 128
"(" (298) 21 23 47 81 119 120 121
")" (299) 21 23 47 81 119 120 121
";" (300) 3 4 5 8 10 40 42 65 70 72 74 76 77 83 89
"." (301) 2 26
"," (302) 28 36 49 68 122 125
"=" (303) 10 11 13 42 43
":" (304) 67 72 73 78 83 84
"[" (305) 27 34 35 44
"]" (306) 27 34 35 44
":=" (307) 100 101 102 104 106 114
".." (308) 38 48 51
LOWER_THAN_ELSE (309)
Nonterminals, with rules where they appear
$accept (55)
on left: 0
program (56)
on left: 2
on right: 0
$@1 (57)
on left: 1
on right: 2
header (58)
on left: 3 4 5 6
on right: 2
declarations (59)
on left: 7
on right: 2 77
constdefs (60)
on left: 8 9
on right: 7
constant_defs (61)
on left: 10 11
on right: 8 10
expression (62)
on left: 12 13 14 15 16 17 18 19 20 21 22 23 24
on right: 10 11 12 13 14 15 16 17 18 19 23 28 29 38 39 100 102 103 108 112 115 116 127
variable (63)
on left: 25 26 27
on right: 20 26 27 100 101 103 105 106 117 124
expressions (64)
on left: 28 29
on right: 21 27 28 119
constant (65)
on left: 30 31 32 33
on right: 22
setexpression (66)
on left: 34 35
on right: 24
elexpressions (67)
on left: 36 37
on right: 34 36
elexpression (68)
on left: 38 39
on right: 36 37
typedefs (69)
on left: 40 41
on right: 7
type_defs (70)
on left: 42 43
on right: 40 42
type_def (71)
on left: 44 45 46 47 48
on right: 42 43
dims (72)
on left: 49 50
on right: 44 49
limits (73)
on left: 51 52
on right: 49 50
limit (74)
on left: 53 54 55 56 57 58
on right: 48 51
typename (75)
on left: 59 60
on right: 44 45 67 72 73 83 84
standard_type (76)
on left: 61 62 63 64
on right: 59 78
fields (77)
on left: 65 66
on right: 46 65
field (78)
on left: 67
on right: 65 66
identifiers (79)
on left: 68 69
on right: 47 67 68 72 73 83 84
vardefs (80)
on left: 70 71
on right: 7
variable_defs (81)
on left: 72 73
on right: 70 72
subprograms (82)
on left: 74 75
on right: 2 74 77
subprogram (83)
on left: 76 77
on right: 74
sub_header (84)
on left: 78 79 80
on right: 76 77
formal_parameters (85)
on left: 81 82
on right: 78 79
parameter_list (86)
on left: 83 84
on right: 81 83
pass (87)
on left: 85 86
on right: 83 84
comp_statement (88)
on left: 88
on right: 2 77 98
$@2 (89)
on left: 87
on right: 88
statements (90)
on left: 89 90
on right: 88 89
statement (91)
on left: 91 92 93 94 95 96 97 98 99
on right: 89 90 108 109 112 114 117
assignment (92)
on left: 100 101 102 103 104 105 106
on right: 91
if_statement (93)
on left: 108
on right: 92
$@3 (94)
on left: 107
on right: 108
if_tail (95)
on left: 109 110
on right: 108
while_statement (96)
on left: 112
on right: 93
$@4 (97)
on left: 111
on right: 112
for_statement (98)
on left: 114
on right: 94
$@5 (99)
on left: 113
on right: 114
iter_space (100)
on left: 115 116
on right: 114
with_statement (101)
on left: 117
on right: 95
subprogram_call (102)
on left: 118 119
on right: 96
io_statement (103)
on left: 120 121
on right: 97
read_list (104)
on left: 122 123
on right: 120 122
read_item (105)
on left: 124
on right: 122 123
write_list (106)
on left: 125 126
on right: 121 125
write_item (107)
on left: 127 128
on right: 125 126
State 0
0 $accept: • program "EOF"
error shift, and go to state 1
"program" shift, and go to state 2
program go to state 3
header go to state 4
State 1
4 header: error • "id" ";"
"id" shift, and go to state 5
State 2
3 header: "program" • "id" ";"
5 | "program" • error ";"
6 | "program" • "id" error
error shift, and go to state 6
"id" shift, and go to state 7
State 3
0 $accept: program • "EOF"
"EOF" shift, and go to state 8
State 4
2 program: header • $@1 declarations subprograms comp_statement "."
$default reduce using rule 1 ($@1)
$@1 go to state 9
State 5
4 header: error "id" • ";"
";" shift, and go to state 10
State 6
5 header: "program" error • ";"
";" shift, and go to state 11
State 7
3 header: "program" "id" • ";"
6 | "program" "id" • error
error shift, and go to state 12
";" shift, and go to state 13
State 8
0 $accept: program "EOF" •
$default accept
State 9
2 program: header $@1 • declarations subprograms comp_statement "."
"const" shift, and go to state 14
$default reduce using rule 9 (constdefs)
declarations go to state 15
constdefs go to state 16
State 10
4 header: error "id" ";" •
$default reduce using rule 4 (header)
State 11
5 header: "program" error ";" •
$default reduce using rule 5 (header)
State 12
6 header: "program" "id" error •
$default reduce using rule 6 (header)
State 13
3 header: "program" "id" ";" •
$default reduce using rule 3 (header)
State 14
8 constdefs: "const" • constant_defs ";"
"id" shift, and go to state 17
constant_defs go to state 18
State 15
2 program: header $@1 declarations • subprograms comp_statement "."
$default reduce using rule 75 (subprograms)
subprograms go to state 19
State 16
7 declarations: constdefs • typedefs vardefs
"type" shift, and go to state 20
$default reduce using rule 41 (typedefs)
typedefs go to state 21
State 17
11 constant_defs: "id" • "=" expression
"=" shift, and go to state 22
State 18
8 constdefs: "const" constant_defs • ";"
10 constant_defs: constant_defs • ";" "id" "=" expression
";" shift, and go to state 23
State 19
2 program: header $@1 declarations subprograms • comp_statement "."
74 subprograms: subprograms • subprogram ";"
"function" shift, and go to state 24
"procedure" shift, and go to state 25
"begin" shift, and go to state 26
subprogram go to state 27
sub_header go to state 28
comp_statement go to state 29
State 20
40 typedefs: "type" • type_defs ";"
"id" shift, and go to state 30
type_defs go to state 31
State 21
7 declarations: constdefs typedefs • vardefs
"var" shift, and go to state 32
$default reduce using rule 71 (vardefs)
vardefs go to state 33
State 22
11 constant_defs: "id" "=" • expression
"id" shift, and go to state 34
"iconst" shift, and go to state 35
"rconst" shift, and go to state 36
"bconst" shift, and go to state 37
"cconst" shift, and go to state 38
"+ or -" shift, and go to state 39
"not" shift, and go to state 40
"(" shift, and go to state 41
"[" shift, and go to state 42
expression go to state 43
variable go to state 44
constant go to state 45
setexpression go to state 46
State 23
8 constdefs: "const" constant_defs ";" •
10 constant_defs: constant_defs ";" • "id" "=" expression
"id" shift, and go to state 47
$default reduce using rule 8 (constdefs)
State 24
78 sub_header: "function" • "id" formal_parameters ":" standard_type
80 | "function" • "id"
"id" shift, and go to state 48
State 25
79 sub_header: "procedure" • "id" formal_parameters
"id" shift, and go to state 49
State 26
88 comp_statement: "begin" • $@2 statements "end"
$default reduce using rule 87 ($@2)
$@2 go to state 50
State 27
74 subprograms: subprograms subprogram • ";"
";" shift, and go to state 51
State 28
76 subprogram: sub_header • ";" "forward"
77 | sub_header • ";" declarations subprograms comp_statement
";" shift, and go to state 52
State 29
2 program: header $@1 declarations subprograms comp_statement • "."
"." shift, and go to state 53
State 30
43 type_defs: "id" • "=" type_def
"=" shift, and go to state 54
State 31
40 typedefs: "type" type_defs • ";"
42 type_defs: type_defs • ";" "id" "=" type_def
";" shift, and go to state 55
State 32
70 vardefs: "var" • variable_defs ";"
"id" shift, and go to state 56
identifiers go to state 57
variable_defs go to state 58
State 33
7 declarations: constdefs typedefs vardefs •
$default reduce using rule 7 (declarations)
State 34
21 expression: "id" • "(" expressions ")"
25 variable: "id" •
"(" shift, and go to state 59
$default reduce using rule 25 (variable)
State 35
30 constant: "iconst" •
$default reduce using rule 30 (constant)
State 36
31 constant: "rconst" •
$default reduce using rule 31 (constant)
State 37
32 constant: "bconst" •
$default reduce using rule 32 (constant)
State 38
33 constant: "cconst" •
$default reduce using rule 33 (constant)
State 39
18 expression: "+ or -" • expression
"id" shift, and go to state 34
"iconst" shift, and go to state 35
"rconst" shift, and go to state 36
"bconst" shift, and go to state 37
"cconst" shift, and go to state 38
"+ or -" shift, and go to state 39
"not" shift, and go to state 40
"(" shift, and go to state 41
"[" shift, and go to state 42
expression go to state 60
variable go to state 44
constant go to state 45
setexpression go to state 46
State 40
19 expression: "not" • expression
"id" shift, and go to state 34
"iconst" shift, and go to state 35
"rconst" shift, and go to state 36
"bconst" shift, and go to state 37
"cconst" shift, and go to state 38
"+ or -" shift, and go to state 39
"not" shift, and go to state 40
"(" shift, and go to state 41
"[" shift, and go to state 42
expression go to state 61
variable go to state 44
constant go to state 45
setexpression go to state 46
State 41
23 expression: "(" • expression ")"
"id" shift, and go to state 34
"iconst" shift, and go to state 35
"rconst" shift, and go to state 36
"bconst" shift, and go to state 37
"cconst" shift, and go to state 38
"+ or -" shift, and go to state 39
"not" shift, and go to state 40
"(" shift, and go to state 41
"[" shift, and go to state 42
expression go to state 62
variable go to state 44
constant go to state 45
setexpression go to state 46
State 42
34 setexpression: "[" • elexpressions "]"
35 | "[" • "]"
"id" shift, and go to state 34
"iconst" shift, and go to state 35
"rconst" shift, and go to state 36
"bconst" shift, and go to state 37
"cconst" shift, and go to state 38
"+ or -" shift, and go to state 39
"not" shift, and go to state 40
"(" shift, and go to state 41
"[" shift, and go to state 42
"]" shift, and go to state 63
expression go to state 64
variable go to state 44
constant go to state 45
setexpression go to state 46
elexpressions go to state 65
elexpression go to state 66
State 43
11 constant_defs: "id" "=" expression •
12 expression: expression • "> or >= or < or <= or <>" expression
13 | expression • "=" expression
14 | expression • "in" expression
15 | expression • "or" expression
16 | expression • "+ or -" expression
17 | expression • "* or / or div or mod or and" expression
"> or >= or < or <= or <>" shift, and go to state 67
"+ or -" shift, and go to state 68
"or" shift, and go to state 69
"* or / or div or mod or and" shift, and go to state 70
"in" shift, and go to state 71
"=" shift, and go to state 72
$default reduce using rule 11 (constant_defs)
State 44
20 expression: variable •
26 variable: variable • "." "id"
27 | variable • "[" expressions "]"
"." shift, and go to state 73
"[" shift, and go to state 74
$default reduce using rule 20 (expression)
State 45
22 expression: constant •
$default reduce using rule 22 (expression)
State 46
24 expression: setexpression •
$default reduce using rule 24 (expression)
State 47
10 constant_defs: constant_defs ";" "id" • "=" expression
"=" shift, and go to state 75
State 48
78 sub_header: "function" "id" • formal_parameters ":" standard_type
80 | "function" "id" •
"(" shift, and go to state 76
":" reduce using rule 82 (formal_parameters)
$default reduce using rule 80 (sub_header)
formal_parameters go to state 77
State 49
79 sub_header: "procedure" "id" • formal_parameters
"(" shift, and go to state 76
$default reduce using rule 82 (formal_parameters)
formal_parameters go to state 78
State 50
88 comp_statement: "begin" $@2 • statements "end"
error shift, and go to state 79
"begin" shift, and go to state 26
"if" shift, and go to state 80
"while" shift, and go to state 81
"for" shift, and go to state 82
"with" shift, and go to state 83
"read" shift, and go to state 84
"write" shift, and go to state 85
"id" shift, and go to state 86
"end" reduce using rule 99 (statement)
";" reduce using rule 99 (statement)
variable go to state 87
comp_statement go to state 88
statements go to state 89
statement go to state 90
assignment go to state 91
if_statement go to state 92
while_statement go to state 93
for_statement go to state 94
with_statement go to state 95
subprogram_call go to state 96
io_statement go to state 97
State 51
74 subprograms: subprograms subprogram ";" •
$default reduce using rule 74 (subprograms)
State 52
76 subprogram: sub_header ";" • "forward"
77 | sub_header ";" • declarations subprograms comp_statement
"const" shift, and go to state 14
"forward" shift, and go to state 98
$default reduce using rule 9 (constdefs)
declarations go to state 99
constdefs go to state 16
State 53
2 program: header $@1 declarations subprograms comp_statement "." •
$default reduce using rule 2 (program)
State 54
43 type_defs: "id" "=" • type_def
"array" shift, and go to state 100
"set" shift, and go to state 101
"record" shift, and go to state 102
"id" shift, and go to state 103
"iconst" shift, and go to state 104
"bconst" shift, and go to state 105
"cconst" shift, and go to state 106
"+ or -" shift, and go to state 107
"(" shift, and go to state 108
type_def go to state 109
limit go to state 110
State 55
40 typedefs: "type" type_defs ";" •
42 type_defs: type_defs ";" • "id" "=" type_def
"id" shift, and go to state 111
$default reduce using rule 40 (typedefs)
State 56
69 identifiers: "id" •
$default reduce using rule 69 (identifiers)
State 57
68 identifiers: identifiers • "," "id"