Shift/Reduce 由于 epsilon 规则,第一个状态发生冲突

Shift/Reduce conflict in first state due to epsilon rule

我在 bison 中有 shift/reduce 冲突。

我检查了 parser.output 文件:

State 0

0 $accept: . Prog $end

STRUCT  shift, and go to state 1

$default  reduce using rule 6 (Structs)

Prog        go to state 2
Structs     go to state 3
StructDec   go to state 4

我有规则:

Prog    :   Structs Funcs {};
Structs :   StructDec Structs | {};
StructDec : STRUCT ID LB StrctMmLst RB SC{};

Prog 是开始符号。

%start Prog

我认为原因是结构的 epsilon 规则。如何在不改变意思的情况下解决?

解决方案实际上是查看文件的开头。 在那里你可以看到冲突状态的数量。我看的那个完全不冲突