[antlr-interest] rewriting stream or generate own trees

Gregor Pardella kruemmel99 at yahoo.de
Wed Feb 23 09:09:57 PST 2005


Hi,

thanks for the answer, I have to admit that after 
writing the mail I came to the same solution ;-)

But now I find a other strange behavior of my grammar
:-(

I will post it later as a seperate thread!

gregor

 --- Bryan Ewbank <ewbank at gmail.com> schrieb: 
> One solution is to delay the problem until you emit
> the code, and then
> the output rule for increment emits the XML cruft:
> 
>     | #( PLUSPLUS id:identifier }
>            { cout << id->getText() << " = 1 + " <<
> id->getText(); }
> 
> Delaying it this far also allows a very simply
> rewrite if assembler is
> extended to support increment (and shows you planned
> ahead :-)
> 
> Another option is to have a tree rewrite that
> converts "++" into
> "a=a+1", but you need to make sure and generate a
> copy of the "a"
> node, rather than attempt to reuse the same node
> twice (kaboom; segv).
> 
> I wrote a trivial little tree walker that I call
> COPY(node) for just
> that reason.  It's a handy beastie to have around:
> 
>     | #(PLUSPLUS id:identifier }
>       {  ## = #( #[ASGN],
>                    COPY(#id),
>                    #( #[PLUS],
>                         #id,
>                         COPY(GlobalOneTree) ) ); }
> 
> 
> On Tue, 22 Feb 2005 11:55:06 +0100 (CET), Gregor
> Pardella
> <kruemmel99 at yahoo.de> wrote:
> > the source C-like language allows code like this:
> >      int a=0;
> >      a++;
> > 
> > The problem is now, that the target language (a
> XML
> > assembler like one) has no
> > OP-Code for INCREMENT :(
>  


	

	
		
___________________________________________________________ 
Gesendet von Yahoo! Mail - Jetzt mit 250MB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de


More information about the antlr-interest mailing list