-
Notifications
You must be signed in to change notification settings - Fork 0
/
SyntaxAnalyzer.py
173 lines (131 loc) · 36.5 KB
/
SyntaxAnalyzer.py
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
# File name: SyntaxAnalyzer.py
# Student Number: 20166450
# Student Name: YoungMin Kim
# Method of First set.
def First(X):
if X in terminals:
return {X}
else:
#make list for a second
first_list = []
#set set.
first = set([])
#append nonterminal in first_list.
first_list.append(X)
for prod in Grammar_dic[X]:
#for head
if prod == ['^']:
first.add('^')
else:
for (i, symbol) in enumerate(prod.split()):
if symbol not in first_list:
symbol_first = First(symbol)
for sf in symbol_first:
if sf in terminals:
first.add(sf)
if '^' not in symbol_first:
break
else:
break
if i + 1 == len(prod):
first.add('^')
first_list.remove(X)
#return first
return first
# Method of FOLLOW set.
def FOLLOW(A):
follow_list = []
#define set.
follow = set([])
follow_list.append(A)
#starting symbol add $
if A == starting_symbol:
follow.add('$')
for (heads, prods) in Grammar_dic.items():
for prod in prods:
prod = prod.split()
if A in prod[:-1]:
first = First(prod[prod.index(A) + 1])
follow |= (first - set('^'))
if '^' in first and heads not in follow_list:
follow |= FOLLOW(heads)
elif A in prod[-1]:
if heads not in follow_list:
follow |= FOLLOW(heads)
follow_list.remove(A)
return follow
####### Very important ! Grammar , terminals, nonterminals, parsing_table which I have already computed by hands.
Grammar_dic={"CODE'": ['CODE'], 'CODE': ['VDECL CODE', 'FDECL CODE', 'FDECL', 'VDECL'], 'VDECL': ['vtype identifier semi'], 'FDECL': ['vtype identifier lparen ARG'], 'ARG': ['vtype identifier MOREARGS', 'rparen lbrace BLOCK'], 'MOREARGS': ['comma vtype identifier MOREARGS', 'rparen lbrace BLOCK'], 'BLOCK': ['STMT BLOCK', 'RETURN rbrace', 'rbrace', 'rbrace else lbrace BLOCK'], 'STMT': ['VDECL', 'identifier assign RHS semi', 'if lparen COND rparen lbrace BLOCK', 'while lparen COND rparen lbrace BLOCK'], 'RHS': ['EXPR', 'literal'], 'EXPR': ['TERM addsub EXPR', 'TERM'], 'TERM': ['FACTOR multdiv TERM', 'FACTOR'], 'FACTOR': ['lparen EXPR rparen', 'identifier', 'integer'], 'COND': ['FACTOR comparison FACTOR'], 'RETURN': ['return FACTOR semi']}
Grammar= {1: 'CODE -> VDECL CODE', 2: 'CODE -> FDECL CODE', 3: 'CODE -> FDECL', 4: 'CODE -> VDECL', 5: 'VDECL -> vtype identifier semi', 6: 'FDECL -> vtype identifier lparen ARG', 7: 'ARG -> vtype identifier MOREARGS', 8: 'ARG -> rparen lbrace BLOCK', 9: 'MOREARGS -> comma vtype identifier MOREARGS', 10: 'MOREARGS -> rparen lbrace BLOCK', 11: 'BLOCK -> STMT BLOCK', 12: 'BLOCK -> RETURN rbrace', 13: 'BLOCK -> rbrace', 14: 'BLOCK -> rbrace else lbrace BLOCK', 15: 'STMT -> VDECL', 16: 'STMT -> identifier assign RHS semi', 17: 'STMT -> if lparen COND rparen lbrace BLOCK', 18: 'STMT -> while lparen COND rparen lbrace BLOCK', 19: 'RHS -> EXPR', 20: 'RHS -> literal', 21: 'EXPR -> TERM addsub EXPR', 22: 'EXPR -> TERM', 23: 'TERM -> FACTOR multdiv TERM', 24: 'TERM -> FACTOR', 25: 'FACTOR -> lparen EXPR rparen', 26: 'FACTOR -> identifier', 27: 'FACTOR -> integer', 28: 'COND -> FACTOR comparison FACTOR', 29: 'RETURN -> return FACTOR semi'}
starting_symbol="CODE'"
terminals=['identifier', 'lparen', 'comma', 'addsub', 'return', 'while', 'rparen', 'rbrace', 'multdiv', 'integer', 'lbrace', 'assign', 'if', 'semi', 'vtype', 'literal', 'comparison', 'else']
nonterminals=['CODE', 'FDECL', 'STMT', 'RHS', 'FACTOR', 'VDECL', 'ARG', 'RETURN', 'COND', 'EXPR', 'TERM', 'MOREARGS', 'BLOCK']
parsing_table = {0: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 's1', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': 3, 'TERM': '', 'FACTOR': '', 'VDECL': 4, 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': 2, 'ARG': '', 'COND': '', 'MOREARGS': ''}, 1: {'comma': '', 'addsub': '', 'identifier': 's5', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 2: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 's1', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r3', 'BLOCK': '', 'CODE': 6, 'TERM': '', 'FACTOR': '', 'VDECL': 4, 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': 2, 'ARG': '', 'COND': '', 'MOREARGS': ''}, 3: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'acc', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 4: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 's1', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r4', 'BLOCK': '', 'CODE': 7, 'TERM': '', 'FACTOR': '', 'VDECL': 4, 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': 2, 'ARG': '', 'COND': '', 'MOREARGS': ''}, 5: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': 's8', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 's9', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 6: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r2', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 7: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r1', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 8: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 's10', 'rparen': 's11', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': 12, 'COND': '', 'MOREARGS': ''}, 9: {'comma': '', 'addsub': '', 'identifier': 'r5', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r5', 'multdiv': '', 'vtype': 'r5', 'rparen': '', 'if': 'r5', 'while': 'r5', 'return': 'r5', 'else': '', '$': 'r5', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 10: {'comma': '', 'addsub': '', 'identifier': 's13', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 11: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': 's14', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 12: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 'r6', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r6', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 13: {'comma': 's15', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 's17', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': 16}, 14: {'comma': '', 'addsub': '', 'identifier': 's23', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 's18', 'multdiv': '', 'vtype': 's19', 'rparen': '', 'if': 's26', 'while': 's21', 'return': 's27', 'else': '', '$': '', 'BLOCK': 24, 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': 25, 'STMT': 22, 'RHS': '', 'EXPR': '', 'RETURN': 20, 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 15: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 's28', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 16: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 'r7', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r7', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 17: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': 's29', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 18: {'comma': '', 'addsub': '', 'identifier': 'r13', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r13', 'multdiv': '', 'vtype': 'r13', 'rparen': '', 'if': 'r13', 'while': 'r13', 'return': 'r13', 'else': 's30', '$': 'r13', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 19: {'comma': '', 'addsub': '', 'identifier': 's31', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 20: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 's32', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 21: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': 's33', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 22: {'comma': '', 'addsub': '', 'identifier': 's23', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 's18', 'multdiv': '', 'vtype': 's19', 'rparen': '', 'if': 's26', 'while': 's21', 'return': 's27', 'else': '', '$': '', 'BLOCK': 34, 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': 25, 'STMT': 22, 'RHS': '', 'EXPR': '', 'RETURN': 20, 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 23: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': 's35', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 24: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 'r8', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r8', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 25: {'comma': '', 'addsub': '', 'identifier': 'r15', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r15', 'multdiv': '', 'vtype': 'r15', 'rparen': '', 'if': 'r15', 'while': 'r15', 'return': 'r15', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 26: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': 's36', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 27: {'comma': '', 'addsub': '', 'identifier': 's40', 'lparen': 's37', 'comparison': '', 'literal': '', 'integer': 's39', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': 38, 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 28: {'comma': '', 'addsub': '', 'identifier': 's41', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 29: {'comma': '', 'addsub': '', 'identifier': 's23', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 's18', 'multdiv': '', 'vtype': 's19', 'rparen': '', 'if': 's26', 'while': 's21', 'return': 's27', 'else': '', '$': '', 'BLOCK': 42, 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': 25, 'STMT': 22, 'RHS': '', 'EXPR': '', 'RETURN': 20, 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 30: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': 's43', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 31: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 's9', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 32: {'comma': '', 'addsub': '', 'identifier': 'r12', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r12', 'multdiv': '', 'vtype': 'r12', 'rparen': '', 'if': 'r12', 'while': 'r12', 'return': 'r12', 'else': '', '$': 'r12', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 33: {'comma': '', 'addsub': '', 'identifier': 's40', 'lparen': 's37', 'comparison': '', 'literal': '', 'integer': 's39', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': 44, 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': 45, 'MOREARGS': ''}, 34: {'comma': '', 'addsub': '', 'identifier': 'r11', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r11', 'multdiv': '', 'vtype': 'r11', 'rparen': '', 'if': 'r11', 'while': 'r11', 'return': 'r11', 'else': '', '$': 'r11', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 35: {'comma': '', 'addsub': '', 'identifier': 's40', 'lparen': 's37', 'comparison': '', 'literal': 's48', 'integer': 's39', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': 46, 'FACTOR': 47, 'VDECL': '', 'STMT': '', 'RHS': 49, 'EXPR': 50, 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 36: {'comma': '', 'addsub': '', 'identifier': 's40', 'lparen': 's37', 'comparison': '', 'literal': '', 'integer': 's39', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': 44, 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': 51, 'MOREARGS': ''}, 37: {'comma': '', 'addsub': '', 'identifier': 's40', 'lparen': 's37', 'comparison': '', 'literal': '', 'integer': 's39', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': 46, 'FACTOR': 47, 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': 52, 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 38: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 's53', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 39: {'comma': '', 'addsub': 'r27', 'identifier': '', 'lparen': '', 'comparison': 'r27', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r27', 'rbrace': '', 'multdiv': 'r27', 'vtype': '', 'rparen': 'r27', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 40: {'comma': '', 'addsub': 'r26', 'identifier': '', 'lparen': '', 'comparison': 'r26', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r26', 'rbrace': '', 'multdiv': 'r26', 'vtype': '', 'rparen': 'r26', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 41: {'comma': 's15', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 's17', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': 54}, 42: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 'r10', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r10', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 43: {'comma': '', 'addsub': '', 'identifier': 's23', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 's18', 'multdiv': '', 'vtype': 's19', 'rparen': '', 'if': 's26', 'while': 's21', 'return': 's27', 'else': '', '$': '', 'BLOCK': 55, 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': 25, 'STMT': 22, 'RHS': '', 'EXPR': '', 'RETURN': 20, 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 44: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': 's56', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 45: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 's57', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 46: {'comma': '', 'addsub': 's58', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r22', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 'r22', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 47: {'comma': '', 'addsub': 'r24', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r24', 'rbrace': '', 'multdiv': 's59', 'vtype': '', 'rparen': 'r24', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 48: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r20', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 49: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 's60', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 50: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r19', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 51: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 's61', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 52: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 's62', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 53: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r29', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 54: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': 'r9', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': 'r9', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 55: {'comma': '', 'addsub': '', 'identifier': 'r14', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r14', 'multdiv': '', 'vtype': 'r14', 'rparen': '', 'if': 'r14', 'while': 'r14', 'return': 'r14', 'else': '', '$': 'r14', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 56: {'comma': '', 'addsub': '', 'identifier': 's40', 'lparen': 's37', 'comparison': '', 'literal': '', 'integer': 's39', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': 63, 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 57: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': 's64', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 58: {'comma': '', 'addsub': '', 'identifier': 's40', 'lparen': 's37', 'comparison': '', 'literal': '', 'integer': 's39', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': 46, 'FACTOR': 47, 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': 65, 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 59: {'comma': '', 'addsub': '', 'identifier': 's40', 'lparen': 's37', 'comparison': '', 'literal': '', 'integer': 's39', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': 66, 'FACTOR': 47, 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 60: {'comma': '', 'addsub': '', 'identifier': 'r16', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r16', 'multdiv': '', 'vtype': 'r16', 'rparen': '', 'if': 'r16', 'while': 'r16', 'return': 'r16', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 61: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': 's67', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': '', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 62: {'comma': '', 'addsub': 'r25', 'identifier': '', 'lparen': '', 'comparison': 'r25', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r25', 'rbrace': '', 'multdiv': 'r25', 'vtype': '', 'rparen': 'r25', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 63: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 'r28', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 64: {'comma': '', 'addsub': '', 'identifier': 's23', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 's18', 'multdiv': '', 'vtype': 's19', 'rparen': '', 'if': 's26', 'while': 's21', 'return': 's27', 'else': '', '$': '', 'BLOCK': 68, 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': 25, 'STMT': 22, 'RHS': '', 'EXPR': '', 'RETURN': 20, 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 65: {'comma': '', 'addsub': '', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r21', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 'r21', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 66: {'comma': '', 'addsub': 'r23', 'identifier': '', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': 'r23', 'rbrace': '', 'multdiv': '', 'vtype': '', 'rparen': 'r23', 'if': '', 'while': '', 'return': '', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 67: {'comma': '', 'addsub': '', 'identifier': 's23', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 's18', 'multdiv': '', 'vtype': 's19', 'rparen': '', 'if': 's26', 'while': 's21', 'return': 's27', 'else': '', '$': '', 'BLOCK': 69, 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': 25, 'STMT': 22, 'RHS': '', 'EXPR': '', 'RETURN': 20, 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 68: {'comma': '', 'addsub': '', 'identifier': 'r18', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r18', 'multdiv': '', 'vtype': 'r18', 'rparen': '', 'if': 'r18', 'while': 'r18', 'return': 'r18', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}, 69: {'comma': '', 'addsub': '', 'identifier': 'r17', 'lparen': '', 'comparison': '', 'literal': '', 'integer': '', 'lbrace': '', 'assign': '', 'semi': '', 'rbrace': 'r17', 'multdiv': '', 'vtype': 'r17', 'rparen': '', 'if': 'r17', 'while': 'r17', 'return': 'r17', 'else': '', '$': '', 'BLOCK': '', 'CODE': '', 'TERM': '', 'FACTOR': '', 'VDECL': '', 'STMT': '', 'RHS': '', 'EXPR': '', 'RETURN': '', 'FDECL': '', 'ARG': '', 'COND': '', 'MOREARGS': ''}}
#file input(last term project output)
file_pj1= open('allG_test.out','r')
#hile ouput(if the grammar is accepted or not)
fileout= open('allG_test_pj2.out','w')
#file input uses as a string.
output_of_project1=file_pj1.read()
output_of_project1=output_of_project1.lower()
buffer = (output_of_project1 + " $").split()
pointer = 0
a = buffer[pointer]
#create the stack.
stack = ['0']
step = 0
#SLR Parser using First set and Follow set. See if the Grammar is accepted or not.
while True:
try:
s = int(stack[-1])
step += 1
#If there is no Symbols in parsing table, break
if a not in parsing_table[s].keys():
print("ERROR: Unrecognized Symbol", a)
break
#input the stack ,a
elif parsing_table[s][a][0] == "s":
stack.append(a)
stack.append(parsing_table[s][a][1:])
pointer += 1
a = buffer[pointer]
#parsing_ table grammar split and input the stack if that is head.
elif parsing_table[s][a][0] == "r":
grammar = Grammar[int(parsing_table[s][a][1:])].split()
if grammar[-1] != '^':
stack = stack[:-(2 * len(grammar[grammar.index('->') + 1:]))]
s = int(stack[-1])
head = grammar[0]
stack.append(head)
stack.append(str(parsing_table[s][head]))
#If all grammar accepted, break
elif parsing_table[s][a] == "acc":
a = "GRAMMAR : ACCEPTED"
fileout.write(a)
print(a)
break
#catch the TypeError and make some comment why the Error occured in output file.
except TypeError:
f = "GRAMMAR : REJECTED \n"
g = "STACK: " + str(stack) + "<- Error occured from here."
h = f + g
print(f)
print(g)
print("\nType Error!!")
fileout.write(h)
fileout.write("\nType Error!!")
break
#catch the IndexError and make some comment why the Error occured in output file.
except IndexError:
f = "GRAMMAR : REJECTED \n"
g = "STACK: " + str(stack) + "<- Error occured from here."
h = f + g
print(f)
print(g)
print("\nIndex Error!!")
fileout.write(h)
fileout.write("\nIndex Error!!")
break
#file close.
file_pj1.close()
fileout.close()