[antlr-interest] generating root nodes in tree parser

Martin Probst mail at martin-probst.com
Tue Jul 12 09:32:57 PDT 2005


> 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); };

> Actually, what is the best way to represent function calls in syntax
> trees? This is just what I thought would be right.

That's probably a matter of personal preference and depends also on what
you want to do with it later on. Some people store function identifiers
in the AST nodes themselves as it provides somewhat of a terser access
to them.

Regards,
Martin



More information about the antlr-interest mailing list