[antlr-interest] (newbie question)the right way for writting rewrite rules

Randall R Schulz rschulz at sonic.net
Tue Jul 10 15:25:57 PDT 2007


On Tuesday 10 July 2007 15:02, ali azimi wrote:
> Hi,
>
>   Thank you very much for all your supports.
>
>   For the following grammar which rewrite rule is correct? 1 or 2
>
>   operatorApplication
>
>  :operatorIdentifier'('expression(','expression)*')'
>
>  ;
>
>   1->^(operatorIdentifier expression+)
>
>   2->^(operatorIdentifier expression)+

As ever, it depends on what you want!

The first will produce a single sub-tree labelled with the 
operatorIdentifier and with all the expressions as its children.

The second will produce as many sub-trees as their are expressions. Each 
of those subtrees will be labelled with the operatorIdentifier and have 
one of the expressions as its only child.

If you have Terence's book, TDAR, you can find this exact issue treated 
in the section titled "Duplicated Nodes and Trees" (page 167 of the 
printed book, page 180 of the PDF).


>   Best wishes,
>
>   Al


Randall Schulz


More information about the antlr-interest mailing list