[antlr-interest] How to get information on the tokens that produced a tree node?

Jim Idle jimi at temporal-wave.com
Wed Dec 28 15:48:57 PST 2011

Did you check the archives? I am sure that I have answered this before.
But you get the start and end token from the node, then ask the start
token for its information and the end token for its information, and then
you have the complete span of a node. Beware of -> ^(NODE1 c u ^(NODE2 x))
as NODE2 won't get the span information when the rewrite is like that.


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Gonzague Reydet
> Sent: Wednesday, December 28, 2011 2:47 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] How to get information on the tokens that
> produced a tree node?
> Sory for the ping, but is their a way get information on the source
> input (line number for example) from the tree grammar & AST side?
> 2011/12/16 Gonzague Reydet <gonzague.reydet at gmail.com>
> > Hi all,
> >
> > I am working on a lexer & parser grammar that produce an AST from an
> > input file. The AST is then passed to a tree grammar that calls my
> > custom code. I think it is a classic ANTLR pattern, isn't it?
> > When an error is detected during the tree parsing, I am looking for a
> > way to print error with information on the original input tokens, not
> > on the tree node which is not relevant for the end user.
> > How to get information on the origin input file from the display
> error
> > function of the tree grammar? Is there a link between the tree node
> > stream of the AST and the token stream produced by the lexer?
> >
> > Note that my target language is C.
> >
> > Regards,
> > Gonzague.
> >
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address

More information about the antlr-interest mailing list