Neha13 commited on
Commit
df6f1ef
1 Parent(s): 794e749

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -54
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, term_userdef
129
- if len(rule) != 0 and (rule is not None):
130
- if rule[0] in term_userdef:
131
- return rule[0]
132
- elif rule[0] == '#':
133
- return '#'
134
  if len(rule) != 0:
135
- if rule[0] in list(diction.keys()):
136
- fres = []
137
- rhs_rules = diction[rule[0]]
138
- for itr in rhs_rules:
139
- indivRes = first(itr)
140
- if type(indivRes) is list:
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
- ansNew = first(rule[1:])
153
- if ansNew != None:
154
- if type(ansNew) is list:
155
- newList = fres + ansNew
156
- else:
157
- newList = fres + [ansNew]
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 len(subrule) != 0:
177
  res = first(subrule)
178
  if '#' in res:
179
- newList = []
180
  res.remove('#')
181
- ansNew = follow(curNT)
182
- if ansNew != None:
183
- if type(ansNew) is list:
184
- newList = res + ansNew
185
- else:
186
- newList = res + [ansNew]
187
- else:
188
- newList = res
189
- res = newList
190
  else:
191
  if nt != curNT:
192
- res = follow(curNT)
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()