Related articles |
---|
Generating Source Code. dara_gallagher@my-deja.com (1999-10-06) |
Re: Generating Source Code. rod.bates@boeing.com (Rodney M. Bates) (1999-10-11) |
Re: Generating Source Code. chase@world.std.com (David Chase) (1999-10-11) |
Re: Generating Source Code. smith@gandalf.uni-trier.de (Craig Smith) (1999-10-11) |
Re: Generating Source Code. cmilner@virginia.edu (Christopher W. Milner) (1999-10-11) |
Re: Generating Source Code. anton@mips.complang.tuwien.ac.at (1999-10-13) |
Re: Generating Source Code. thetick@jguru.com (Scott Stanchfield) (1999-10-13) |
[4 later articles] |
From: | dara_gallagher@my-deja.com |
Newsgroups: | comp.compilers |
Date: | 6 Oct 1999 09:18:15 -0400 |
Organization: | Compilers Central |
Keywords: | translator |
Hi folks,
I'd appreciate any pointers/references on the subject of generating
human readable source from an AST. I've looked at some of the source
code pretty printers which are floating around but all of them seem
are relatively simple and are based on lexical analysis. I realize
that "human readable" is a subjective term and that for any particular
language people will have preferences regarding indentation, line
splitting etc.
One issue which I've already resolved to my satisfaction is the
removal of superfluous parenthesis in generated expression code. I've
done this by carrying around "the binding context" (for lack of a
better term) during generation. This context is a measure of how
strongly binding the surrounding operator is; only if the current
operator is less binding (i.e. has a lower precedence) are parenthesis
written around the generated code. This scheme also supports handing
binary operator associativity by slightly decreasing the "binding
context" for left or right sub-expressions as appropriate.
Some outstanding issues I'm trying to resolve include:
1) How to split long lines especially for long expressions.
2) Adding extra parenthesis even if they are not strictly
necessary from a grammatical point of view but might
improve the readability.
3) Neatly abstracting "layout preferences" from the AST
walking code.
Any pointers/help would be appreciated.
Cheers,
Dara Gallagher (dara_gallagher@hotmail.com)
Sent via Deja.com http://www.deja.com/
Before you buy.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.