[antlr-interest] Re: Parser and infinite recursion... ?

idontwantanidwith2000init idontwantanidwith2000init at yahoo.com
Wed Apr 14 11:49:41 PDT 2004


It depends upon the parser algorithem:
If it is a top down alg. 
for example it might try the left nonterminal rule until it reaches 
the first terminal.
As you can see the first set of rules do not have left recursion.

Tal.


--- In antlr-interest at yahoogroups.com, "jbfraleigh" 
<jbfraleigh at h...> wrote:
> Hello -- 
> 
>    I was wondering if someone might be able to explain to me why 
code 
> example 1 works (doesn't produce any error/warning messages) while 
> code example 2 does not work (and hopefully how to fix it).  The 
> output from code example 2 follows the code.  Note that the only 
> difference occurs in "logic_1" where I've changed the definition 
> from: "logic_2" to "logic_2 | logic_3."
> 
> --- Code Example 1:
> 
> logic_1	: logic_2 ;
> logic_2	: (LPAREN logic_3 RPAREN) ;
> logic_3	: logic_4 ((AND|OR) logic_4)* ;
> logic_4	: logic_1 | if_br ;
> 
> ========================
> 
> --- Code Example 2:
> 
> logic_1	: logic_2 | logic 3;
> logic_2	: (LPAREN logic_3 RPAREN) ;
> logic_3	: logic_4 ((AND|OR) logic_4)* ;
> logic_4	: logic_1 | if_br ;
> 
> ========================
> 
> --- Output from Example 2:
> 
> ANTLR Parser Generator   Version 2.7.2   1989-2003 jGuru.com
> xx.g:14:21: infinite recursion to rule logic_3 from rule logic_1
> xx.g:17:11: infinite recursion to rule logic_3 from rule logic_4
> xx.g:16:11: infinite recursion to rule logic_3 from rule logic_3
> xx.g:14:21: infinite recursion to rule logic_3 from rule logic_1
> xx.g:14: warning:nondeterminism between alts 1 and 2 of block upon
> xx.g:14:     k==1:LPAREN
> Exiting due to errors.
> 
> ========================
> 
> This should be functionally equivalent to the following code, 
which 
> does work:
> 
> Code Example 3:
> 
> logic_1	: logic_2 ;
> logic_2	: logic_3 ((AND|OR) logic_3)* ;
> logic_3	: (LPAREN logic_1 RPAREN) | if_br ;
> 
> ========================
> 
> Thanks in advance for any help.



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list