Due by 11:59pm 11/17/2010
In this assignment, you are asked to write a calculator in Scheme syntax that takes an expression of integer constants and outputs the result of the expression. Following is an example (each line is input/out in a shell):
% cat exp_file
(cal '(+ 2 (- 5 4)))
% scheme exp_file
The semantics of arithmetic operations is the same as integer operations in C (so (cal '(/ 5 3)) = 1). Write the calculator in Scheme using car/cdr, cond, and eq?.
<expr> --> left_parenthesis <operator> <expr> <expr> right_parenthesis | num
<operator> --> plus_sign | minus_sign | star_sign | forward_slash
You receive extra credits if you support variable declarations. It is up to you to design the language extension and implement it. An example would be (cal ‘(declare (a 2) (b 5) (c 4) ) (+ a (- b c ))). Try using a higher order function to implement the symbol table.
Turn in your code, test cases, and a report on the design and instructions to run and test your calculator. Submit these files in project_code/func_cal/user_id before 11:59pm Wednesday 11/17/2010.
It may take you longer time to read the assignment than to finish it. But part of the purpose, which we do not grade you on, is for you to compare this calculator with the one you wrote for assignment 3 and think about the implications of language design in terms of the user interface and language implementation. You may suplement/substitute your thinking with those of Richard Gabriel's in Worse Is Better, in particular, Section 2.1 in his original 1991 article.