[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Output text from AST
On Thu, 2002-07-25 at 20:05, Jim Moores wrote:
> I had a very similar problem. The easiest way I found to do it is to
> write a custom lexer that builds up a linked list of whitespace
> characters before each token. It then makes an entry into the hashtable
> (using setIn I seem to remember), associating the list with the Token
> that follows it. Then you can simply make the deafaultCase in your
> Walker class look up the list for each token passed to it and print that
> to the output stream before outputting the token's string value. This
> does not pretty print, but does preserve the original comments and
> indentation structure.
I'm not so interested in keeping the original structure. It is not
intended for users to read/access the translated Java code --- just for
the standard Java compiler to compile it. It would be nice to have it
slightly formatted, even if not in the original style, but is not a
> PS. No disrespect to SableCC (it's the first Compiler-Compiler I've
> ever been able to get my head around!), but if you are implementing a
> Java pre-processor, you might want to look at EPP which has access to
> type information and might be easier (although the documentation is
> awful and the learning curve quite steep).
I was initially going to use this, but it does not allow for the radical
AST transformations that I require. It also more difficult to preserve
states and other information between parses.
Also, state two of my project would have been impossible to implement
with EPP, but SableCC should allow me to do it by simply changing a few
Type information is also not a requirement for the application I'm
As you also mentioned, the learning curve *is* very steep, and with such
bad documentation, I did not have the time to pursue EPP as an option
(The project is part of my thesis).
This made me look towards SableCC, and I'm very happy that I did. So
far, it has been everything that I had required :)
Nicholas Read, BSc
ICQ #: 20770226
"Bud, if dynamite was dangerous do you think they'd
sell it to an idiot like me?"
- Al Bundy, "Married with Children"