Re: Generating Source Code.

"Scott Stanchfield" <thetick@jguru.com>
13 Oct 1999 01:17:35 -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)
Re: Generating Source Code. chstapfer@bluewin.ch (Christian Stapfer) (1999-10-21)
| List of all articles for this month |

From: "Scott Stanchfield" <thetick@jguru.com>
Newsgroups: comp.compilers
Date: 13 Oct 1999 01:17:35 -0400
Organization: Posted via Supernews, http://www.supernews.com
References: 99-10-036 99-10-042
Keywords: tools

Rodney M. Bates <rod.bates@boeing.com> wrote in message
news:99-10-042@comp.compilers...
> For each syntactic construct, the formatting routine tries to display
> it "horizontally", i.e. all on one line, given a starting position on
> the current line. If it won't fit, then it is displayed "vertically",
> i.e. on multiple lines. Each construct has its own rule for vertical
> formatting. Either way, the nested constructs are formatted in their
> own way.
>
> The kicker is that the starting position has to come from the parent
> construct, and the parent formatting routine doesn't know this yet,
> until it has seen how much space the children constructs will require.


Seems to me that a nice way to deal with nesting would be to use the
LayoutManager approach taken in Java's AWT libraries (a strategy
pattern).


If we were to come up with a "layout manager" for each type of
construct, it could perform layout on its children, asking them for
their "preferred size". The children have layouts as well, which
return preferred size based on _their_ children and so on.


This type of strategy leads to very simple layout manager design
(ain't recusrion grand!) _and_ ease of changing layout strategies. You
can simply plug in different layout strategies for the AST nodes to
change layout behavior for different user styles.


This type of thing has been done in the Swing text framework.


Take a look at the Swing text framework (see
http://www.theswingconnection.com for some details). They use an
Element/View representation to display the data. Elements map nicely to
ASTs (well, they really _are_ an AST of the text's layout). Views are
like layout managers, showing how to display the data on the screen.
There's built-in help for tweaking display (splitting and combining
lines as necessary).


The Swing text framework is rather complex, but designed for just this
type of work to display a document.


You could use this as a model for the pretty printer, or perhaps create
a set of Views that write code to a file.


Hope this spawns some interesting discussion...


--
-- Scott
Scott Stanchfield thetick@jguru.com http://www.jGuru.com/thetick
jGuru Training by MageLang Institute http://www.jGuru.com
VisualAge for Java Tips --> http://www.jGuru.com/thetick/visualage/tips


Post a followup to this message

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