[antlr-interest] rewrite rule translation to tree grammar

Terence Parr parrt at cs.usfca.edu
Fri Dec 14 13:16:12 PST 2007


On Dec 14, 2007, at 1:09 PM, Johannes Luber wrote:

> Terence Parr schrieb:
>> hi. that seems incorrect to me.  You can't have a tree as a root  
>> node.
>> Imagine creating $qualified_identifier as tree in first subrule then
>> making root in (...)*.  Probably not right.
>> Ter
>
> Having thought about your answer, it explains one of my  
> difficulties. I
> tried to mimic the following example:
>
> expr : (INT -> INT) ('+' i=INT -> ^('+' $expr $i) )* ;
>
> The solution seems to be that I need an equivalent for the '+'. But my
> rule doesn't have a token which could be the overall root. What do you
> suggest? And what would be the tree grammar equivalent?

First, allow me to suggest:

expr : INT ('+'^ INT)* ;

To match either in tree grammar:

expr : ^('+' expr expr)
	| INT
	;

Ter


More information about the antlr-interest mailing list