尝试示例语法时解析器的奇怪行为
我试图了解 antlr3,我粘贴了 表达式评估器< /a> 进入 ANTLRWorks 窗口(最新版本)并编译它。它成功编译并启动,但有两个问题:
- 尝试使用
1+2*4/3;
的输入导致解析器的实际输入为1+2*43
代码>. - 它在图形解析器树中显示的错误之一是
MissingTokenException(0!=0)
。
由于我是 antlr 的新手,有人可以帮忙吗?
I'm trying to get the feel for antlr3, and i pasted the Expression evaluator into an ANTLRWorks window (latest version) and compiled it. It compiled successfully and started, but two problems:
- Attempting to use a input of
1+2*4/3;
resulted in the actual input for the parser being1+2*43
. - One of the errors it shows in it's graphical parser tree is
MissingTokenException(0!=0)
.
As i'm new to antlr, can someone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您链接到的示例不支持除法(只需查看代码,您就会发现这里没有除法:
The example you linked to doesn't support division (just look at the code, you'll notice there's no division here:
我们常常会得到
当我们犯错误时, 。我认为这意味着它找不到它正在寻找的令牌,并且可能是由不正确的令牌生成的。解析器有时可能会根据语法“恢复”。
还请记住,词法分析器在解析器之前运行,您应该检查实际传递给解析器的标记。 AntlrWorks 调试器在这里非常有帮助。
We often get
when we make mistakes. I think it means that it cannot find a token it's looking for, and could be produced by an incorrect token. It's possible for the parser to "recover" sometimes depending on the grammar.
Remember also that the LEXER operates before the parser and your should check what tokens are actually passed to the parser. The AntlrWorks debugger can be very helpful here.