Writing An Interpreter In Go
Interpreters are cool. I had never written any, but you keep seeing them in many different places: Svelte, Prometheus, build tooling, scripted languages REPL. So it was on my wishlist to somewhen dig deeper.
This book does a great job at that. A kind of tutorial on steroids, with many references to papers, codebases, online articles. Pointers to keep exploring that stuff.
I typed my own version of the interpreter presented in the book. You go through each step: 1. lexer / tokenizing 2. parser 3. evaluator. And at the end, you have an REPL that evaluates a fictious language named Monkey.
The progression is perfect. TDD is put in practice very nicely here. Great iterations that keeps you close to the topic addressed, you keep growing your understanding while you implement each pieces of the puzzle.
There’s a lot about Pratt Parsers online, if you are not interested with an entire book, I guess the chapter Top Down Operator Precedence made available by Douglas Crockford would be an entrypoint to recommend. Together with jslint, the project that made Pratt Parsers cool again.
I’m happy I took the time to go through this book and put the effort in writing my own interpreter. That’s the kind of coding project that interests me and the next step would be logically to move toward compilers. As the author mentions, the border between the two, interpreter and compiler, is blurry. They are conceptually similar.