I'm implementing a Javascript parser using Bison. The ECMAScript specification states that
ExpressionStatement:
[lookahead ∉ { '{' , 'function'}] Expression ;
That breaks the ambiguity between "{ }" as a BlockStatement (empty statement block) and as an ExpressionStatement (empty object literal) because an ExpressionStatement just can't start with a '{' token, although an Expression could.
Example of an empty statement block:
if (a > 5) {}
Example of an empty object literal:
var a = {};
How can I specify in a bison/yacc grammar that some production should not start with some particular tokens? I mean, something like:
expressionStatement
: %must-not-start-with('{', TOKEN_FUNCTION) expression ';'
;
I know I could duplicate all my expression rules to define an "ExpressionNotStartingWithOpenCurlyBraceOrFunction", but that would increase a lot the size of my grammar, so I'm trying to avoid it.