bison -d
你的输入给了我:
test.y:6.17-20: symbol CODE is used, but is not defined as a token and has no rules
test.y:6.13-15: symbol DEC is used, but is not defined as a token and has no rules
它准确地告诉你问题是什么——你正在使用CODE
而DEC
不是定义它们。将它们添加到其中%token
一行,它工作正常......
编辑
错误“开始符号 S 没有派生任何句子”告诉您您的语法中有无限递归,因此没有(有限)输入可以匹配开始符号。在您的情况下,S
必须包含 a CODE
,其中必须包含 a command
(直接或通过 a listcommand
),其中必须包含 a boucle
,而后者又必须包含另一个listcommand
。所以你最终会得到一个无限的扩展链listcommands
-> command
-> boucle
-> listcommands
。
问题可能是你的规则
listcommands: command | listcommands ;
它完全匹配一个命令,加上该命令的无用(和模棱两可)无界 noop 扩展。你可能想要
listcommands: /*epsilon*/ | listcommands command ;
它按顺序匹配 0 个或多个command
s。进行此更改修复了致命错误,但仍然留下了一堆 shift-reduce 冲突,以及无用的 rule dectype: dectype
。
要跟踪和修复 shift/reduce 冲突,请使用bison -v
生成.output
详细列出语法、状态和冲突的文件。你的大部分来自没有优先级 for NOT
,另外两个来自于模棱两可dectype
和CODE
规则。