Beginner Recursion in ANTLR, no call stack?
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!
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:
grammar T;
parenset
: LPAREN parenset* RPAREN
;
LPAREN : '(';
RPAREN : ')';
and provide the input ((()))
I get the following parse-tree:
So, to answer your question:
Where are my other right parens?! Am I doing something incorrect?
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.
精彩评论