[antlr-interest] AST Question

Bart Kiers bkiers at gmail.com
Fri May 20 13:56:36 PDT 2011


On Fri, May 20, 2011 at 9:54 PM, massimiliano.masi at gmail.com <
massimiliano.masi at gmail.com> wrote:

> Hi,
>
> On Fri, May 20, 2011 at 10:55 AM, Bart Kiers <bkiers at gmail.com> wrote:
> > targetsExpr
> >   :  category ('CAND' targetsExpr)* -> ^('CAND' category targetsExpr*)
> >   ;
> >
> > is incorrect. You're always using `CAND` in your rewrite rule but that
> rule
> > could just match `category` only.
> > You'll probably want to do:
> >
> > targetsExpr
> >   :  category ('CAND'^ targetsExpr)*
> >   ;
> >
>
> Thank you for your answer! It works now! But I've another question now.
> When I traverse the tree using this function (is there an example to
> have a visitor
> created by antlr?)
>

Yes, this is typically what tree grammars are for. But you can also walk it
manually.
See:

http://www.antlr.org/article/1100569809276/use.tree.grammars.tml
http://www.antlr.org/article/1170602723163/treewalkers.html

Regards,

Bart.


More information about the antlr-interest mailing list