Skip to main content
  1. Books/
  2. Monkey Interpreter In Zig/
Chapter 5

Where To Go From Here

2 mins
On this page
Table of Contents

You have a working interpreter. It’s small and slow and it’s missing things a real language needs, all of which was on purpose. This chapter is a list of changes to make if you want to keep going. None of this is required reading.


Exercises
#

If you want to expand your knowledge on this book, here are a set of changes you can make to the existing interpreter. Every one of them has a test you can write before you start.

  1. Make let silent in the REPL instead of printing null.
  2. Add <= and >=. Lexer (two-character lookahead, same as ==), precedence table, infix loop, integer infix evaluation.
  3. Add %. Same path as above, and decide what 5 % 0 should do.
  4. Add comments. // to end of line, handled entirely in the lexer’s skipWhitespace.
  5. Add string escapes so "a\nb" contains a newline. Lexer only, but now readString has to allocate.
  6. Add line numbers to tokens and error messages.
  7. Add && and || with short-circuit evaluation. The interesting part is that the right side must not be evaluated if the left side decides the answer, which means these can’t go through evalInfixExpression as written.
  8. Add a while loop. You’ll need to decide whether it’s a statement or an expression, and what it evaluates to.
  9. Add assignment. Then go back to push and ask yourself whether it should still copy.
  10. Fix the string hash key collision by storing the original string in the key and comparing on lookup.
  11. Make puts write to real stdout instead of stderr.
  12. Write a mark-and-sweep garbage collector.

Thanks for reading. If you find bugs or have a better way to explain something, my socials are on the front page. Fail a lot, and learn.