Now that we have the parser up and running, it's time to start working on the evaluator. We'll start with some simple expressions, such as evaluating numbers or booleans, and a few of the most basic special forms in the language.
quote
takes one argument which is returned directly (without being evaluated).atom
also takes a single argument, and returns true or false depending on whether the argument is an atom.eq
returns true if both its arguments are the same atom, and false otherwise.- The arithmetic operators (
+
,-
,*
,/
,mod
and>
) all take two arguments, and do exactly what you would expect.
This time, your work is in the file Evaluator.java
.
The following command runs the tests, stopping at the first one failed. You know the drill.
mvn -Dtest=EvaluatorTest test
Head on to part 3 where the expressions we take become slightly more complex.