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

Gonzague Reydet gonzague.reydet at gmail.com
Thu Dec 29 11:01:32 PST 2011


Thank you for the reply Jim!
Actually I did not know what keyword to search for my question in
markmail...

I did not tried again since your reply but I remember from my initial
investigation that the tokens' information of the start & end base tree
only gave information of the node position on the AST, not the line and
character number in the input file.
Am I wrong?

Regards,
Gonzague

2011/12/29 Jim Idle <jimi at temporal-wave.com>

> 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.
>
> Jim
>
> > -----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
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>



-- 
Tél : +33 (0)6 21 02 90 48


More information about the antlr-interest mailing list