I'm getting a reduce/reduce conflict on the following grammar (excerp)
declaration : type list_of_id
list_of_id : ID
| list_of_id ',' ID
;
type : PATH
| SCAL
;
assignment : ID ":=" param
| ID ":=" expr
param : point relative_param
| ID relative_param
point : '(' expr ',' expr ')'
| '(' expr ':' expr ')'
relative_param : /* empty rule */
| "--" '+' param
| "--" CYCLE relative_param
| "--" param
expr : NB
| ID ``
| expr '+' expr
| expr '-' expr
| expr '*' expr
| expr '/' expr
| '(' expr ')'
I see that when the input is : foo := bar , there are two possible derivations:
- assignment-> ID ":=" param and param -> ID
- assignment-> ID ":=" expr and expr-> ID
I used ID twice in the grammar because a variable can be either of type path or scal. How can i remove this conflict without using the glr-parser option ?
I tried to split ID in two possibilies : ID_PATH and ID_SCAL and change productions param and expr to :
param : point relative_param
| ID_PATH relative_param
;
expr : NB
| ID_SCAL
| expr '+' expr
| expr '-' expr
| expr '/' expr
| '(' expr ')'
but in this case , how can i differenciate those two (ID_SCAL and ID_PATH) in the lexer ?