On 08/25/2015 09:38, Claude Pache wrote:
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 ```
The above is not a valid grammar. For example, parsing ++x leads to a reduce-reduce conflict, where the ++ can come from either a UnaryExpression or an IncrementExpression.
where the following production (which exists only to avoid to confusingly interpret, e.g., `++x++` as `+ +x++`):
That makes no sense. ++ is a lexical token. The lexer always greedily bites off the largest token it can find, even if that leads to a parser error later. The parser does not backtrack into the lexer to look for alternate lexings. For example, x +++++ y; is a syntax error because it's greedily lexed as: x ++ ++ + y; The parser does not backtrack into the lexer to look for other possible lexings such as: x ++ + ++ y;
``` UnaryExpression: ++ UnaryExpression -- UnaryExpression ``` yields a static SyntaxError (or a static ReferenceError if we want to be 100% compatible ES2015).
This is a problem. It makes ++x into a static SyntaxError because x is a UnaryExpression. If you got rid of these two ++ and -- productions in UnaryExpression, that would solve that problem (and I think make the grammar valid). Waldemar _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss