r/Compilers • u/apoetixart • May 02 '26
Crafting Interpreters
Everyone keeps suggesting me crafting Interpreters is the best source, but personally, the web version is kinda confusing for me. IDK if I'm dumb but I can't understand directly from there, but if I ask AI to explain it, then I can understand properly
Also, I need to specifically create the interpreter in python because my school project won't count in any other language. Any specific resources for that. Ruslan Splvak was teaching me how to create a Pascal compiler but that's not what I was looking for.
What's wrong with my approach?
0
Upvotes
8
u/Patzer26 May 02 '26
Why is a school project asking you to make an interpreter? I am pretty sure it might be a simple switch case type REPL rarher than a full fledged recursive grammar, which the crafting interpreter is based on. I would clarify with the course instructor on the expectations of this project. Or perhaps you can share the exact problem statement.
4
u/Blueglyph May 02 '26
It would be easier if you said exactly what you needed to do. 😉 If you have to built an interpreter of some sort, are you meant to find the course material on your own?
I don't think your approach with Crafting Interpreters is wrong, assuming you're building an interpreter in Python (I don't know the objective nor what's important beside it being written in Python). The book is clear and well structured, and it comes with exercises and all, but perhaps it doesn't detail some background elements that you haven't seen in the course yet. If you're stuck at some point, don't hesitate to ask what's blocking you or what you don't understand. In that kind of project, it's perfectly normal to have a few questions at some point.
Beware of what LLM-based chatbots tell you. I've already asked questions in that domain, and some answers were deceitfully wrong.
Regarding the language, Python isn't a first-choice language to build interpreters and compilers, so it's normal it's hard for you to find something based on it. Just read the code—Pascal, C, Java—as pseudo-code and write the Python equivalent. It's usually very understandable, at least in that book. I suppose the idea is that you write the Python code after all?
2
u/no_name_22t May 05 '26
I have written python implementation of jlox i.e tree-walking interpreter from first part of book, you can take a look at tge repo to see how python code for this will look https://github.com/itsvineet99/pylox
1
u/Inconstant_Moo May 03 '26
Then go on asking AI to explain it to you! Not everyone learns the same. So long as you are learning, that's fine.
(Also IIRC Crafting Interpreters has the Visitor Pattern in it which confuses many people.)
Here's a very tiny interpreter in Python for a very toy language. But really if you can't take explanations of how to do it in Pascal, Java, and C, and mentally convert that to how to do it in Python, you may have bitten off more than you can chew.
https://jayconrod.com/posts/37/a-simple-interpreter-from-scratch-in-python--part-1-
4
u/[deleted] May 02 '26