Exponentiation operator precedence

Claude Pache claude.pache at gmail.com
Tue Aug 25 16:38:38 UTC 2015


I think the following grammar could work. 
Replace the current (ES2015) PostfixExpression production with:

```
IncrementExpression:
    LeftHandSideExpression
    LeftHandSideExpression [no LineTerminator here] ++
    LeftHandSideExpression [no LineTerminator here] --
    ++ LeftHandSideExpression
    -- LeftHandSideExpression
```

And define UnaryExpression as:

```
UnaryExpression:
    IncrementExpression    
    delete UnaryExpression
    void UnaryExpression
    typeof UnaryExpression
    ++ UnaryExpression
    + UnaryExpression
    -- UnaryExpression
    - UnaryExpression
    ~ UnaryExpression
    ! UnaryExpression
    IncrementExpression ** UnaryExpression
```

where the following production (which exists only to avoid to confusingly interpret, e.g., `++x++` as `+ +x++`):

```
UnaryExpression:
    ++ UnaryExpression
    -- UnaryExpression
```

yields a static SyntaxError (or a static ReferenceError if we want to be 100% compatible ES2015). 


That way, we have the following expected behaviour:
* in/decrement operators bind most tightly;
* unary and exponentiation operators are applied from right to left.


—Claude




More information about the es-discuss mailing list