Reason for strange ExponentiationExpression & UpdateExpression productions?

Bradford Smith bradfordcsmith at google.com
Wed Jul 20 19:48:46 UTC 2016


Can anyone explain the reasoning behind the strange "leapfrogging" behavior
of the ExponentiationExpression
<https://tc39.github.io/ecma262/#prod-ExponentiationExpression> and
UpdateExpression
<https://tc39.github.io/ecma262/#prod-UpdateExpression> productions
in the current spec?

Simplified relevant productions in operator precedence order are:

ExponentiationExpression :
    UnaryExpression
    UpdateExpression ** ExponentiationExpression

UnaryExpression :
    UpdateExpression
    { delete | void | typeof | + | - | ~ | ! } UnaryExpression

UpdateExpression:
    { ++ | -- } UnaryExpression
    LeftHandSideExpression { ++ | -- }

Things that seem weird about this are:
1. '-x ** y' is a syntax error, because UnaryExpression isn't allowed
before **
    You must write it as '(-x) ** y'
    I would expect the production right hand side to be
        UnaryExpression ** ExponentiationExpression
    That avoids this strange syntax error and is consistent with the
pattern followed by productions for lower-precedence operators.

2. Having UnaryExpression in the right hand side of UpdateExpression
confuses precedence by going 'backward' to a lower-precedence non-terminal,
and the only production of UnaryExpression that generates a valid argument
for '++'/'--' is UnaryExpression => UpdateExpression =>
LeftHandSideExpression anyway.

I've just finished implementing these rules in the closure-compiler, where
I had to implement logic to deal with this strange behavior. Is it at all
possible that these are simply typos in the spec?

Thanks,
Bradford
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160720/fd62dca3/attachment.html>


More information about the es-discuss mailing list