Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 EBNF 表示法中有这个语法:
expr -> expr (opt1 | opt2 | opt3) expr
我想将其转换为 BNF 以在 Bison 中使用它,但我在此遇到 shift/reduce 错误:
expr : expr opt1 expr | expr opt2 expr | expr opt3 expr
我想我在此过程中误解了一些东西。有什么帮助吗?
谢谢
怎么样
expr: expr optexpr expr optexpr: opt1 | opt2 | opt3
shift/reduce 错误是由于 expr 前缀重叠造成的。通过引入另一个定义,对 expr 的解析变得明确。