Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: -2 ** 2 Date: Fri, 05 May 2017 08:17:14 +0200 Organization: PointedEars Software (PES) Lines: 82 Message-ID: <1634774.atdPhlSkOF@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1493965035 32375 eJwNyckRwCAMBLCWbO8BtAPE/ZcQRk8JTp9By1Q/e3anKrUQt1GAaoZf4GM2zW3AK3zrjPoBAcwP4Q== (5 May 2017 06:17:15 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 5 May 2017 06:17:15 +0000 (UTC) User-Agent: KNode/4.14.2 Cancel-Lock: sha1:xwoZfPczPRi+XnVcedkuVoEQso0= X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. In a recent Firefox: > > -2 ** 2 > > SyntaxError: unparenthesized unary expression can't appear on > the left-hand side of '**' > > . Can't seem to find the corresponding rule in a recent copy > of ECMAScript (12.6), though. Next time, *cite* your sources, OK? | 12.6 Exponentiation Operator | | Syntax | | ExponentiationExpression[Yield] : | UnaryExpression[?Yield] | UpdateExpression[?Yield] ** ExponentiationExpression[?Yield] (via /Statement/ → /ExpressionStatement/ → /Expression/ → /AssignmentExpression/ → … → /MultiplicativeExpression/) *The longest match wins*, so check the second (longer) alternative first: “-2” must be producible by UpdateExpression. Check by looking at the possible productions for that: | 12.4 Update Expressions | | Syntax | | UpdateExpression : | LeftHandSideExpression[?Yield] | LeftHandSideExpression[?Yield][no LineTerminator here]++ | LeftHandSideExpression[?Yield][no LineTerminator here]-- | ++ UnaryExpression[?Yield] | -- UnaryExpression[?Yield] Conclusion: “-2” cannot be produced by the /UpdateExpression/ production’s results. The only remaining alternative is /UnaryExpression/: | 12.5 Unary Operators | | Syntax | | UnaryExpression : | UpdateExpression[?Yield] | delete UnaryExpression | void UnaryExpression | typeof UnaryExpression | + UnaryExpression | - UnaryExpression | ~ UnaryExpression | ! UnaryExpression And therein lies the problem. “-2” cannot be produced by /UpdateExpression/, so it must be producible by “- UnaryExpression” for “-2 ** 2” to be syntactically valid. But “2” cannot be produced by /UnaryExpression/, because it can neither be produced by /UpdateExpression/ nor any other /UnaryExpression/ production result. Conclusion: “-2 ** 2” is *syntactically invalid*. [This has nothing to do with operator precedence.] Finding out why “(-2) ** 2” is valid syntax, and works as intended, is left as an exercise to the reader. -- PointedEars FAQ: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.