Re: Object-oriented compiler construction: ideas?

Greg Morrisett <jgm@CS.Cornell.EDU>
27 Jun 1996 11:42:40 -0400

          From comp.compilers

Related articles
[9 earlier articles]
Re: Object-oriented compiler construction: ideas? kalsow@winternet.com (1996-06-14)
Re: Object-oriented compiler construction: ideas? darius@phidani.be (Darius Blasband) (1996-06-21)
Re: Object-oriented compiler construction: ideas? rwatson@CAM.ORG (Richard Edward Watson) (1996-06-23)
Re: Object-oriented compiler construction: ideas? bronnikov@aol.com (1996-06-24)
Re: Object-oriented compiler construction: ideas? bobduff@world.std.com (1996-06-26)
Re: Object-oriented compiler construction: ideas? leichter@smarts.com (Jerry Leichter) (1996-06-27)
Re: Object-oriented compiler construction: ideas? jgm@CS.Cornell.EDU (Greg Morrisett) (1996-06-27)
Re: Object-oriented compiler construction: ideas? cliffc@ami.sps.mot.com (1996-06-30)
Re: Object-oriented compiler construction: ideas? compres@world.std.com (1996-06-30)
Re: Object-oriented compiler construction: ideas? jdean@cs.washington.edu (1996-06-30)
Dynamic Attribute Grammars (was: Object-oriented compiler construction Martin.Jourdan@inria.fr (1996-07-01)
Re: Object-oriented compiler construction: ideas? solution@gate.net (1996-07-01)
Re: Object-oriented compiler construction: ideas? robison@kai.com (Arch Robison) (1996-07-01)
[2 later articles]
| List of all articles for this month |

From: Greg Morrisett <jgm@CS.Cornell.EDU>
Newsgroups: comp.compilers
Date: 27 Jun 1996 11:42:40 -0400
Organization: Cornell University
References: 96-06-047 96-06-064 96-06-117
Keywords: OOP

Robert A Duff wrote:
> That is, it seems to me that when you choose to use the Visitor pattern,
> you're basically saying that the OOP way is inappropriate in that
> particular case. The OOP way organizes keeps classes together, and
> scatters the operations all over; the "old fashioned" way keeps each
> operation together in one place, as does the Visitor pattern. The "old
> fashioned" way requires that the fields of each node type be visible to
> the operations, or else accessor functions are needed -- just like the
> Visitor pattern.
>
> Which technique is better depends in part on which parts of the system
> are likely to change -- are you going to add new classes, or add new
> operations?


This is a fundamental problem with taking the OO-paradigm too far.
What we need are languages that allow programmers to view the organization
or their programs in different ways in order to support different kinds
of modifications. Ideally, when adding a new kind of primitive to the
AST, the system would present the OO version, so that all I have to
add is one new definition, with appropriate methods. But when I go to
add a new transformation or optimization, I'd rather see the "old-
fashioned" view of my program where I code one big procedure that
switches on the different kinds of AST objects. This way, I don't have
to touch all of the classes to add new methods.


Another problem with the OO-approach is fixing the order of traversal
in the Visitor pattern. In-order? Post-order? Pre-order? Visit
right children first or left children? Depends a lot on the optimization
or transformation you're performing. Perhaps this is the reason why
attribute grammars and other forms of declarative tree/graph-rewriting
seem attractive to compiler writers.


-Greg Morrisett
  jgm@cs.cornell.edu
--


Post a followup to this message

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