I'm working on the parser component of my Tiger compiler in SML using ML-Yacc. I cannot find any glaring problems with my grammar file (I've used priority rules to resolve all shift-reduce conflicts) but it seems to never reduce using the second and third rules of lvalue
, which I've specified as follows:
lvalue : ID ()
| lvalue DOT ID ()
| lvalue LBRACK exp RBRACK ()
The grammar for exp
is:
exp : lvalue ()
| INT ()
| ID LBRACK exp RBRACK OF exp ()
| lvalue ASSIGN exp ()
...
When trying to parse a[0] := 5
, I expect it to reduce using the fourth exp
rule (where the lvalue
is lvalue LBRACK exp RBRACK
). Instead, Yacc finds a syntax error and substitutes ASSIGN
for OF
and parses using the third exp
rule.
Similar problems occur with lvalue DOT ID
.