Generating Source Code.
6 Oct 1999 09:18:15 -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)
[4 later articles]
| List of all articles for this month |

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.
Dara Gallagher (

Sent via
Before you buy.

Post a followup to this message

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