Hacker News new | past | comments | ask | show | jobs | submit login

Writing an Interpreter in Go / Writing a Compiler in Go, the two part series by Thorsten Ball, was what I really cut my teeth on. It straightforwardly takes you through some parsing, ASTs, a basic tree-walk interpreter, and then in part two refactors the whole thing to compile to bytecode and introduces a virtual machine.

Like other sibling comments mention about Crafting Interpreters, I recommend following the book but implementing in another language you're familiar with. I ran through "Writing an Interpreter" in Go once, but felt like it stuck a lot harder when I went back through and did it again in Swift. Though you're still following code with the hard parts figured out, the simple act of translating the syntax will mean you're looking harder at what's actually happening.

Someone on here a few weeks ago also mentioned chapter 8 of Rob Pike and Brian Kernighan's "the UNIX Programming Environment". I've had an old eBay recovered copy of this book on my shelve for a few years, it's a neat intro to shell as well, but I've been working though chapter 8 this Memorial Day weekend to dip my toes back into the vintage C waters. The book builds up a simple calculator adding variables, builtins, complex control flow, and functions. It starts as a pure yacc parser, and then shifts to a strategy reminiscent of bytecode. This time I'm using a process I'm familiar with (language implementation) to sharpen my C skills.

By doing either of these projects, you also then have a testbed language where you can start developing more advanced concepts. GC, a type system, externalizeable bytecode, linking, the list goes on forever. About four years ago I started working on the Apex language at Salesforce, and the problems encountered in these projects are absolutely still relevant at the scale we're compiling and executing code across our datacenter.

EDIT: I'll also throw in... it gets a lot more fun when the parser's done. If you're finding recursive descent to be a bit of a brain twister, fight through!




Thanks for the thorough reply. I had seen that Crafting Interpreters used Java as the language, glad to hear that implementing in a different language is ideal.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: