[antlr-interest] Changing root node lable

Wilson Urdaneta akikax at gmail.com
Wed Apr 6 00:39:40 PDT 2011


On Wed, Apr 6, 2011 at 3:
> Hi everyone,
>
> This is my first question on this list and I have been using ANTLR for
> about two weeks.
>
> Lets say I want to parse a simple arithmetic expression. For that I
> create a simple grammar - as shown in many of the available examples -
> and I order ANTLR to generate the AST. Now, is there any simple way to
> change the label of each root node so it reflects the value of their
> children? That is, given
>
> (2+3)*4
>
> I would get the following AST
>
> *
>  4
>  +
>    2
>    3
>
> and I would like to get instead
>
> (2+3)*4
>  4
>  (2+3)
>    2
>    3
>
> Instead of only getting * or + On the root nodes I would like to get a
> label with the full content or information or the children at current
> depth.
>
> Currently, I am thinking doing this using the commontree class. Is
> there anyway of specifying this directly at the grammar? Also, I have
> not succeed in this using rewrite rules....
>
> Regards,
>


More information about the antlr-interest mailing list