Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import copy
|
2 |
import streamlit as st
|
3 |
|
@@ -125,44 +126,28 @@ def generateStates(I0):
|
|
125 |
return
|
126 |
|
127 |
def first(rule):
|
128 |
-
global diction,
|
129 |
-
if len(rule) != 0 and
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
return '#'
|
134 |
if len(rule) != 0:
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
for i in indivRes:
|
142 |
-
fres.append(i)
|
143 |
-
else:
|
144 |
-
fres.append(indivRes)
|
145 |
-
|
146 |
-
if '#' not in fres:
|
147 |
-
return fres
|
148 |
-
else:
|
149 |
-
newList = []
|
150 |
-
fres.remove('#')
|
151 |
if len(rule) > 1:
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
else:
|
159 |
-
newList = fres
|
160 |
-
return newList
|
161 |
-
fres.append('#')
|
162 |
-
return fres
|
163 |
|
164 |
def follow(nt):
|
165 |
-
global start_symbol, diction
|
166 |
solset = set()
|
167 |
if nt == start_symbol:
|
168 |
solset.add('$')
|
@@ -173,32 +158,20 @@ def follow(nt):
|
|
173 |
while nt in subrule:
|
174 |
index_nt = subrule.index(nt)
|
175 |
subrule = subrule[index_nt + 1:]
|
176 |
-
if
|
177 |
res = first(subrule)
|
178 |
if '#' in res:
|
179 |
-
newList = []
|
180 |
res.remove('#')
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
else:
|
186 |
-
newList = res + [ansNew]
|
187 |
-
else:
|
188 |
-
newList = res
|
189 |
-
res = newList
|
190 |
else:
|
191 |
if nt != curNT:
|
192 |
-
|
193 |
-
|
194 |
-
if res is not None:
|
195 |
-
if type(res) is list:
|
196 |
-
for g in res:
|
197 |
-
solset.add(g)
|
198 |
-
else:
|
199 |
-
solset.add(res)
|
200 |
return list(solset)
|
201 |
|
|
|
202 |
def createParseTable(statesDict, stateMap, T, NT):
|
203 |
global separatedRulesList, diction
|
204 |
|
@@ -309,4 +282,4 @@ def main():
|
|
309 |
st.text_area("Compact Follow Sets Representation:", value=compact_follow, height=300)
|
310 |
|
311 |
if __name__ == "__main__":
|
312 |
-
main()
|
|
|
1 |
+
|
2 |
import copy
|
3 |
import streamlit as st
|
4 |
|
|
|
126 |
return
|
127 |
|
128 |
def first(rule):
|
129 |
+
global rules, term_userdef, diction, firsts
|
130 |
+
if len(rule) != 0 and rule[0] in term_userdef:
|
131 |
+
return [rule[0]]
|
132 |
+
if len(rule) != 0 and rule[0] == '#':
|
133 |
+
return ['#']
|
|
|
134 |
if len(rule) != 0:
|
135 |
+
fres = []
|
136 |
+
rhs_rules = diction[rule[0]]
|
137 |
+
for itr in rhs_rules:
|
138 |
+
indivRes = first(itr)
|
139 |
+
if '#' in indivRes:
|
140 |
+
indivRes.remove('#')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
if len(rule) > 1:
|
142 |
+
indivRes += first(rule[1:])
|
143 |
+
else:
|
144 |
+
indivRes.append('#')
|
145 |
+
fres.extend(indivRes)
|
146 |
+
return list(set(fres))
|
147 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
def follow(nt):
|
150 |
+
global start_symbol, diction, firsts, follows
|
151 |
solset = set()
|
152 |
if nt == start_symbol:
|
153 |
solset.add('$')
|
|
|
158 |
while nt in subrule:
|
159 |
index_nt = subrule.index(nt)
|
160 |
subrule = subrule[index_nt + 1:]
|
161 |
+
if subrule:
|
162 |
res = first(subrule)
|
163 |
if '#' in res:
|
|
|
164 |
res.remove('#')
|
165 |
+
solset.update(res)
|
166 |
+
solset.update(follow(curNT))
|
167 |
+
else:
|
168 |
+
solset.update(res)
|
|
|
|
|
|
|
|
|
|
|
169 |
else:
|
170 |
if nt != curNT:
|
171 |
+
solset.update(follow(curNT))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
return list(solset)
|
173 |
|
174 |
+
|
175 |
def createParseTable(statesDict, stateMap, T, NT):
|
176 |
global separatedRulesList, diction
|
177 |
|
|
|
282 |
st.text_area("Compact Follow Sets Representation:", value=compact_follow, height=300)
|
283 |
|
284 |
if __name__ == "__main__":
|
285 |
+
main()
|