[antlr-interest] StringTemplate stack overflow exception, stringtemplate-3.0

Hardy, Stephen Stephen_Hardy at rabbit.com
Mon Jul 16 14:12:00 PDT 2007


Terence,

I'm not sure I entirely understand what you mean by "one template
enclosing itself", however based on examination of the FAQ and other
sources, these recursion problems can only arise when constructing and
using templates in java code, where the code can obviously set up
circular references via setting of attributes.  

My tree grammar template rewrite rules, on the other hand, are entirely
constructed using in-line (anonymous) templates -- look mum, no java --
and hence if there are any circular references then they are created by
the magic of ANTLR.  

If there is a recursive rule (say, compound statement in a C grammar)
then nested compound statements get their own instance of the template,
hence there can be no circular references at the java "pointer" level?
If I am wrong, would you kindly provide a small counterexample?

With respect, I would say that this potential for stack overflow
exceptions in an ANTLR-generated parser with no "open code" is a serious
bug, especially if the bug is only revealed at run-time.

> Those refs are what attributes are used in that template instance.

There is something fishy going on.  If this is the list of attributes,
then the given trace did not make sense.

Regards,
SJH

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Terence Parr
> Sent: Monday, July 16, 2007 12:21 PM
> To: antlr-interest Interest
> Subject: Re: [antlr-interest] StringTemplate stack overflow
> exception,stringtemplate-3.0
> 
> 
> On Jul 15, 2007, at 6:43 PM, Hardy, Stephen wrote:
> 
> > OK, welding done...
> >
> >
> >
> > Well , it turns out that there *is* a loop in the template
> > inclusion, but there are more steps than indicated by the trace.
> > Maybe there's a limit in the code somewhere.  However, I don't
> > understand why this should cause an exception since recursion is
> > such a natural part of most grammars.
> 
> Hi.. Recursion is fine, it's an error though when a ST directly or
> indirectly encloses itself.  Look for something like that: a block
> that encloses itself.
> > What is the interpretation of the "references=[...]" stuff in the
> > trace.  Sure, I have scs and d attributes in some of the templates,
> > but not in any of those listed.  Maybe it is some sort of run-time
> > indication of how it got to the particular state.  Needs a bit of
> > explanation though.
> Those refs are what attributes are used in that template instance.
> 
> Ter


More information about the antlr-interest mailing list