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

[BUG] check_if always overflow #403

Closed
wants to merge 8 commits into from
Closed

[BUG] check_if always overflow #403

wants to merge 8 commits into from

Conversation

jigyasudhingra
Copy link
Contributor

@jigyasudhingra jigyasudhingra commented Dec 12, 2020

Trying to fix #361 bug, and it is fixed, showing error " Expected { before if body ":

MAIN
    if()

But, when I ran the program:

MAIN
    if()
    {
    }

Then, again it showing the error which is showing in above case.

So, someone please help me to resolve this.

@Math-O5
Copy link
Collaborator

Math-O5 commented Dec 13, 2020

@jigyasudhingra That is weird. Maybe this is a bug from a wrong merge. My advice is keep your master branch clear to compare with your modified branch.

Just discover, it may be a newline inserted by you or your editor on your test file, the error happens when there is no next line.

In order to see the tokens, in function parser(), located in simc_parser.py, use this for debug:

for j in range(len(tokens)-1):
        print(tokens[j + 1].type)

The error still persist for

MAIN
        var i = 3
        while() {
fun() {

The bug happens with this statement, as you already note:

# Check if ( follows id in function
    check_if(
        tokens[i + 1].type,

# Check if ( follows id in function
    check_if(
        tokens[i + 2].type,

Or any tokens[i + k]. You can do the check_incomplete function, but use it inside check_if too, that way we ensure check_if is a safe function.

@jigyasudhingra
Copy link
Contributor Author

jigyasudhingra commented Dec 13, 2020

Yes, it is exactly what is happening whenever I try to run. It accounts newline as well into it because of which 'while' loop (which checks for newline) becomes infinite loop and it throws overflow error.

I don't think so, modifications in check_if works for every case because whenever while loop run to find left_brace, it always throw error, so, I have to put something before while loop to check whether tokens are present.

I tried this also, but the compiler take account the newline when runs.

I will try, what you suggest for checking the tokens.

@Math-O5
Copy link
Collaborator

Math-O5 commented Dec 13, 2020

@jigyasudhingra I would suggest create a function is_equal(tokens, i, expected) which responsible by comparation that will compare tokens, if out of range throw an error. And do the same check in check_if. I suggest start with the new master, which update and splitted simc_parse into small pieces.

Copy link
Collaborator

@Math-O5 Math-O5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to add review, branch conflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG REPORT] Print error message: A case where the the check_if will always overflow
2 participants