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

Incorrect tokenization for negative constants #2894

Closed
jcoehoorn opened this issue Mar 25, 2019 · 1 comment
Closed

Incorrect tokenization for negative constants #2894

jcoehoorn opened this issue Mar 25, 2019 · 1 comment

Comments

@jcoehoorn
Copy link

jcoehoorn commented Mar 25, 2019

As first seen here:

https://3dprinting.stackexchange.com/questions/8534/why-is-2-2-2-equal-to-2-in-openscad-mathematical-order-of-operations

This expression:

 2 / -2 / 2 

results in -2. The expected result is -.5. You can see this with a new empty project with only this statement:

echo(2 / -2 / 2);

We believe what happens is the expression is evaluated right-to-left, where you first have 2 / 2 from the right side (resulting in 1), then the - operator is applied (now -1), and finally the leading division (2 / -1) becomes -2. Or perhaps it works left-to-right where the bug is the first / operator trying to resolve the right-hand side to an integer.

What should happen is the lexer should see the inner -2 as the same token, so you have a single literal -2 value hit the parser.

@t-paul
Copy link
Member

t-paul commented Mar 25, 2019

Right, it seems the unary precedence is missing (e.g. like in this example). Same issue also with echo(2 / +2 / 2);

@kintel kintel closed this as completed Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants