I am using Bison and my CFG has a Shift reduce conflict which is screwing up my precedence.
This is my code:
Decl : vartype T_Identifier T_Semicolon {
// replace it with your implementation
Identifier *id = new Identifier(@2, $2);
$$ = new VarDecl(id, $1);
}
| vartype T_Identifier T_Equal primaryExpr T_Semicolon {
Identifier *id = new Identifier(@2, $2);
$$ = new VarDecl(id, $1, $4);
}
| function_prototype T_Semicolon {$$ = $1;}
;
I have a shift reduce conflict for this particular rule. I want the last line (function_prototype ...) to have the highest precedence but the conflict shifts and sends me to another state. FYI, "function_prototype" is a nonterminal that has a rule of "vartype T_Identifier T_LeftParenth". This is the output file from bison:
State 28 conflicts: 1 shift/reduce
...
state 28
4 Decl: vartype . T_Identifier T_Semicolon
5 | vartype . T_Identifier T_Equal primaryExpr T_Semicolon
11 fully_specified_type: vartype .
T_Identifier shift, and go to state 34
T_Identifier [reduce using rule 11 (fully_specified_type)]
...
state 34
4 Decl: vartype T_Identifier . T_Semicolon
5 | vartype T_Identifier . T_Equal primaryExpr T_Semicolon
T_Equal shift, and go to state 36
T_Semicolon shift, and go to state 37
State 34 skips over my "function prototype" rule! How do I fix this conflict and precedence problem?