[antlr-interest] Re: Putting this all into an AST

offline314159 offline at shaw.ca
Fri Mar 5 08:23:19 PST 2004


Both of those are working like a charm for me.  Now, i'm left with one
problem left, and then this is complete.

i have the following for an item:

item
:
   (name) =>
      baseitem // baseitem starts with (name) always
   |
   groups DOT! baseitem
   ;

Is there a way to plug an empty group into the first alternative, and
use a [group, ""] as the root of a #(group baseitem) tree which will
be the form for both of these?  Or a #([ITEM, "item"] group baseitem)
tree, which might be the better way -- although i think that a group
will be a better, more logical root to the tree.

I tried doing this:

{#item = #([groups, ""], #item);}

but i got back "groups cannot be resolved" in a java.lang.Error

Basically, the groups should be the root, and everything else a node,
and an empty group should still have a group as the root, just with
the text "" instead of a group.

I'm sure i've read how to do this, and i'm looking over the antlr docs
on tree construction now, but i'm missing it, i'm sure.

--- In antlr-interest at yahoogroups.com, "lgcraymer" <lgc at m...> wrote:
> I have to disagree with Monty, here (sorry, Monty).  There are a few
tricks that you can do.  First of all, you want a value rule that 
> builds the subtree with VALUE as root.  The WORD ( DOT WORD )* can
be refactored as
> 
> WORD ( DOT^ WORD ( DOT! WORD )* )?
> 
> to build a tree #( DOT (WORD)+ ) or a single node WORD
> 
> name should probably be inlined (ugly, but that's the way ANTLR 2
works) with ^ appended to each of the token names, but as a 
> brutal hack you can also do
> 
> n:name!  { astFactory.makeASTRoot(currentAST, #n); }
> 
> That's pretty ugly, but 2.8 (if Ter can get a final 2.7.3 release
out the door and I can find time to finish testing the C++ interface)
will 
> provide a better alternative.
> 
> --Loring



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

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



More information about the antlr-interest mailing list