Live data from Hacker News

Crafting Interpreters

craftinginterpreters.com

11–20 of 193 posts

Re: Crafting Interpreters

#11
post #10

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…

As the author of a POSIX standard utility, I would advise you to only reach for such utilities when portability is the most important thing.

POSIX utilities are not great. Lex and Yacc included.

Re: Crafting Interpreters

#12
post #7

Is this book still relevant?

Yes, very much so. Why wouldn't it be? Can you recommend a better resource for learning how to create a programming language from first principles? I just started it today, which I why I felt the inclination to create this post.

It’s an incredible book. Munificent did an amazing job.

Re: Crafting Interpreters

#13
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.

Re: Crafting Interpreters

#14
post #10

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…

As the author of a POSIX standard utility, I would advise you to only reach for such utilities when portability is the most important thing. POSIX utilities are not great. Lex and Yacc included.

Is your criticism of the relationship of the lexer and the parser, or something more fundamental? Is an LR parser expressed in BNF notation unsatisfactory?

I say this only as it has been many years since I have written one, but I thought this OCaml presentation on a POSIX shell held the structure in high regard.

https://archive.fosdem.org/2018/schedule/event/code_parsing_...

Re: Crafting Interpreters

#15
post #14

Earlier quoted context omitted.

As the author of a POSIX standard utility, I would advise you to only reach for such utilities when portability is the most important thing. POSIX utilities are not great. Lex and Yacc included.

Is your criticism of the relationship of the lexer and the parser, or something more fundamental? Is an LR parser expressed in BNF notation unsatisfactory? I say this only as it has been many years since I have written one, but I thought this OCaml presentation on a POSIX shell held the structure in high regard. https://archive.fosdem.org/2018/schedule/event/code_parsing_...

The UX of the BNF notation.

I am partial to hand-coded recursive descent purely because I struggled with Lex and Yacc too much when I tried.

Re: Crafting Interpreters

#16
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!

Re: Crafting Interpreters

#17
post #14

Earlier quoted context omitted.

Is your criticism of the relationship of the lexer and the parser, or something more fundamental? Is an LR parser expressed in BNF notation unsatisfactory? I say this only as it has been many years since I have written one, but I thought this OCaml presentation on a POSIX shell held the structure in high regard. https://archive.fosdem.org/2018/schedule/event/code_parsing_...

The UX of the BNF notation. I am partial to hand-coded recursive descent purely because I struggled with Lex and Yacc too much when I tried.

I commiserate, it can be unforgiving, and the use of C is admittedly out of vogue.

Re: Crafting Interpreters

#18
post #17

Earlier quoted context omitted.

The UX of the BNF notation. I am partial to hand-coded recursive descent purely because I struggled with Lex and Yacc too much when I tried.

I commiserate, it can be unforgiving, and the use of C is admittedly out of vogue.

Oh, I love C. [1] But yes, unforgiving.

And a lot of magic, with special variables, macros, and functions that you must know. And unclear scoping.

[1]: https://gavinhoward.com/2023/02/why-i-use-c-when-i-believe-i...

Re: Crafting Interpreters

#19

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.

I trust that you're correct, but I'm glad that this is the case. There are books designed to be introductory, and there are books that serve as reference for advanced topics and state-of-the-art techniques. The first type can often serve as an enabler for the second type.

Re: Crafting Interpreters

#20
post #10

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…

For a few reasons.

One, because actually building the lexer and parser from scratch is a useful exercise in a learning context, which is what this is.

Two, because the book wants to teach Pratt parsers, rather than LALR parsers. There’s a lot of literature out there on LALR parsers and generated parsers in general, but precious little on handrolled parsers. Covering material that hasn’t been covered to hell and back is a Good Thing.

Three, because lex and yacc generate C, and the book has two implementations of the interpreter, in C and Java. You could’ve used ANTLR to generate both parsers, but lex/yacc would only cater to the C version

And finally, because not everybody is on a POSIX system. Before WSL, using anything Unix-y on Windows was miserable. These days it’s mostly fine, but using WSL means you’re not actually building windows-native stuff anymore.

Post reply on HN