Lecture: A Metacircular Scheme Interpreter
- Chapter 3 of the text (scope, binding and environments).
- Chapter 4 (sec. 1-2) of
The scheme interpreter is an implementation of the environment model of
computation discussed. Evaluation
(SICP sec. 4-1) has to parts:
This implemented with two mutually recursive procedures: eval and
apply. The procedure eval processes the expression,
determining its syntax, and dispatches routines to handle the special forms.
If a function application is detected, its subexpressions are evaluated
and apply is called. The procedure apply
creates a new environment by extending the defining environment of the
function to include bindings of the function parameters to the argument
values and calls eval to evaluate the function body in the extended
- To evaluate a combination (a compound expression other than a special
form), evaluate the subexpressions and then apply the value of the
operator subexpression to the values of the operand subexpressions.
- To apply a compound procedure to a set of arguments, evaluate the body
of the procedure in a new environment. To construct this environment,
extend the environment part of the procedure object by a frame in which
the formal parameters of the procedure are bound to the arguments to
which the procedure is applied.
The interpreter is called metacircular, since the interpreter is written
in the language it is interpreting. Note that by using abstraction
the interpreter can easily be modified to incorporate different syntax.
The semantics can be changed by changing the parts of the interpreter (see
the exercises). The use of such an interpreter allows us to study modifications
to the language syntax and semantics.
- Environment model for function evaluation
(SICP sec. 3.2, Louden sec. 13.2)
- procedure definition and application
- lexical scope and local variables
- The core evaluator
(SICP sec. 4.1.1)
- Representing expressions
(SICP sec. 4.1.2)
- Evaluator data structures
(SICP sec. 4.1.3)
- Running the evaluator
(SICP sec. 4.1.4)
Created: Apr. 10, 2007 (revised April 5, 2012) by jjohnson AT cs DOT drexel DOT DOT edu
- Study code for scheme interpreter.
- Show how to transform let special form into a lambda expression.
- Show how to modify the interpreter to use dynamic rather than static
- Show how to modify the interpreter to support streams and test on the
example from streams lecture.
- Study how to modify the interpreter to use normal order rather than
applicative order (see
sec. 4.2.1 of SICP).