[antlr-interest] automatic tree grammar generation
Loring Craymer
lgcraymer at yahoo.com
Mon May 19 18:14:07 PDT 2008
Ter--
The basic methodology is "refactor until the transformation is obvious". For this one, the sequence is:
a : b ( '+' x = b -> ^('+' $a $x) )* ;
goes to
a : b ( '+' x = b -> ^('+' $a $x) )+
| b
;
after which you factor out
c : b ( '+' x = b -> ^('+' $a $x) )+ ;
which becomes
c : c1 = a '+' x = b -> ^('+' $c1 $x) ;
and substituting back into a gives
a : ^( '+' a b )
| b
;
Cheers!
--Loring
----- Original Message ----
> From: Terence Parr <parrt at cs.usfca.edu>
> To: Kamal Verma <kverma at yahoo.com>
> Cc: Loring Craymer <lgcraymer at yahoo.com>; Bernardo Elayda <belayda at gmail.com>; antlr-interest at antlr.org
> Sent: Monday, May 19, 2008 5:30:21 PM
> Subject: Re: [antlr-interest] automatic tree grammar generation
>
>
> On May 19, 2008, at 4:49 PM, Kamal Verma wrote:
>
> > Wonderful, when can we have it.
> >
> > Few months ago I had similar need and I almost thought of same
> > thing. It will be wonderful if have it as a command line option on
> > antlr. Like "-treeg ". How about string templating the
> > 'AST' of 'antlr' grammar. ( inside the tool )
> >
> > It will also help with understanding of generated AST and debug and
> > develop the grammar.
> >
> > I will love to hear Terence thoughts on this.
>
> Not always easy for -> rewrites even when they use $a vars.
>
> a : (b->b) ('+' x=b -> ^('+' $a $x) )* ;
>
> not sure how i'd figure that out off top of my head.
>
> A basic "get me started" kind of thing would be pretty easy I guess. :)
>
> Ter
More information about the antlr-interest
mailing list