[antlr-interest] manual AST creation

Ric Klaren klaren at cs.utwente.nl
Tue Sep 16 02:36:27 PDT 2003


On Fri, Sep 12, 2003 at 10:47:41AM -0000, Ben wrote:
> I am totaly new to ANTLR, so forgive me, if I ask something stupid
> or obvious...
> Here is a part of a very simple grammar I use for testing
> start!: b:(B)* NEWLINE;
> 	{#start = #([B,"start"],b);};
> I would like to construct a tree that looks like that
> (start B B B B...). The action above does not work. I also
> tried to substitute (B)* with another rule, but that does not
> work, too. I believe that I am missing some basic understanding
> here. Can someone enlightmen me??

You probably want something like:

{ ## = #([B,"start"],##); }

This adds a topnode of 'type' B with text "start" hooked to it. The b:(B)*
notation would be a labeled subrule which is not implemented at the moment
(newer versions of antlr give a warning of it)


    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
  Xander: "Buffy, we need to do something *now*"
  Angel: "We need a distraction."
  Buffy: "Right."
  Angel: "What are you going to do?"
  Buffy: "I'm going to kill them all. That oughtta distract 'em..."


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list