[antlr-interest] Augmenting AST with additional info

Krishnan Subramanian krishsub at microsoft.com
Wed Aug 1 14:13:16 PDT 2012


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


More information about the antlr-interest mailing list