If computer scientists have one universal trait, it must be this visceral urge to create our programming language. Let’s not kid ourselves; we all did it. When I was a young computer science student in college, Jean Méhat made us write a C compiler for a SPARC processor running under Solaris. It taught me syntax, grammar, several tools such as Lex and Yacc and generating assembler code. The result was simple, short, and utterly inefficient. But it was alive, and it was mine. Years earlier, Daniel Guillaume, our algorithm teacher, fond of IBM System/370, taught us that C doesn’t know how to do anything but knows how to have everything done. He was right, and coining out my C toy compiler demonstrated it to me. A few weeks later, Harald Wertz blew my mind away with lambda calculus, and Patrick Greussay used it to bridge us over to LISP. Professor Greussay enlightened us with the code of a LISP interpreter that fitted on a single page. It was short, elegant, and gosh, it made my primitive C compiler look like a pile of mud. Extra teaching: every occasion to learn humility is good. Later, I fell in love with threaded languages, FORTH to name the best, and have created several derivative dialects and their interpreters-compilers.
With the background I shared above, you won’t be surprised to learn that I bought a copy of Crafting Interpreters by Robert Nystrom as soon as I spotted it (published by Genever Benning – ISBN-13: 978-0990582939). Everything I learned creating my languages over the years – and more – is in this 639-page book! If I had this wealth of knowledge and applied techniques in a single source back then, I can’t imagine how far and faster I would have gone in creating my languages. So, do not hesitate; you will learn a lot of techniques and their practical implementation tricks. To be honest, I didn’t pay much attention to the code extracts in the book. Indeed, to me, it is the least important aspect. I am not looking for code to re-use, but more to learn about the author’s views on techniques I already applied in the past. “Hey, he does it the same way I did,” “what, really? But why?” or “Wao, I didn’t think about it this way” are just a few of my exclamations while cherrypicking this book. If you are looking for a pre-canned code, check if the book is for you before buying (~$50). To do so, you can download a sample chapter here. Last but not least, I was delighted by the hand-drawn schemas used all over the book by the author. The approach resonates with my motto: if I can draw it, I can program it!*
During the past few months, I bought many books, and I will present the most remarkable according to me here in the future. But among all of them, Crafting Interpreters is what I must recommend first, and I would repurchase it in a heartbeat.
* I shamelessly adapted it from Predator, the movie, when Duch – Arnold Schwarzenegger – finds the predator’s fluorescent blood and claims, “if it bleeds, I can kill it.”