[antlr-interest] The right way to invoke templates with null arguments?

Terence Parr parrt at cs.usfca.edu
Thu Jun 21 17:25:34 PDT 2007


On Jun 21, 2007, at 8:57 PM, Tim Clark wrote:

> Hi
>
> My application is outputting 'assembler code' for a stack machine.
> Corresponding to this tree parser rule:
>
> -------------A------------------
> ifStatement
>     :
>     ^(IF_STAT e=expr s1=statement s2=statement?)
>      -> ifStat(
>              expr={$e.st},
>              stat1={$s1.st},
>              stat2={$s2.st},
>              L1={myHelper.nextLabel ()},
>              L2={myHelper.nextLabel()}
>          )
> -------------------------------
>

Hi. the problem is that s2 may be null since it's optional. I've not  
got a good way to say $s2.st in the {...} w/o getting an error (have  
to have a cumbersome conditional in there).  I've got a bug report in  
about this.

Ter


More information about the antlr-interest mailing list