[antlr-interest] infinite loop in tree

Monty Zukowski monty at codetransform.com
Wed Sep 22 09:27:03 PDT 2004


On Sep 21, 2004, at 9:35 AM, antlruser wrote:

> Hey everyone,
> I have a situation where the following string may arise
>
> blah CLIPPED
>
> I want to represent this in an AST as:
>
> LS_CLIPPED
>    |
>    blah
>
> so I have the following in my grammer
>
> factor
>   : v:variable (l:leftSidedOperators[#v] { #factor=#l; })?
>   ;
>
> leftSidedOperators[AST operator]
>   : CLIPPED {#leftSidedOperators = #(#[LS_CLIPPED,"LS_CLIPPED"],
> #operator);}
>   ;
>
> However when the AST is generated I get a StackOverflowError and as
> infinite representation of the Tree like
> LS_CLIPPED->blah->LS_CLIPPED->blah->LS_CLIPPED etc.
>
> Can anyone help me with this.
> Thanks in advance,
> Mark
>
>

Yeah, you should turn off automatic tree building for factor:

factor!:
....

In fact you should do that for leftSidedOperators as well.  In general 
if you are constructing trees with actions you want to turn off the 
automatic tree construction.  This is a common reason for having an 
infinite loop in a tree.

Monty

ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit -- 
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html



 
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