[antlr-interest] Could anyone give an example fo making a linked
list using antlr?
Bryan Ewbank
ewbank at gmail.com
Mon Feb 20 08:11:45 PST 2006
I'm guessing here that what you mean is a single node with all the
"exp" nodes under it, rather than a tree of COMMA nodes, each with two
children.
> Could anyone give an example for making a linked list using antlr?
>
> My grammar is
> explist: exp (COMMA^<AST=ExpList> exp)* ;
This will, as you probably know, produce a left-to-right tree.
To produce a single-level tree, use this instead:
explist: exp (COMMA! exp)* { ## = #( #[EXPLIST], ## ); }
To produce a right-to-left tree (for exponentiation, e.g.):
explist : exp ( POWER^ explist )? ;
More information about the antlr-interest
mailing list