Skip to content

Latest commit

 

History

History
34 lines (21 loc) · 1.34 KB

2.md

File metadata and controls

34 lines (21 loc) · 1.34 KB

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.py.

Make it happen!

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

nosetests tests/test_2_evaluating_simple_expressions.py --stop

Play while you work

Now that we are beginning to get an interpreter going, we can start testing the results in the read-eval-print-loop (REPL).

Start the REPL from the command line, and try the language as we move along.

./repl

Remember, you'll need to restart the REPL for it to pick up any changes you make to the language.

What's next?

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