July 12th, 2024

Crafting Interpreters

The book "Crafting Interpreters" by Robert Nystrom is a detailed guide on creating programming languages. It covers parsing, semantics, bytecode, and more. Nystrom provides free online access and additional resources.

Read original articleLink Icon
AppreciationInspirationRecommendations
Crafting Interpreters

The book "Crafting Interpreters" offers a comprehensive guide for individuals interested in creating their own programming language. It covers a wide range of topics including parsing, semantics, bytecode representation, and garbage collection. Readers will build a scripting language from scratch, incorporating features like dynamic typing, lexical scope, first-class functions, and inheritance. The book is available in print and ebook formats, with detailed typography and illustrations. Author Robert Nystrom, a language enthusiast and Google employee, shares his expertise gained from developing hobby languages and working on Dart at Google. Readers can access the book for free online or purchase it through various platforms. Nystrom also offers additional resources like his blog, Twitter account, and mailing list for those interested in further exploration of programming languages.

AI: What people are saying
The comments on the article about "Crafting Interpreters" by Robert Nystrom highlight several key points:
  • Many readers praise the book for its clarity, structure, and the balance between technical implementation and conceptual insights.
  • Several users found the book indispensable for their projects, with some mentioning it inspired them to create their own programming languages or interpreters.
  • There are discussions about the book's approach, with some appreciating the step-by-step guidance and others noting minor frustrations with code examples that don't compile immediately.
  • Readers recommend pairing the book with other resources for a more comprehensive understanding of programming languages and compilers.
  • Some users express a desire for the book to be available in other languages or formats, such as a German hardcopy.
Link Icon 30 comments
By @munificent - 3 months
Author here. Seeing all of the positive comments about my book is really warming my heart. I appreciate everyone and I'm glad so many people have enjoyed the book. I put a ton of time and love into it and it's gratifying to see it had the effect I'd hoped for.
By @liamilan - 3 months
Read Crafting Interpreters when building Crumb (https://github.com/liam-ilan/crumb). It was indispensable, especially the sections on scope and local variables. The balance between technical implementation and conceptual insights is super helpful, especially when trying to go off of the book’s set path.

It’s inspiring to see technical writing done like this. As an aspiring engineer, this sets a really high standard to aim for - excellent resource.

By @sunday_serif - 3 months
My favorite part of this book is that guides you through writing two separate interpreters for the same language.

I think it really allows you to grasp some of the more intricate and nuanced parts about building a programming language.

You can encounter all of the big ideas in the first half of the book and gain enough familiarity with them so that when you revisit them again in the second interpreter, you can actually absorb the interesting parts.

Such a phenomenal book!

By @runevault - 3 months
Since people are talking about other compiler resources, one I have enjoyed so far though I still need to finish it, Immo Landwerth writing a compiler in c# that generates IL and also debug symbols and the like. It is older (about 5 years, so Core but like 3ish timeframe I believe) so doesn't use current c# syntax but shouldn't matter much for most of what you'd be doing other than a lot of warnings about nullability on types.

https://www.youtube.com/playlist?list=PLRAdsfhKI4OWNOSfS7EUu...

By @chris37879 - 3 months
I feel like this is a book most programmers should work through at some point or another. Doing so made me really appreciate just what's going on inside a compiler / language toolkit. It's also one of the most well written technical guides I've ever followed, it really helped me internalize the concepts, and they are useful all over the place, not just in compilers.
By @dgb23 - 3 months
The secondary but perhaps equally important benefit of this book is that it teaches clarity.

The text, code, structure and pacing, everything is clear and to the point.

„Crafting“ is the right word, because the book feels like it’s written by and for craftspeople.

By @fooker - 3 months
This book should be the second or maybe third step of your journey into PL compilers.

The first step is to write an interpreter yourself, for a simple language you create, without knowing anything about interpreters or language design. The second step is to rewrite it, and make less mistakes! :)

If you don't do this, you are never going to appreciate the nuances of this topic. And you are going to skip over concepts that don't seem important.

By @eternityforest - 3 months
Mad respect to those with that kind of dedication, and everyone working to keep all the dev infrastructure going, but I'm super glad my "I want to make a language" phase was just a passing interest!

That's just a crazy amount of work!

By @xigoi - 3 months
Does anyone know of a good resoucce for creating a statically typed language with stuff like parametric polymorphism and basic type inference?
By @britannio - 3 months
I just finished the second half, it's a great book! I recommend doing one or two of the proposed challenges in each chapter to reinforce your understanding of the content.
By @Arisaka1 - 3 months
Curious question from someone new to the programming field who lacks a formal CS background: How are books like this one are meant to be consumed? Do you read it cover to cover as you code along with the author in a way YouTube tutorials work?

The main reason for asking is, I don't know if I'm lacking in natural gifts (really likely) but I can't seem to retain knowledge like that. It feels nice to onboard myself to a language or framework by doing so, but afterwards I will still struggle to connect pieces together.

I'm interested to learn more on how language interpreters work, I just don't know if the format is something that will assist me. I'm trying to compliment and assist my brain with note taking after reading the note taking thread that is currently in the front page, so perhaps that will change.

By @cageface - 3 months
The author is one of the lead developers for Dart, which has evolved over time into a pretty nice language.
By @trenchgun - 3 months
Alright, I will finally read the book. It has been collecting dust in my bookshelf for a while.
By @lifeinthevoid - 3 months
What bothered me a little bit while following the book was that copying the code doesn’t result in compilable code all the time because there is code missing that is only introduced later. I get why the author chose to follow this path, but I’m from the club that every commit should compile and was annoyed a bit by that.
By @dmeijboom - 3 months
Ha, neat! I’m building a dynamic programming language in Rust called atom (https://github.com/dmeijboom/atom). It’s an interpreted language with a bytecode compiler. Will definitely check it out.
By @zengid - 3 months
I cherish this book, its fantastic. I love all of the tidbits about PL history in the margins, and its a great guide through the world of language design.

If you're looking for a follow up, I might have a recommendation. I recently got Essentials Of Compilation by Jeremy G. Siek, and I'm very excited to find some time to read it. There is a version implemented in python and racket (two separate books), so you can pick what you're more comfortable with. (I chose python). Its very elegantly written and after each chapter you end up with a working compiler.

By @packetslave - 3 months
codecrafters (YC S22, http://codecrafters.io) has a new module called "Building Your Own Interpreter" that works its way through this book. It's great because you work in small chunks, each of which has unit tests to tell you if you got, e.g. scanning string literals correct.

Currently free while the module is in beta. I spent today working through all of the lexer exercises in Rust (I'm currently learning it), and had a lot of fun.

By @IAmLiterallyAB - 3 months
Planning to read this soon. Anyone got any other compiler book recommendations? Preferably modern (I've heard the dragon book is out of date)
By @kqr - 3 months
For someone who has sporadically worked through large parts of the dragon book over time (I'm not sure the dragon book is appropriate to consume from cover to cover), and written a couple of tiny interpreters and compilers for fun -- will committing the time for Crafting Interpreters book be revelatory or more of the same? I've long been curious.
By @iainctduncan - 3 months
I love this book, it's an excellent and refreshingly readable complement to more academic texts. I recommend pairing with Friedman's "Essentials of Programming Language". While I also love the Friedman, it's nice to read some PLT without feeling like I got punched in the face sometimes... ;-)
By @endgame - 3 months
Finishing the C interpreter gave me enough confidence to begin my own, from-scratch, interpreter project. Thank you, Bob.
By @nu11ptr - 3 months
How easy is it to follow along and yet build a statically typed language (instead of dynamically typed one as used in the book)?
By @purple-leafy - 3 months
Waiting on the shelf for me once I finish cs50
By @deknos - 3 months
I would wish, there's a german version which i could buy as hardcopy :D
By @alabhyajindal - 3 months
I really wish this book used something other than Java. Nothing against Java - just that I don't know it and don't feel excited about learning it.
By @yodsanklai - 3 months
I know this book has been praised before on HN, but I've been personally a bit disappointed. It's suitable for someone with no very little knowledge on the topic, but it doesn't really cover any advanced topic.
By @brcmthrowaway - 3 months
Is this book still relevant?
By @chasil - 3 months
The lex and yacc utilities are part of POSIX.2; is there any reason not to reach for them first?

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/l...

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/y...

All the POSIX.2 standards for shell utilities can be found here:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/

The original introduction to lex and yacc was in the book by Kernigan and Pike:

https://scis.uohyd.ac.in/~apcs/itw/UNIXProgrammingEnvironmen...