By the way, for the Python folks with a Pi around, this one is also an interesting read to dive into what it means to write a compiler
"Writing Interpreters and Compilers for the Raspberry Pi Using Python"
https://www.amazon.com/Writing-Interpreters-Compilers-Raspbe...
Writing interpreters and compilers for the raspberry pi using python by Anthony J.Dos Reis
Crafting Interpreters by Nystrom
Game Scripting Mastery (Forgot the author and too lazy to Google)
And there is a C version of "Modern Compiler Implementation" as well.
> If you want to learn how to write interpreters and compilers, and at the same time learn how Python, Python bytecode, assembly language, and dynamic typing work, this is the book for you. The only prerequisites are some experience with any programming language and a computer on which you can install Python 3 (or Python 2 if you prefer). A Raspberry Pi is not required. Included in the software package for the book is an interpreter that allows you to run ARM/Raspberry Pi assembly language programs on your Windows, Linux, or Mac OS X systems.
> If you have not yet learned Python or assembly language, so much the better. You will get the added bonus of learning Python and assembly language while you learn all about interpreters and compilers.
That sounds like a pretty sweet mix of skills to learn all at once, actually!
Let me first say that this is an excellent book and IMO is as good as a Compiler book for laymen as it can be. It is way better than the other books with the same focus IMO (I compared it to two other books: "Game Scripting Mastery" and ""Writing Interpreters and Compilers for the Raspberry Pi using Python"). I really appreciate the efforts the author put into the book. This is one of the few CS books that I actually purchased a physical copy. However, I do have one recommendation:
Express Expr.java in code instead of generating it through a class GenerateAst.
I understand it might be more efficient to write a generator class than writing the whole Expr.java manually. But it is inconvenient for pedagogical reasons.
First, the Expr.java with the Visitor pattern, IMHO, is one of the most important ideas in the book, at least for the frontend. But I find it confusing to read the code through the generating class. Yes I later found out that there is a list of the whole Expr.java as an appendix, but maybe it's a bit easier if it is listed in the chapters.
Second, tabs are expressed as spaces in the code instead of "\t". I don't know about you guys, but I spent a ton of time trying to get the perfect indentation.
Third, everytime we read about new parameters, we have to go back to the Appendix to re-learn Expr.java (Oh this is how the code would look like after adding this new parameter). I think the reason is that the Visitor pattern is not particularly intuitive for me. This could be me stupid but I think it could happen to other laymen as well.
What do you think? Do you agree with me?
Anyone that understands compilers knows one can write language X in X.
In fact, "Writing Interpreters and Compilers for the Raspberry Pi Using Python" does exactly that.
We can nuke CPython and there is plenty of Python code that would still run without problems.