Re: Generating Source Code.

David Chase <>
11 Oct 1999 02:33:42 -0400

          From comp.compilers

Related articles
Generating Source Code. (1999-10-06)
Re: Generating Source Code. (Rodney M. Bates) (1999-10-11)
Re: Generating Source Code. (David Chase) (1999-10-11)
Re: Generating Source Code. (Craig Smith) (1999-10-11)
Re: Generating Source Code. (Christopher W. Milner) (1999-10-11)
Re: Generating Source Code. (1999-10-13)
Re: Generating Source Code. (Scott Stanchfield) (1999-10-13)
Re: Generating Source Code. (H. Ellenberger) (1999-10-14)
Re: Generating Source Code. (Vadim Maslov) (1999-10-16)
[2 later articles]
| List of all articles for this month |

From: David Chase <>
Newsgroups: comp.compilers
Date: 11 Oct 1999 02:33:42 -0400
Organization: None
References: 99-10-036
Keywords: translator, practice wrote:
> 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;

rather than

x = a + b + c + d + e +

I also recall that keeping track of comments, and placing them
nicely, is a big problem.

David Chase --
NaturalBridge LLC --

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.