[antlr-interest] Determining Imaginary Nodes

Terence Parr parrt at cs.usfca.edu
Thu Jan 10 18:22:23 PST 2008


On Jan 10, 2008, at 4:26 PM, John Volk wrote:

> Hi,
>
> I'm wondering if there is a way to determine programmatically  
> whether a CommonTree node is an imaginary node (i.e., a node created  
> in a rewrite rule; not from the text of the file being parsed).
>
> I've looked at a few possiblities.  For example, it seems that if  
> the CommonToken for a particular CommonTree node has -1 as it's  
> tokenIndex, then that node is imaginary.  This doesn't catch all the  
> cases, though.  In some cases where an imaginary node is a non-leaf  
> node, it looks like the tokenIndex of the token for that node is  
> somehow derived from the node's children.  This isn't true of all  
> non-leaf nodes, though.  Many will have -1 as the tokenIndex.

Imaginary nodes can be created from real tokens, in which case I copy  
all known info (such as index) into the new node/token.  Why do you  
need this, btw?  You can probably use a TreeAdaptor to mark them  
specially in create().
Ter


More information about the antlr-interest mailing list