[antlr-interest] rewriting stream or generate own trees

Gregor Pardella kruemmel99 at yahoo.de
Tue Feb 22 02:55:06 PST 2005


Hi,

I'm relativly new to ANTLR and I've got a (possibly
trivial) problem:

I'm working on a compiler for a C-like language, and
parsing was not such a
big deal, but:

the source C-like language allows code like this:
     int a=0;
     a++;

or
     int a = 0; int b;
     b = a++

The problem is now, that the target language (a XML
assembler like one) has no
OP-Code for INCREMENT :(

So now I want to replace the INCREMENT (e.g. a++)
calls by (a=a+1) _on-the-fly_.
(maybe in the lexer but preferable in the parser).

Now I construct trees like:

a++    =>           ++
  generates tree    |_ a

but I want to have

a++    =>         =
                  |_ a
                  |_ +
                     |_ a
                     |_ 1

My expression definition looks like the one in java.g
which can be found on
the ANTLR web-site.

Is there a cute trick doing it, or is the only
solution to build
a preprocessor and replace it before starting
parsing??


Thanks for your help.

gregor



	

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


More information about the antlr-interest mailing list