[antlr-interest] How to get number of children in a tree?

Tim Clark timgclark at gmail.com
Wed Jun 13 09:30:39 PDT 2007


Hi all

In my parser (output=AST) I have two rules like this:

exprList : expr (COMMA! expr)*  |  // Empty ;

funcCall : ID LPAREN exprList RPAREN -> ^(FUNC_CALL ID exprList) ;

So a sentence fragment like "foobar()" produces ^(FUNC_CALL foo)

and one like "foobar(1,2,3)" produces ^(FUNC_CALL foo 1 2 3)


In a later pass, a tree grammar has this:

funcCall: ^(FUNC_CALL ID expr*
     {
       within this action, how can I get hold of the number of expressions?
       or, indeed, iterate over the expressions themselves (say in reverse
order)?
     }
);

I hope that's clear enough for someone to help :)

Regards, Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070613/c5926f43/attachment.html 


More information about the antlr-interest mailing list