Skip to content

Commit

Permalink
Fixed the String Index out of bound hatamiarash7#2 Issue
Browse files Browse the repository at this point in the history
Fixed the String Index out of bound hatamiarash7#2 Issue
Add the functionality of parsing multiple strings until the user types "bas kro".
  • Loading branch information
CO18353 committed Jun 20, 2021
1 parent 2a59d66 commit f0ade8b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ def first(s, productions):
flag = 1
start = ""
for line in grammar:
l = re.split("( |->|\n|\||)*", line)
line = line.replace(" ", "").replace("\n", "")
l = line.split("->")
lhs = l[0]
rhs = set(l[1:-1]) - {''}
rhs = l[1].split("|")
if flag:
flag = 0
start = lhs
Expand Down Expand Up @@ -178,4 +179,8 @@ def first(s, productions):
ll1Table = ll1(follow_dict, productions)

# parse("edcc", start, ll1Table)
parse("aabd", start, ll1Table)
while(True):
st = input("Enter the string: ")
if(st == "bas kro"):
break
parse(st, start, ll1Table)

0 comments on commit f0ade8b

Please sign in to comment.