On 03/08/2011 01:45 PM, [email protected] wrote:
> Thanks Jim
> 
> In order to get the right tree I ended up with this:
> 
> rhs
>       : a=rhs_alt (OR b=rhs)*
>       ;
> 
> 
> Sorry to labor the point here but what I keep failing to see is how you 
> spec a rewrite rule for this kind of expression. I know the default gets 
> me what I need but that's not quite the same as knowing :)

Sorry, I'm not Jim.  B^)

When I write tree grammars (I've only written a couple), I think of what
the trees will look like, and write the grammars to match the trees that
could possibly be walked as input.  If it helps you to think of what the
trees will look like, consider this:  Most parsed trees are a list of
root nodes.  What can those root nodes have for children.  Create rules
for those cases and for the cases of when those children are themselves
trees (and not single nodes).  When there are multiple possibilities,
either handle them with alternations or with multiple rules to be able
to match all possible cases.

Pretty simple when you think about it, but its not exactly the same as
trying to parse the source code into an AST (at least its not how *I*
think about it).

> I do not want to use the list idiom Ter mentions in the book. Are 
> sub-rules the only way to do it?

-- 
Kevin J. Cummings
[email protected]
[email protected]
[email protected]
Registered Linux User #1232 (http://counter.li.org)

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to