[antlr-interest] generating root nodes in tree parser

Terence Parr parrt at cs.usfca.edu
Tue Jul 12 09:34:45 PDT 2005


On Jul 12, 2005, at 9:32 AM, Martin Probst wrote:

>> Is there a way to add a root node that is not part of the parser
>> grammar? e.g. I when the parser sees a function call I want to
>> generate a subtree with a root such as CALL and two children.
>>
>
> Yes, for example:
>
> functionCall: id:ident pl:paramlist { ## = #(#[CALL,'function call'],
> #id, #pl); };

And in ANTLR v3, you can say:

functionCall : ident paramlist -> ^(CALL["function call"] ident  
paramlist) ;

:)

Ter



More information about the antlr-interest mailing list