使用Yacc和Lex生成解析树
我花了6个小时为LEX和YACC编写了一份编译器。终端报告警告:输入非终端的空规则,没有操作
,但我仍然找不到我的代码出了什么问题。
P -> L | LP
L -> S
S -> ID = E | if C the S | if C then S else S
C -> E>E | E<E | E=E
E -> E+T | E-T | T
T -> F | T*F | T/F
F -> (E)| ID
I've spent 6 hours writing a compiler for the productions below with Lex and Yacc. The terminal report warning: empty rule for typed nonterminal, and no action
but I still can't find out what's wrong with my code.
P -> L | LP
L -> S
S -> ID = E | if C the S | if C then S else S
C -> E>E | E<E | E=E
E -> E+T | E-T | T
T -> F | T*F | T/F
F -> (E)| ID
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到的警告似乎完全准确:
f
是非终端;它有一种类型,第一个替代方案是空的,没有动作。如果非终端没有任何动作的生产,则野牛会自动添加操作$$ = $ 1
,但不能为空生产而做到这一点,因此它抱怨。我假设该行中的
|
是错别字。The warning you get seems completely accurate:
F
is a non-terminal; it has a type, and the first alternative is empty with no action. If a non-terminal has a production with no action, bison will automatically add the action$$ = $1
, but it can't do that for an empty production, so it complains.I assume the
|
in that line is a typo.