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

Order of operations is not respected #3

Open
astromme opened this issue May 27, 2011 · 1 comment
Open

Order of operations is not respected #3

astromme opened this issue May 27, 2011 · 1 comment
Assignees

Comments

@astromme
Copy link
Owner

Because of the way the AST compiles down into C code the operator precedence is not honored. The AST gets it right but writes it out wrong for C to interpret. It is going to be more involved than just putting () around every function, that seems to break things. (maybe makes things into bools??)

operations.chestnut
print("4 * (1+1) should equal 8, in reality it is %s", 4 * (1+1));
output:
$ ./operations
4 * (1+1) should equal 8, in reality it is 5
@ghost ghost assigned astromme May 27, 2011
@astromme
Copy link
Owner Author

When compiling the AST I now put parentheses around everything, which fixes this issue but makes the generated code look awful. The correct way to fix this is to re-create the parentheses when compiling, which requires the compiler (in addition to the parser) to know about operator precedence.

commit 4d0db10

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