How can I tell Beaver to ignore reduce/reduce conflicts?

467 Views Asked by At

I'm attempting to use Beaver to parse a grammar that contains a reduce/reduce conflict. The conflict is expected. Other parser generators support saying something like %expect 0 1 to specify that one reduce/reduce conflict is expected, but Beaver doesn't appear to support this. How can I tell Beaver to ignore a known reduce/reduce conflict and generate a parser?

1

There are 1 best solutions below

0
On

Beaver can't do that, but you can use %left, %right or %nonassoc directives to define associativity and precedence rules.

I assume that you don't care which reduce is performed in case of conflict (either because the parse trees are identical, or because they are identical for your purpose). It therefore shouldn't matter to you which precedences you define, just that you define enough precedence.

Suppose the conflict is between operators OP1 and OP2, then the following directives will resolve your conflict.

%nonassoc OP1;
%nonassoc OP2;

However, if the conflict is between two deduction rules with the same operator (OP), then you need either

%left OP;

or

%right OP;