Lab 04: Building a Scheme Interpreter in Python: Step 2

CS245: Programming Languages
Bryn Mawr College, Fall 2016
Prof. Blank

In this assignment we will add primitive functions, variables, and user-defined functions to our S-Calc language.

By-line below:

1. Starting from Lab03

Copy and paste your functions from Lab03 here. Only include the functions and definitions that you need.

You may use Doug's solution if you wish.

Check to make sure all of Lab03 still works.

You will want to refer to and add any needed functions.

2. Moving Primitive Functions to an Env

2.1 Move functions from evaluator_apply to top_level_env.

After this step, evaluator_apply should just be:

In [1]:
def evaluator_apply(op, operands):
    return op(operands)

2.2 Change evaluator to have var-exp use lookup

2.3 Add a new parameter to evaluator called env

Make sure you pass evaluator env whenever called (even in Map).

Test these thoroughly here before proceeding.

3. Adding User-Defined Functions

3.1 Add lambda to parser

Parsing a lambda should produce a proc-exp.

3.2 Add proc-exp handling to evaluator

Evaluating a proc-exp should produce a closure-exp.

3.3 Add closure-exp handling to evaluator_apply

You now need to change apply_evaluator again to allow the application of closures.

4. Reflections

As per usual, please reflect deeply on this week's lab. What was challenging, easy, or surprising? Connect the topics onto what you already know.