[antlr-interest] Re: Putting this all into an AST
mzukowski at yci.com
mzukowski at yci.com
Fri Mar 5 09:45:46 PST 2004
Remember, only tokens, not rules, can be made into a root. So {#item =
#([groups, ""], #item);} makes no sense because "groups" is a rule. ANTLR
isn't smart enough to know if the rule "groups" only returns a single token.
And I don't know because you didn't post the groups rule. So more detail is
needed to help you.
Monty
-----Original Message-----
From: offline314159 [mailto:offline at shaw.ca]
Sent: Friday, March 05, 2004 8:23 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: Putting this all into an AST
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
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