I'm in the process of defining a grammar with Bison and I stumbled upon a shift/reduce conflict I'd like to eliminate. The conflict is caused by a rule that aims to match if/else
statements:
state 17
13 Stmt: IfBlock . OptionalElseBlock
ELSE shift, and go to state 42
ELSE [reduce using rule 16 (OptionalElseBlock)]
$default reduce using rule 16 (OptionalElseBlock)
OptionalElseBlock go to state 43
The OptionalElseBlock
was defined as follows:
16 OptionalElseBlock: /* empty */
17 | ELSE Stmt
States 42 and 43 look like this with the shift and reduce info omitted:
state 42
17 OptionalElseBlock: ELSE . Stmt
state 43
13 Stmt: IfBlock OptionalElseBlock .
I've used optional tokens before, but I'm guessing that since the parser's lookahead buffer only contains 1 terminal OptionalElseBlock
causes a conflict. Is there an easy way to resolve this conflict?