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

[parser] Add support for the minus (-) prefix operator #10

Open
MarcellPerger1 opened this issue Jun 4, 2024 · 0 comments
Open

[parser] Add support for the minus (-) prefix operator #10

MarcellPerger1 opened this issue Jun 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@MarcellPerger1
Copy link
Owner

Add support for - as a prefix operator (e.g. -(1+2)). There is currently support for it but only as a part of a literal.
So currently this is allowed:

-1 + 2
2--1
4*-2*(-1/-2)

And this is not:

-(1+1)
--2*2

And this is interpreted incorrectly:

-1**2  # Gives 1.0 ((-1)**2), should give -1.0 (-(1**2))

So we need to:

  • Add code for the prefix operator - (** < precedence < */)
  • TODO: need to add some special cases to ensure that 2**-1 and 2**-3**-2. Python does this using:
    prefixop = '-' power | '+' power | ...
    power = primary '**' prefixop
    primary = ... | '(' ... ')' | ...
    
@MarcellPerger1 MarcellPerger1 added the bug Something isn't working label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant