[antlr-interest] Difference in tree parsers

Bryan Ewbank ewbank at gmail.com
Wed Aug 24 04:33:29 PDT 2005


There are differences, but perhaps not in the way you are thinking of
them.  I usually use imaginary nodes to mark a tree for later
processing, or if I've figured out something important about that
node.

For example, an LCURLY can be either (1) a block statement or (2) a
set expression.  That means once I figure out which it is, I will
likely replace the LCURLY with BLOCK or SETEXPR,  To preserve source
file information, I typically just overwrite the type of the node
rather than replacing it:

   // overwrite node type:
   a_rule
   :
      ( LCURLY^ ... )
      { if (isStatement(##)) ##->setType(BLOCK) else ##->setType(SETEXPR); }
   ;

In later tree parsers, it is now easy to distinguish between BLOCK and
SETEXPR by the type of the node, rather than having to rediscover the
flavor of LCURLY...

Hope this helps

On 8/24/05, Serafettin Senturk <serafettin_sentuerk at intergral.com> wrote:
> I had a look at the "treewalk/treewalk.g" where the LCURLY is used as the
> root of the AST. In the "imagNodeAST/treewalk.g" file it uses the imaginary
> BLOCK token as the root. What is the difference between these taking
> different kinds of roots, one is normal root with "^" and one is imaginary
> token. Are they really different from each other?


More information about the antlr-interest mailing list