The grammar that has the conflict is as follow
method_call: T_ID T_LPAREN method_arg_list T_RPAREN T_SEMICOLON
value: T_ID T_LSB expr T_RSB
| T_ID;
method_arg_list: /* Empty */
| method_arg method_arg_list;
method_arg: string_constant
| expr;
expr: value
| '(' expr ')';
The problem is that when it reads a T_ID, it doesn't know whether it should shift and read the following '(' or reduce to a value. But shouldn't it check if the next token is a left parenthesis?
I am quite new to bison and parser in general and I am wondering what are the ways that I can rewrite the grammar and solve the conflict?
Edit
State 60
37 method_call: T_ID . T_LPAREN method_arg_list T_RPAREN T_SEMICOLON
67 value: T_ID . T_LSB expr T_RSB
68 | T_ID .
T_LPAREN shift, and go to state 71
T_LSB shift, and go to state 72
T_LPAREN [reduce using rule 68 (value)]
$default reduce using rule 68 (value)
yacc -v
(bison -v
). We need enough grammar to be able to reproduce the problem — but no more than enough to be able to reproduce the problem. – Jonathan Leffler'('
should beT_LPAREN
and the')'
should beT_RPAREN
. As written, with%token T_ID T_LPAREN T_RPAREN T_SEMICOLON T_LSB T_RSB string_constant
and Bison is OK with the code. I hope you're keeping a record of what broke and then what works; using a version control system becomes very important. – Jonathan Leffler