[antlr-interest] Determining Imaginary Nodes

John Volk john.t.volk at gmail.com
Fri Jan 11 08:20:30 PST 2008


On Jan 10, 2008 8:22 PM, Terence Parr <parrt at cs.usfca.edu> wrote:

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


Basically, I'm creating an AST, doing some processing on it, and then
attempting to highlight relevant tokens in a GUI.  The processing step might
tell me that, for example, the ALT token created by the ANTLRv3 grammar
needs to be highlighted.  I need to be able to determine that the ALT token
is not actually present in the text of the grammar I'm parsing, and I need
to be able to do this for arbitrary grammars.

TreeAdaptor is the way to do this?  I'm not very familiar with that really,
but I'm sure there's stuff out on the web.

- John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080111/491824f2/attachment.html 


More information about the antlr-interest mailing list