[antlr-interest] How to walk a tree with an imaginary root

Bryan Ewbank ewbank at gmail.com
Fri Jun 16 06:06:43 PDT 2006


What is the value of "l" when it is parsed?  Try using the "toStringTree"
and "toStringList" methods to discover if the parser is buillding the
correct trees.

One thing that is, to me, curious, is the "!" after ruleAlt.  I don't use
this much, so I'm not sure what it does...

One aside... When I add an imaginary node, as you are doing here, I prefer a
standard idiom:

   ruleAlt : graph  { ## = #( [RULE_ALT,"ruleAlt"], ##); } ;

It may not do anything different, but seeing this as a standard idiom helps
you (and others that read your code) to recognize where you are adding
imaginary nodes.

On 6/15/06, Ëï¼Í¸Õ Jigang (Robert) Sun <sunjigang1965 at yahoo.com.cn> wrote:
>
> In parser, to build a tree,
>    ruleAlt! :l:graph {##=#([RULE_ALT,"ruleAlt"],l);} ;
>
> In tree walker,
>    ruleAlt : RULE_ALT graph ;

got a tree has only "ruleAlt" node without any child,
> runtime error: <AST>: unexpected end of subtree.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060616/0c67479f/attachment-0001.html


More information about the antlr-interest mailing list