|Generating Source Code. firstname.lastname@example.org (1999-10-06)|
|Re: Generating Source Code. email@example.com (Rodney M. Bates) (1999-10-11)|
|Re: Generating Source Code. firstname.lastname@example.org (David Chase) (1999-10-11)|
|Re: Generating Source Code. email@example.com (Craig Smith) (1999-10-11)|
|Re: Generating Source Code. firstname.lastname@example.org (Christopher W. Milner) (1999-10-11)|
|Re: Generating Source Code. email@example.com (1999-10-13)|
|Re: Generating Source Code. firstname.lastname@example.org (Scott Stanchfield) (1999-10-13)|
|Re: Generating Source Code. email@example.com (H. Ellenberger) (1999-10-14)|
|Re: Generating Source Code. firstname.lastname@example.org (Vadim Maslov) (1999-10-16)|
|[2 later articles]|
|From:||David Chase <email@example.com>|
|Date:||11 Oct 1999 02:33:42 -0400|
> I'd appreciate any pointers/references on the subject of generating
> human readable source from an AST. ...
I don't know exactly what is published, but this problem was fiddled
with for years at Rice. The original language in question was
Fortran, fed either through a vectorizer, parallelizer, or living in a
"programming environment". We had, at various times, a "pretty
printer", a "Lisp unparser", an "ugly printer" (card image Fortran),
and "incremental pretty printers" (for screen display). These all
worked from ASTs. Work on this continued for years after I left; you
might look for work by Warren (Scott, not Joe) or Baker (Don). I
think Caplinger wrote his dissertation on some aspect of this problem,
but there was years of work that came after that.
> 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.
I was wondering, could some of the dynamic-programming stuff from
Knuth's work apply here? It would seem that there would be penalties
for breaking within a deep nesting, and penalties for badly unbalanced
lines. Thus, you might want to say
x = a + b + c +
d + e + f;
x = a + b + c + d + e +
I also recall that keeping track of comments, and placing them
nicely, is a big problem.
David Chase -- firstname.lastname@example.org
NaturalBridge LLC -- http://www.naturalbridge.com
Return to the
Search the comp.compilers archives again.