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

Variable Substitution Algorithm Bug #76

Open
126pikaqiu opened this issue Nov 14, 2022 · 0 comments
Open

Variable Substitution Algorithm Bug #76

126pikaqiu opened this issue Nov 14, 2022 · 0 comments

Comments

@126pikaqiu
Copy link

In the get_example_batch function of run_parser.py, there is an error in the substitution algorithm for variable names. In your code, the problem of variable name length inconsistency before and after substitution is handled by accumulating differences, but only if the row is replaced sequentially from left to right. Failure to do so results in substitution misplaced code that produces syntax errors.

Your code in get_example_batch:

    for index, pos in enumerate(replace_pos[line]):

        code[line] = code[line][:pos[3]+diff] + pos[1] + code[line][pos[4]+diff:]

        diff += pos[2]

Bug fixed code in get_example_batch:

    for index, pos in enumerate(list(sorted(replace_pos[line], key=lambda x:x[3]))):

        code[line] = code[line][:pos[3]+diff] + pos[1] + code[line][pos[4]+diff:]

        diff += pos[2]
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

No branches or pull requests

1 participant