I\'m having an issue with my bison grammar, it is giving me shift/reduce errors, and I have already defined precedence for the operators.
I know that it is cause by
Precedence only works if the productions directly include terminals named in the precedence declaration.
In other words, you cannot use expr: expr binop expr
because the precedence relations can't help bison decide whether to shift the reduced binop
non-terminal or reduce the expr
on the top of the parse stack. Bison would have to know what the terminal inside the binop
was, but it doesn't know that any more. (That's why reductions are called "reductions".)
To make it work, you have to write the productions out in full:
expr: expr '+' expr
| expr '-' expr
| expr '*' expr
|...