Skip to content

Latest commit

 

History

History
22 lines (14 loc) · 993 Bytes

2.md

File metadata and controls

22 lines (14 loc) · 993 Bytes

Part 2: evaluating simple expressions

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.

Make it happen!

The following command runs the tests, stopping at the first one failed. You know the drill.

mvn -Dtest=EvaluatorTest test

What's next?

Head on to part 3 where the expressions we take become slightly more complex.