[prev in list] [next in list] [prev in thread] [next in thread] 

List:       antlr-interest
Subject:    [antlr-interest] Difference in tree parsers
From:       ewbank () gmail ! com (Bryan Ewbank)
Date:       2005-08-24 4:33:33
Message-ID: dd3a065f0508240433382306e8 () mail ! gmail ! com
[Download RAW message or body]

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@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?

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic