ANTLR 中的初学者递归,没有调用堆栈?
ANTLR 中是否存在递归(即存在调用堆栈)?示例:
parenset
: LPAREN
parenset*
RPAREN
;
LPAREN: '(';
RPAREN: ')';
应该验证左括号和右括号的数量一样多。然而,在 ANTLRWorks 1.4.3 中,当我在解释器中输入 '((()))' 时,我得到
我的其他右父母在哪里?!我做错了什么吗?谢谢!
Is there recursion in ANTLR in the sense that there is a call stack? Example:
parenset
: LPAREN
parenset*
RPAREN
;
LPAREN: '(';
RPAREN: ')';
Should just verify that there are as many left parenthesis as there right. However in ANTLRWorks 1.4.3, in the interpreter when I type in '((()))', I get
Where are my other right parens?! Am I doing something incorrect? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用 ANTLRWorks 的解释器:众所周知,它有很多错误。
如果我在 ANTLRWorks 中使用调试器(与解释器不同!),语法为:
并提供输入
((()))
我得到以下解析树:因此,回答您的问题:
不,你没有做错任何事:ANTLRWorks 的解释器把你的事情搞砸了。每当您的语法包含谓词或递归规则调用时,最好使用调试器或编写您自己的测试类。
Don't use ANTLRWorks' interpreter: it is notoriously buggy.
If I use the debugger in ANTLRWorks (not the same as the interpreter!) with the grammar:
and provide the input
((()))
I get the following parse-tree:So, to answer your question:
No, you're not doing anything wrong: ANTLRWorks' interpreter is messing things up for you. Whenever your grammar contains predicates or recursive rule-invocations, better use the debugger or write your own test class.