I have the following yacc grammar:
33 CompSt: "{" DefList StmtList "}"
34 | "{" error ";" DefList StmtList "}"
......
52 DefList: Def DefList
53 | %empty
54 Def: Specifier DecList ";"
55 | Specifier error ";"
56 | Specifier DecList error ";"
57 | Specifier VarDec "[" error ";"
58 | Specifier VarDec "[" INT error ";"
59 DecList: Dec
60 | Dec "," DecList
61 Dec: VarDec
62 | VarDec "=" Exp
I add the rule 34 to handle the situation when an illegal item appears at the beginning of a pair of brace. I think this rule is necessary (If you have any other methods, please tell me), but there is a shift/reduce warning:
33 CompSt: "{" . DefList StmtList "}"
34 | "{" . error ";" DefList StmtList "}"
error shift, and go to state 45
STRUCT shift, and go to state 2
TYPE shift, and go to state 3
error [reduce using rule 53 (DefList)]
I don't understand why "error" can be reduced by rule 53, and I have no idea how to fix this warning.
Thank you very much for your reply.