[antlr-interest] rewrite rule translation to tree grammar

Johannes Luber jaluber at gmx.de
Fri Dec 14 14:43:34 PST 2007


Terence Parr schrieb:
> 
> On Dec 14, 2007, at 1:34 PM, Johannes Luber wrote:
> 
>> Terence Parr schrieb:
>>> First, allow me to suggest:
>>>
>>> expr : INT ('+'^ INT)* ;
>>>
>>> To match either in tree grammar:
>>>
>>> expr : ^('+' expr expr)
>>>    | INT
>>>    ;
>>
>> So my rule should be:
>>
>> qualified_identifier
>>   :   (i1=IDENTIFIER -> ^(QUALIFIED_IDENTIFIER $i1))
>>       (DOT i2=IDENTIFIER -> ^(ROOT $qualified_identifier DOT $i2))*
>>   ;
> 
> why not
> 
> qid : ID (DOT^ ID)* ;
> 
>> And the tree grammar equivalent:
>>
>> qualified_identifier
>>   :   ^(ROOT qualified_identifier DOT i2=IDENTIFIER)
>>   |   ^(QUALIFIED_IDENTIFIER IDENTIFIER)
>>   ;
> 
> qid : ^(DOT qid)
>       |  ID
>       ;

Because I didn't realize that DOT equals '.'... I will change my grammar
 accordingly. But now I've got two other questions:

1. What is the right translation for c?

r[CommonTree c] : ID -> ^(ID {$c}) ;

2. What do I have to write in this instance to make it syntactically
correct?

s: NEW t[$NEW.tree] -> t;

t[CommonTree newTree]: q -> ^(q {$newTree});

Johannes


More information about the antlr-interest mailing list