|Generating Source Code. email@example.com (1999-10-06)|
|Re: Generating Source Code. firstname.lastname@example.org (Rodney M. Bates) (1999-10-11)|
|Re: Generating Source Code. email@example.com (David Chase) (1999-10-11)|
|Re: Generating Source Code. firstname.lastname@example.org (Craig Smith) (1999-10-11)|
|Re: Generating Source Code. email@example.com (Christopher W. Milner) (1999-10-11)|
|Re: Generating Source Code. firstname.lastname@example.org (1999-10-13)|
|Re: Generating Source Code. email@example.com (Scott Stanchfield) (1999-10-13)|
|[4 later articles]|
|Date:||6 Oct 1999 09:18:15 -0400|
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
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
Any pointers/help would be appreciated.
Dara Gallagher (firstname.lastname@example.org)
Sent via Deja.com http://www.deja.com/
Before you buy.
Return to the
Search the comp.compilers archives again.