I am using a Javascript parser using Bison. the ECMAScript specification states that
ExpressionStatement: [lookahead ∉ { '{' , 'function'}] Expression ;
This breaks the ambiguity between "{}" as a BlockStatement (empty statement block) and as an ExpressionStatement expression (empty object literal), because the ExpressionStatement expression simply cannot start with a '{' token, although the expression can.
An example of an empty block:
if (a > 5) {}
An example of an empty object literal:
var a = {};
How can I indicate in bison / yacc grammar that some production should not start with specific tokens? I mean, something like:
expressionStatement : %must-not-start-with('{', TOKEN_FUNCTION) expression ';' ;
I know that I could duplicate all my expression rules to define "ExpressionNotStartingWithOpenCurlyBraceOrFunction", but that would increase the size of my grammar, so I try to avoid this.
source share