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

Parenthesise operators if necessary #16

Open
atg opened this issue Mar 18, 2016 · 1 comment
Open

Parenthesise operators if necessary #16

atg opened this issue Mar 18, 2016 · 1 comment
Assignees
Labels
Milestone

Comments

@atg
Copy link

atg commented Mar 18, 2016

In Python the not operator has low precedence. In JS the ! operator has high precedence.

To be on the safe side, generators should wrap all operators in parens by default, and only remove them if the generator can prove there is no precedence/associativity issue. Otherwise you'll get issues with things like PHP's weird-ass left associative ternary operator.

Input (Python):

not 0.1 > 0.1

Expected output (JavaScript):

!(0.1 > 0.1)

Actual output (JavaScript):

!0.1 > 0.1

@alehander92
Copy link
Collaborator

There is already a dict with operator precedence order in the base code generator. It was in one of the initial python generator versions and it was good enough for the alpha release, but now I can just overload some of the precedences in the language specific generators

@alehander92 alehander92 added this to the v0.3 milestone Mar 19, 2016
@alehander92 alehander92 self-assigned this Mar 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants