Prog Blog for January 19th, 2026
Today and Saturday I spent a few hours each morning working on the next few chapters of Crafting Interpreters, "Representing Code" and "Parsing Expressions".
The most difficult part I'm having with this is trying to translate the interpreter code from Java to Python at the same time I'm translating the Lox language to the Taylor language. Luckily, a lot of the conceptual stuff about compiler design is still familiar from college and a brief period in around 2020 where I attempted creating Taylor with TCL code.
One thing I'm realizing is that I still have a lot of practice with Python type hints and using the ABC module for abstact base classes. I learned Python before these were added, so by default I don't use typing and always just used "raise NotImplementedError" to simulate an abstract base class. Once I get things up and running, I'll go back and add these to the code as a learning experience. Right now I have to stick with tried-and-true to get finished.
A nice learning experience from this is learning the Visitor Pattern, which I wasn't familiar with. At first I had a hard time understanding it. The author starts a metaphor with pastries but doesn't finish it. However, shortly after, we built a small example and that made it more understandable. Another reason I had a hard time understanding it is because in Python it seems less necessary, especially if you're utilizing the dynamic typing and multiple inheritance (like mixins).
Overall, I think a lot of the content in the book is overkill for as simple of a language as Taylor, but I'm learning a lot of interesting things and it is a fun project to work on. My hope is that I'll get to work through the book, learn a bunch of new stuff, and then go back and optimize the interpreter into the smallest, fastest, most "purpose built" version of itself. The book ends with a virtual machine written in C, so maybe for the final iteration, I can do a full compiler.
Here's an example of where we're at, it shows entering an expression, building an abstract syntax tree, and printing it out:
taylor-lang> python3 taylor.py
> 3 * 6 + (-2 / 18)
( + ( * 3.0 6.0) ( group ( / ( - 2.0) 18.0)))
>
Next up is the chapter "Evaluating Expressions."