Re: Generating Source Code.

David Chase <chase@world.std.com>
11 Oct 1999 02:33:42 -0400

          From comp.compilers

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)
Re: Generating Source Code. ele@freesurf.ch (H. Ellenberger) (1999-10-14)
Re: Generating Source Code. vadik@siber.com (Vadim Maslov) (1999-10-16)
[2 later articles]
| List of all articles for this month |
From: David Chase <chase@world.std.com>
Newsgroups: comp.compilers
Date: 11 Oct 1999 02:33:42 -0400
Organization: None
References: 99-10-036
Keywords: translator, practice

dara_gallagher@my-deja.com 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 +
        f;


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


--
David Chase -- chase@naturalbridge.com
NaturalBridge LLC -- http://www.naturalbridge.com


Post a followup to this message

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