Writing An Interpreter In Go is a a fun book which covers writing an end to end interpreter in Go. I took a compiler course at my university which required reading the dragon book, but I feel that this book was a great and to-the-point guide in building your own language. While it doesn’t cover the theory, the intent is a straightforward text to introduce you to interpreters/compilers.
You write a lexer, parser, and the evaluating interpreter in Go from scratch without any third party dependencies. It is fast-paced with an encouraging tone which celebrates your accomplishments. The full code is provided, but I found it helpful to write and then play around with the code to fully understand it. I hadn’t written any significant Go programs before so it was helpful in learning the language.
The book guides the reader to implement the
is fairly featured and covers basic expressions, functions, arrays, hashes,
built-ins, closures, and a bit more.
While I haven’t written an end-to-end compiler since college, many of the concepts especially lexing/parsing are useful in a wide range of problems. Knowing how a compiler works is fundamental to advancing programming skills at a certain point. Reading this book has made me appreciate again how important those skills are in a relatively short and practical text.
There is a lost chapter available for free which implements a macro system and a sequel book to implement a bytecode compiler. I intend to read both in the future.