Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String Index out of bound #2

Open
Lal47 opened this issue Apr 8, 2021 · 4 comments
Open

String Index out of bound #2

Lal47 opened this issue Apr 8, 2021 · 4 comments
Assignees
Labels
help wanted Extra attention is needed
Milestone

Comments

@Lal47
Copy link

Lal47 commented Apr 8, 2021

Hey when i try to run the parser.py file, I get this error.
image

@Lal47
Copy link
Author

Lal47 commented Apr 8, 2021

I just cloned the repository and tried running the code. Any leads on this?

@hatamiarash7
Copy link
Owner

What version of Python are you using and have you installed Pandas?

@CherryChelsea18
Copy link

Yeah I have pandas installed

@hatamiarash7 hatamiarash7 self-assigned this Jun 7, 2021
@hatamiarash7 hatamiarash7 added the help wanted Extra attention is needed label Jun 7, 2021
@hatamiarash7 hatamiarash7 added this to the String Index milestone Jun 7, 2021
@CO18353
Copy link

CO18353 commented Jun 20, 2021

The error is occurring because of the nulls being stored in list "l". In the for loop, the "lhs" is storing null instead of the first non-terminal and so the "productions" dictionary stores every rule on null index.
image
If you print the "productions" dictionary, you would see that the production rules are incorrectly stored.
image
So for fixing this error you just remove the nulls before assigning lhs and rhs.
l=[x for x in l if x != ""]
But another issue that would arise is that the rhs does not store each production rule (specified by "|" in the input) separately.
For that we can first split on the basis of "->" and store the lhs and then split the second list on "|" and store in rhs.

I have used the inbuilt split function of python.
For removing the whitespace and the newline using replace function:
line=line.replace(" ", "").replace("\n", "")
Then split the input at "->" using
l=line.split("->")
And lastly split l[1] on "|"
rhs=l[1].split("|")

CO18353 added a commit to CO18353/LL1_Parser that referenced this issue Jun 20, 2021
Fixed the String Index out of bound hatamiarash7#2 Issue
Add the functionality of parsing multiple strings until the user types "bas kro".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants