[antlr-interest] tricky (to this newby) translation problem

Terence Parr parrt at cs.usfca.edu
Fri Dec 30 10:14:34 PST 2005


On Dec 30, 2005, at 8:31 AM, Kenny Tilton wrote:
>   enumerator
>        :       i:ID            { print( i ); }
>                ( b:ASSIGN      { print( b ); }
>                  expr
>                )?
>        ;
>
> But my problem is that, if the match with an ASSIGN happens, I need  
> to get a left-parens /in front/ of the emitted ID. Otherwise I have  
> to always wrap enumerators in parens:

Hi.  First let me suggest using StringTemplate in combination with  
ANTLR:

http://www.codegeneration.net/tiki-read_article.php?articleId=77

As to your problem.  Try this

enumerator
        :       i:ID
                ( b:ASSIGN      { print( i ); print( b ); }
                  expr
		 |            { print( i ); } // empty grammatical production
                )
        ;

Ter



More information about the antlr-interest mailing list