Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 864 Bytes

3.md

File metadata and controls

29 lines (19 loc) · 864 Bytes

Part 3: evaluating complex expressions

You have now already made a simple language, able to evaluate nested arithmetic expressions. It is time to add the ability to use controll structures.

For our language, an if statement will suffice. The if takes three arguments. The first one is the predicate p, which is always evaluated. The second or third argument is then evaluated and returned depending on the value of p.

Make it happen!

Go on, you know what to do.

nosetests tests/test_3_evaluating_complex_expressions.py --stop

Play while you work

Remember that the REPL is a great way to play around with your language while you work on it.

./repl
→  (if (> 42 100)
…      'foo
'bar)
bar

What's next?

Go to part 4 where we add environments that'll enable us to work with variables.