Re: Object Oriented Compiler Construction

litsios@iis.ee.ethz.ch (James Litsios)
Wed, 5 Jan 1994 09:54:55 GMT

          From comp.compilers

Related articles
Object Oriented Compiler Construction drh@world.std.com (1994-01-04)
Re: Object Oriented Compiler Construction litsios@iis.ee.ethz.ch (1994-01-05)
Re: Object Oriented Compiler Construction knapp@cs.purdue.edu (1994-01-05)
Re: Object Oriented Compiler Construction chase@Think.COM (1994-01-05)
Re: Object Oriented Compiler Construction preston@dawn.cs.rice.edu (1994-01-06)
Object Oriented Compiler Construction clark@zk3.dec.com (Chris Clark USG) (1994-01-06)
| List of all articles for this month |

Newsgroups: comp.compilers
From: litsios@iis.ee.ethz.ch (James Litsios)
Keywords: OOP, design
Organization: Compilers Central
References: 94-01-010
Date: Wed, 5 Jan 1994 09:54:55 GMT

|> It occurs to me that inheritance should be especially useful in the
|> construction of a parse tree. ...
|> A better way to do this, it seems to me, is to define an abstract class
|> for parse tree nodes, and then subclass specific node types from the
|> abstract base class. I envision member functions like SanityCheck(),
|> Optimize(), and GenerateCode() which take very different (though
|> conceptually identical) actions for each node subclass.


I have a feeling this only works well for simple compilers. On my current
project I am writing a compiler that does so many transformation of the
original parse tree that the idea of storing each different type of node
in a different class (the work is in C++) is simply not practical.
Instead I use the OO properties of C++ to manipulate generic LISP like
data structures with smart pointers to manage the garbage collection. I
can then have pattern matching rules to do the optimization and code
generation. Granted this philosophy might make the compiler slow but this
is acceptable for our purposes.


|> It also seems to me that something other than yacc and lex should be used
|> for the parser. This venerable old tools have served us well, but their
|> design is beginning to show its age. Upgrades like yacc++ and lex++ don't
|> seem to help much since it is the basic design of the tools, not their
|> implementations, which seems to be at fault.


I don't think so, as discussed in the comp.lang.c++ group, yacc can be
used without much problem to directly build C++ parse trees that use smart
pointers or other special features.
--
James Litsios Phone: +41 1/632 60 92
Integrated Systems Laboratory Fax: +41 1/252 09 94
ETH Zurich E-Mail:litsios@iis.ee.ethz.ch
CH-8092 Zurich, Switzerland
--


Post a followup to this message

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