gpt4 book ai didi

bison - 这个 Bison 代码中的 shift/reduce 冲突来自哪里?

转载 作者:行者123 更新时间:2023-12-01 07:16:26 25 4
gpt4 key购买 nike

我正在尝试解析此语法:

34 + 1 − 8, 32 * 87 + 6 / 4, 34 / 8

我希望像这样接地:
(, (- (+ 34 1) 8) (/ (+ (* 32 87) 6) 4) (/ 34 8))

这是 BISON 的代码:
%token NUMBER
%token COMMA
%token OPERATOR
%left OPERATOR
%left COMMA
%%

term: NUMBER | term op term ;
op: OPERATOR | COMMA;
%%

有一个问题:
test.y: conflicts: 2 shift/reduce

我该如何解决?

最佳答案

要查找冲突的位置,请使用 --verbose选项并查看文件 example.output您的输入文件在哪里 example.y .这是我从您的输入中获得的文件:

State 7 conflicts: 2 shift/reduce

(略)
state 7

2 term: term . op term
2 | term op term .

COMMA shift, and go to state 4
OPERATOR shift, and go to state 5

COMMA [reduce using rule 2 (term)]
OPERATOR [reduce using rule 2 (term)]
$default reduce using rule 2 (term)

op go to state 6

关于bison - 这个 Bison 代码中的 shift/reduce 冲突来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3264884/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com