[antlr-interest] Augmenting AST with additional info

Jim Idle jimi at temporal-wave.com
Wed Aug 1 15:25:28 PDT 2012


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


More information about the antlr-interest mailing list