Live data from Hacker News

Want to write a compiler? Just read these two papers (2008)

prog21.dadgum.com

41–50 of 173 posts

Re: Want to write a compiler? Just read these two papers (2008)

#42

It's been about 4 years since I took a compilers course (from OMSCS, graduate program) and still shutter ... it was, hands down, the most difficult (yet rewarding) classes I've taken.

What did you find more painful about compilers than other forms of programming?

I think there is a million ways to make a compilers course.

The course I did was organized perfectly with big parts of compiler boiler plate already written, and I only had to implement parser/lexer rules and the translation of language structures into assembly instructions. Also it was a compiler for a language designed just for this course with the intention of it being specifically easy to write a compiler for it and not programming.

Without this I can imagine it being a painful experience

Re: Want to write a compiler? Just read these two papers (2008)

#44

Nowadays I’ve heard recommended Crafting Interpreters. ( https://craftinginterpreters.com ) The Nanopass paper link doesn’t work.

Compilers are broad enough that when someone recommends a "compiler book", it's rarely exactly the slice you wanted.

So this made me do a runnable cheat sheet for Crafting Interpreters. I keep parsing demonstrative, and the AST is a little more Lisp-y than the book's.

Disclaimer: it's meant to convey the essence of what you'll learn, it is NOT by any means a replacement for the book. I'd also describe the book as more of an experience (including some things Nystrom clearly enjoyed, like the visitor pattern) than a compilers manual. If anyone's interested, I can do a separate visitor-pattern cheat sheet too, also in Python.

I turned it into a 'public-facing artifact' from private scripts with an AI agent.

[0] https://ouatu.ro/blog/crafting-interpreters-cheat-sheet/

Re: Want to write a compiler? Just read these two papers (2008)

#47

I've been having a look at the Crenshaw series, and it seems pretty good, but one thing that kinda annoys me is the baked-in line wrapping. Is there a way to unwrap the text so its not all in a small area on the left of my screen?

https://xmonader.github.io/letsbuildacompiler-pretty/

Re: Want to write a compiler? Just read these two papers (2008)

#48
post #22

*Donald Knute -> Donald Ervin Knuth is the author of the book "The Art of Computer Programming" (in progress for a couple of decades, currently volume 4c is being written). It is quite advanced, and it will likely not cover compilers anymore (Addison-Wesley had commissioned a compiler book from Knuth when he was a doctoral candidate, now he is retired and has stated his goal for the series has changed). I disagree wi…

There is still hope for a compiler book. From Knuth's website:

> And after Volumes 1--5 are done, God willing, I plan to publish Volume 6 (the theory of context-free languages) and Volume 7 (Compiler techniques), but only if the things I want to say about those topics are still relevant and still haven't been said.

https://www-cs-faculty.stanford.edu/~knuth/taocp.html

Re: Want to write a compiler? Just read these two papers (2008)

#49
post #30

Been working on a toy compiler for fun recently. I have ignored all the stuff about parsing theory, parser generators, custom DSL's, formal grammers etc. and instead have just been using the wonderful Megaparsec parser combinator library. I can easily follow the parsing logic, it's unambiguous (only one successful parse is possible, even if it might not be what you intended), it's easy to compose and re-use parser fu…

I'll push back and say that the lexer/parser split is well worth it.

And the best thing about the parser combinator approach is that each is just a kind of parser, something like

  type Lexer = ParsecT e ByteString m [Token]

  type Parser = ParsecT e [Token] Expr
All the usual helper functions like many or sepBy work equally well in the lexing and parsing phases.

It really beats getting to the parentheses-interacting-with-ordering-of-division-operations stage and still having to think "have I already trimmed off the whitespace here or not?"

Re: Want to write a compiler? Just read these two papers (2008)

#50
post #47

I've been having a look at the Crenshaw series, and it seems pretty good, but one thing that kinda annoys me is the baked-in line wrapping. Is there a way to unwrap the text so its not all in a small area on the left of my screen?

https://xmonader.github.io/letsbuildacompiler-pretty/

Perfect!
Post reply on HN