Skip to content

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

Open
@MarcellPerger1

Description

@MarcellPerger1

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 = ... | '(' ... ')' | ...
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions