[antlr-interest] Augmenting AST with additional info

Jim Idle jimi at temporal-wave.com
Thu Aug 2 09:24:10 PDT 2012


It is the index to the token stream, so you just get those tokens out of
the token stream and they then tell you what their start line and offset
are.

Jim

> -----Original Message-----
> From: Krishnan Subramanian [mailto:krishsub at microsoft.com]
> Sent: Thursday, August 02, 2012 2:29 AM
> To: Jim Idle; antlr-interest at antlr.org
> Subject: RE: [antlr-interest] Augmenting AST with additional info
>
> Hi Jim,
>
> The METHOD_DECL node gives me the TokenStartIndex and TokenStopIndex as
> integers (I'm using C#; I don't know if Java is different).
>
> How would one translate the int to the actual token efficiently (e.g.
> as a lookup?)  in order to get the token's line number and offset?
>
> Regards,
>
> -krish
>
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Jim Idle
> Sent: Thursday, August 2, 2012 12:25 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Augmenting AST with additional info
>
> The METHOD_DECL node will give you the first and last token, then you
> can get the line number and offset of the last token.
>
> Jim
>
>
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Krishnan Subramanian
> > Sent: Wednesday, August 01, 2012 2:13 PM
> > To: antlr-interest at antlr.org
> > Subject: [antlr-interest] Augmenting AST with additional info
> >
> > Hi all,
> >
> > I have some information that needs to be augmented to an AST and I
> > cannot figure out how to go about it.
> >
> > It is maybe best to illustrate via an example:
> >
> > Assuming I have a grammar where a method & its method body are
> > declared and the AST as follows:
> >
> > method_declaration
> >                 :               return_type type_name OPEN_PARENS
> > formal_parameter_list? CLOSE_PARENS LEFT_BRACE method_body
> RIGHT_BRACE
> >                                 -> ^(METHOD_DECL return_type
> type_name
> > formal_parameter_list? method_body)
> >                 ;
> >
> > Problem description
> > ================
> > In my AST, for METHOD_DECL (a token), I need to add some information
> > that tells me the location where the method has ended . That is, the
> > line number and column of RIGHT_BRACE.
> >
> > Given that I eliminate RIGHT_BRACE from my AST, is there any
> mechanism
> > to augment METHOD_DECL with (say) the line number and column number
> > information for RIGHT_BRACE?
> >
> > Regards,
> >
> > -krish
> >
> > 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
>


More information about the antlr-interest mailing list