Ask HN: Writing an Interpreter in Go or Crafting Interpreters?
I'm thinking of learning about compilers and am pleased to find that there seems to be at least two very accessible choices, "Writing An Interpreter In Go" and Crafting Interpreters. Curious if folks here have experience with either and could provide recommendations?
https://interpreterbook.com/ https://craftinginterpreters.com/
Read both if you like.
I read and liked them both, but my heart belongs to Bob's writing, especially the C implementation in Crafting Interpreters and how he explains things.
Crafting Interpreters is the right at the top of my list of favorite programming books…and I’ve been reading them since the late 70’s. Amazingly clear and well-designed.
May I get the list of your favorite programming books?
I went over "Writing an Interpreter in Go" and "Writing a Compiler in Go" but instead of doing it in Go, I did it in C. In hindsight it was a very good decision, because it forced me to write the code myself, instead of mindlessly copying it. After finishing the books I've spent some time extending the compiler I've written and I've published it on github (https://github.com/kgabis/ape). I've read Bob Nystrom's previous book, so I'm sure Crafting Interpreters is great as well, but I really recommend Writing an Interpreter/Compiler in Go.
I recommend skimming over the first few chapters of crafting interpreters, the main value there is the recursive descent algorithm and abstract syntax trees, the rest is implementation. I've been developing my own language [1] and that's how I got started
The ideas in crafting interpreters are not language specific, the examples are in java, but I used C++ for instance. Im sure you could transfer the same ideas to Go. Then again I've never read the go book you are referring to
[1] https://youtu.be/azR1mUfFjHI?si=PsP-7o-w1yIN4xyq
If you go with Crafting Interpreters, there is a coding challenge on CodeCrafters that follows the book: https://app.codecrafters.io/courses/interpreter/overview
It is free (for now) and it helps me focused.
Crafting Interpreters has been sitting on my shelf for two or so years. I would love to read the book but the use of Java shelved it. I don’t have the time to understand the concepts from the book while simultaneously learning Java.
Bob uses basic programming constructs. If you know any language you can follow the book.
Yes, but half the code in the book is implemented in Java.
You can use Python or anything else you like to implement your code. The Java code he writes is simple, imperative code. But the OOP stuff might get in the way. If you've got programming experience, it isn't hard to read it and write your own in your preferred language.
Or you can simply jump to the second part in C. I don't think it's mandatory to read the first part for the second one. Plus the second part is more interesting as it implements a VM.
I'm doing Crafting Interpreters... in Go! The book uses Java, but I prefer Go so I just went with it. It was an interesting exercise to "translate" the understanding of the implementation shown in the book (which relies heavily in OOP) to something more idiomatic in Go.
There's also an excellent tutorial from LLVM, it got me started, I got some ideas and didn't want to be too influenced by "the right way", so I stopped somewhere mid tokenizer.. But I have a turing complete, interpreted language as of now, that I'm having a lot of fun thinking about.
https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/index...
The kaleidoscope tutorial is a good tour of LLVM capabiltiies, but I don't think I would consider it an alternative to either of these books.
I've read Writing an Interpreter in Go and Writing a Compiler in Go. Crafting Interpreters is on my bookshelf and on the list to get through Soon™. The latter books by Thorsten Ball are an incredibly approachable introduction to the topic. It's how I initially learned Go and it reinforced what I learned back in my undergrad on how parsers and compilers work.
I love writing parsers and get far too few opportunities to flex that muscle. I wish I had read Crafting Interpreters for this question, as well, but by all accounts it's an incredible tome, as well. Read them all and see what different information you pick up from them!
I only read Crafting Interpreters and I can recommend this one. It's also free as a website so you can evaluate it before making a purchase. I did think it is interesting enough to go straight to make the purchase.
I really enjoy Crafting Interpreters, but I’ve revisited it a couple times and haven’t yet made it through half the book. It’s very well written and there’s a lot of material to chew on. That said, Writing an Interpreter in Go, is short, sweet, and the Pratt Parser implementation and explanation are great! I haven’t cracked open his compiler book yet, but the interpreter book was a breeze.
Yeah I agree lox has a bit of too many features. I didn't complete the interpreter part and now I'm diving into the VM part. I'm not particularly interested in the more advanced stuffs. I won't get a compiler job anyway.
I started them but dropped them and went straight for:
- Engineering a Compiler
- Programming Language Pragmatics
- Crafting a Compiler
Quite doable, particularly if you focus on one and supplement with the other two.
Why drop them? If you have time for 3 books, you can probably find time for 5. Writing an Interpreter in Go and Crafting Interpreters are both great, and much more fun than these.
Both are great!