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

Unary operator precedence #54

Open
ghost opened this issue Nov 15, 2016 · 2 comments
Open

Unary operator precedence #54

ghost opened this issue Nov 15, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Nov 15, 2016

Please add feature to adjust unary operator precedence so it will be possible to make following example works properly.
-x^2 and (-x)^2
gives

{
    type: "BinaryExpression",
    operator: "^",
    left: {
        type: "UnaryExpression",
        operator: "-",
        argument: { type: "Identifier", name: "x" },
        prefix: true
    },
    right: { type: "Literal", value: 2, raw: 2 }
}

I would like to add something like this:
jsep.addUnaryOp("-", 0);
So output of jsep() would be

{
    type: "UnaryExpression",
    operator: "-",
    argument: {
        type: "BinaryExpression",
        operator: "^",
        left: { type: "Identifier", name: "x" },
        right: { type: "Literal", value: 2, raw: 2 }
    },
    prefix: true
}

It would be only optional feature so IMO it will only improve library.

@mikeazo
Copy link

mikeazo commented Nov 28, 2016

It would seem that in this case, JSEP mimics the behavior of Excel and Matlab. See Order of operations, special cases. It also happens if you input 2^3^2, which should parse as 2^(3^2) given typical mathematical right-associativity of exponentiation, but instead it parses as (2^3)^2.

@mikeazo
Copy link

mikeazo commented Nov 28, 2016

This is probably a duplicate of #40

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