________________________________________________________________________________________________________________________________________________________
The Kamin Interpreters in C++
_____________________________________________________________________________________________________________
This paper describes C++ implementations of the interpreters in the book
\Programming Languages: An Interpreter-Based Approach"
by Samuel Kamin (Addison-Wesley, 1989).
Timothy Budd
September 11, 1991
Updated by Henry G. Weller
January 25, 2014
Abstract
This paper describes a series of interpreters for the languages used in the book \Programming Languages: An Interpreter-Based Approach" by Samuel Kamin (Addison-Wesley, 1989). Unlike the interpreters provided by Kamin, which are written in Pascal, these interpreters are written in C++. It is my belief that the use of inheritance in C++ better illustrates the unique features of each of the several languages. In the Pascal versions of the interpreters the di erences between the various interpreters, although small, are scattered throughout the code. In the C++ versions di erences are produced using only the mechanism of subclassing. This means that the vast majority of code remains the same, and di erences can be much more precisely isolated.
The chapters in this report correspond to the chapters in the original text. Where motivational or background material is provided in that source it is generally omitted here. A major exception is in those places (chie y chapters 3, 7 and 8) where I have selected a syntax slightly di erent from that provided by Kamin.
The use of an Object-Oriented language for the interpreters may seem a bit incongruous, since Object-Oriented programming is not discussed until Chapter 7. Nevertheless, I think the bene ts of programming the interpreters in C++ outweighs this problem.
The structure of our basic interpreter1 di ers somewhat from that described by Kamin. Our interpreter is structured around a small main program which manipulates three distinct types of data structures. The main program is shown in Figure 1.1, and will be discussed in more detail in the next section. Each of the three main data structures is represented by a C++ class, such is subclassed in various ways by the di erent interpreters. The three varieties of data structures are the following:
In subsequent sections we will explore in more detail each of these data structures.
Figure 1.1 shows the main program, 2 which de nes the top level control for the interpreters. The same main program is used for each of the interpreters. Indeed, the vast majority of code remains constant throughout the interpreters.