我正在通过 Appel 的“现代编译器在 ML 中实现”一书中生成 Tiger Parser 的 Ch3 编程练习。我的tiger.grm 文件在这里。我试图诊断的错误是由一元和二元减号运算符的规则引起的减少-减少冲突。这是 yacc 错误:
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on OR
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on AND
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on GE
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on GT
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on LE
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on LT
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on NEQ
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on EQ
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on DIVIDE
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on TIMES
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on MINUS
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on PLUS
error: state 128: reduce/reduce conflict between rule 48 and rule 46 on RPAREN
state 128:
boolean : exp . AND exp
boolean : exp . OR exp
arithmetic : MINUS exp . (reduce by rule 46)
arithmetic : exp . PLUS exp
arithmetic : exp . MINUS exp
arithmetic : exp MINUS exp . (reduce by rule 48)
arithmetic : exp . DIVIDE exp
arithmetic : exp . TIMES exp
comparison : exp . EQ exp
comparison : exp . NEQ exp
comparison : exp . GT exp
comparison : exp . LT exp
comparison : exp . LE exp
comparison : exp . GE exp
我已经定义了 UNARY 的优先级高于 MINUS,并在我的规则中使用%prec
. 当然,当我删除任一规则时,冲突就会消失,但语法会错误地解析 MINUS 符号。
我无法诊断此错误 - 有什么想法吗?