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

Terence Parr parrt at cs.usfca.edu
Fri Jul 20 19:24:51 PDT 2007


On Jul 20, 2007, at 7:14 PM, Hardy, Stephen wrote:

>
> I managed to resolve this problem.  There was no circular  
> reference, but
> I made the mistake of blithely using null list pointers as template
> parameters, when the grammar used "zero or more" arity (* operator).
> Silly me, I already knew this was a problem for the '?' operator,  
> but I
> thought that lists were somehow handled differently.
>
> The odd thing is that the null List objects were not causing null
> pointer exceptions (as one would expect) but instead would cause
> "random" data to be substituted into the template expansion or, in  
> other
> cases, would create infinite reference loops.

Ouch, really?  hmm...

> So now, the tree grammar is interspersed with stuff like
>
> direct_abstract_declarator
>     : abstract_declarator  (ads+=abstract_declarator_suffix)*
>         -> template(
>                ad={$abstract_declarator.st},
>                ads={($ads==null?"":$ads)})
>            "(<ad>)<ads; separator=\" \">"
> ;
>
> Before, I had simply ads={$ads} which was no good.
>
> Having to put in conditional expressions is not that much of a burden,
> however it seems much cleaner to fix string templates so they check  
> for
> null, and substitute an empty string in this case -- this would be a
> reasonable default.

The optional and (...)* are both optional and yeah I need some kind  
of condition to yield null if not matched.  Surprised by random data  
though. hm...
Ter


More information about the antlr-interest mailing list