This extended example implements a reader for Scheme lists and an evaluator for the Calculator language, an expression language of numbers and arithmetic call expressions.
This example includes several files. They can be downloaded together as a zip archive.
||A parser for Scheme lists.|
||A tokenizer for Scheme expressions.|
||An evaluator for numbers and arithmetic call expressions.|
||Utility classes for reading multi-line input.|
||Utility functions for CS 61A.|
Syntax. Legal Calculator expressions are either numbers
or well-formed Scheme lists that have an operator symbol as their first
element. The latter are interpretered as call expressions. Legal operator
Evaluation. The evaluation procedure for each operator is described in the lecture notes section about the Scheme-Syntax Calculator.
Read-Eval-Print. When run interactively, the interpreter reads Scheme expressions (without quotation or dotted lists), evaluates them, and prints the results.
> 2 2 > (+ 1 2 (* 3 4)) 15