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

Terence Parr parrt at cs.usfca.edu
Wed Jul 18 15:30:32 PDT 2007


On Jul 16, 2007, at 2:12 PM, Hardy, Stephen wrote:

> 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.

Well, this

ds={$declaration_specifiers.st}

is not exactly ANTLR code...you can refer to whatever you want... ;)

>> 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.

You can easily create a template that includes itself using  
references to prior attributes and so on.	I'm afraid that ST is  
probably catching a correct cycle in your ST containment hierarchy.  
Is always caught my problems correctly.

Ter


More information about the antlr-interest mailing list