[antlr-interest] Why no children in tree generated by C++ parser?

Bryan Ewbank ewbank at synopsys.com
Thu Oct 7 14:59:44 PDT 2004


> The AST that I get seems to have only siblings of the root.
>
> Is this because the C++ grammar does not define any structure for ASTs?
> If so, how am I supposed to create a useful tree? Should I modify the
> grammar, subclass the parser or is there something else I'm missing?

The default tree is really a forest - there's no root - so you need to
traverse the nextSibling list to see the rest of the stuff.  You can create
a single root by adding the appropriate tree construction action; it will
look something like this (assuming a dummy token ITEMLIST):

program : ( decldef )* { #program = #( #[ITEMLIST, "ITEMLIST"], #program); }

This replaces the default forest of trees (one per matched child) with a
single tree rooted at the new node ITEMLIST.



 
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