[antlr-interest] A basic question about AST construction operators

Hitesh Shetty hitesh.p.shetty at gmail.com
Tue Aug 10 09:19:20 PDT 2010


Hello,

First of all, Thank you Mr. Jim for your reply.
The question was actuall sent in reference to the Definite ANTLR reference,
table 7.1 found on page 176,  which mentions that the first non-suffixed
element becomes the first child of the root of the subtree. This seemed
in-consistent with the grammar rules mentioned in the earlier mail.

What is your opinion about this.

Regards,
Hitesh

On 8/9/10, Hitesh Shetty <hitesh.p.shetty at gmail.com> wrote:
>
> Hi,
>
> Im a newbie ANTLR user and I had a basic question about the AST
> construction operator '^' caret,
> When the AST construction operator '^' (caret) is used along with a normal
> rule such as
>    condStatement : 'expression' ^ x=statement1 (y=statement2)? ;
> The term 'expression' becomes the root for the tree and the next
> un-suffixed element i.e $x becomes the first child and $y becomes the second
> child. This can be rewritten as ^('expression' $x $y?).
> However when the operator '^' is used along with a subrule such as
>    expr : x=INT ('+' ^ y=INT)* ;
> The $x is chosen as the first child not the next unsuffixed element i.e $y.
> For example input 1+2 is parsed as ^('+' 1 2) and not as ^('+' 2 1)
> Am I missing something obvious or Is this the behaviour of the AST
> construction operator ?
> Any pointers would be greatly appreciated.
>
>
>


More information about the antlr-interest mailing list