我有以下 yacc/bison/happy 语法:
%token
if TokenIf
then TokenThen
else TokenElse
true TokenTrue
false TokenFalse
%left APP
%right IF
%%
Hungry
: NoHungry
| Hungry NoHungry %prec APP
| if Hungry then Hungry else Hungry %prec IF
NoHungry
: true
| false
bison -v
告诉我以下情况有两个冲突:
State 12
2 Hungry: Hungry . NoHungry
3 | if Hungry then Hungry else Hungry .
true shift, and go to state 2
false shift, and go to state 3
true [reduce using rule 3 (Hungry)]
false [reduce using rule 3 (Hungry)]
$default reduce using rule 3 (Hungry)
NoHungry go to state 8
我试图通过给出明确的优先级声明来解决冲突%prec
,但无济于事。鉴于野牛根据需要解决了冲突(例如,转变而不是减少),这还不错,但我想知道我们如何在不改变公认语言的情况下摆脱冲突。