I am currently implementing the part of the Decaf (programming language) grammar. Here is the relevant snippet of bison code:
type:
INT
| ID
| type LS RS
;
local_var_decl:
type ID SEMICOLON
;
name:
THIS
| ID
| name DOT ID
| name LS expression RS
;
Nevertheless, as soon as I started working on name production rule, my parser gives the reduce-reduce warning.
Here what it's inside the .output file (generated by bison):
State 84
23 type: ID .
61 name: ID .
ID reduce using rule 23 (type)
LS reduce using rule 23 (type)
LS [reduce using rule 61 (name)]
$default reduce using rule 61 (name)
So, if we give the following input { abc[1] = abc; }
, it says that syntax error, unexpected NUMBER, expected RS
. NUMBER comes here from expression rule (basically, how it must have parsed it), though it tries to parse it through local_var_decl rule.
What do you think should be changed in order to solve this problem? Spent around 2 hours, tried different stuff, did not work.
Thank you!!
PS. Here is the link to the full .y source code