[antlr-interest] Bug in ASTFactory.cpp, version 2.7.3

Ric Klaren ric.klaren at gmail.com
Thu Dec 30 06:31:16 PST 2004


On Thu, 30 Dec 2004 08:26:16 -0500, Waldemar Sauer
<waldemarsauer at hotmail.com> wrote:
> I am bumping into some infinite loops in ASTFactory.cpp, and I was wondering
> if this is a bug in that code, or if there is maybe something about the
> antlr grammar that I'm not understanding. I think rather the former, because
> the compiled compiler should never run into an infinite loop, but rather
> cast exceptions if there are problems that it is experiencing. 

The basic problem is that the current tree building does not work
reliable in cases like this when your touching the tree while it is
being built. When you want to do something like this you need to turn
off tree construction on the rule or on the alternative of the rule
and construct the tree for that part completely yourself.

> One grammar fragment that is causing this is as follows: 
> 
> primaryExpr: 
> 
>         literal_value 
> 
>       | id:ident (ap:actualParams)? { 

Of the top of my head suffix the | with a ! and you should have the
right behaviour.

>             if (#ap.get() != NULL) { 
> 
>                   #primaryExpr = #([MEM_CALL, "MEM_CALL"], #id, #ap); 
> 
>             } else { 
> 
>                   #primaryExpr = #id; 
> 
>             } // if 
> 
>         } 
...
> Like I said, I've seen this problem before, and usually there is a way I can
> get out of it by redefining what I would like to be doing, just in this
> case, I haven't found the workaround in the grammar yet. 

See above...

> I resolved the issue by patching the ASTFactory::make code to check for this
> condition (see end of posting), but I need someone to look at the code, and
> say if it is the right thing to do, or if there is an issue with my
> definition of the grammar. 

It is indeed an option to do this. 3.0 might do this per default. I
recall discussing it at least.... So far no plans exist to change this
for the 2.7 series.

Cheers,

Ric


More information about the antlr-interest mailing list