0
votes

My question is regarding bison rules syntax. I'm trying to produce parser for ecmascript and end up with shift-reduce conflict about '{' '}' where this production can be either object literal or block. Thing is that specification declares rule for statement:

Statement :
    Block |
    /*...*/
    ExpressionStatement |
    /*...*/
    ;

and ExpressionStatement is descriped in specification as Expression when lookahead is not "function" or '{'. How can I achieve this with bison? I've tried to use precedence but without sucess:

%nonassoc '{'
%nonassoc BLOCK

Block :
    '{' StatementListOpt '}' %prec BLOCK
    ;

Assuming I'm doing somethig wrong.

Conflict happens after '{' and before '}' (I mean with '}' lookahead).

1

1 Answers

0
votes

I found the solution: actually I should've been applying the %prec dirrective not to the rule I'm resolving but to reducing rule.

This answer is actually helps to understand details of how this directive works: https://stackoverflow.com/a/12734499/1480424