Live data from Hacker News

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

prog21.dadgum.com

21–30 of 173 posts

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

#21

[flagged]

Some of us enjoy intellectual challenges.... The Bornat book looks great. The fact that it is in BCPL is ultra cool.

Liking intellectual challenges on Hacker News is very 2008. It's 2026, the AI will write a compiler in 5 minutes, no headache required.

If you're still playing with Rubik's cubes you're going to get left behind.

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

#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 with the author's point: the "Dragon book"'s ("Compilers: Principles, Techniques, and Tools" by Aho et al.) Chapter 2 is a self-sufficient introduction into compilers from end to end, and it can be read on its own, ignoring the rest of the excellent book.

Another fantastic intro to compiler writing is the short little book "Compilers" by Niklaus Wirth, which explains and contains the surprisingly short source code of a complete compiler (the whole book is highly understandable - pristine clarity, really) and all in (I learned enough from these two sources to write a compiler in high school.)

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

#23
See also, Andy Keep's dissertation [1] and his talk at Clojure/Conj 2013 [2].

I think that the nanopass architecture is especially well suited for compilers implemented by LLMs as they're excellent at performing small and well defined pieces of work. I'd love to see Anthropic try their C compiler experiment again but with a Nanopass framework to build on.

I've recently been looking in to adding Nanopass support to Langkit, which would allow for writing a Nanopass compiler in Ada, Java, Python, or a few other languages [3].

[1]: https://andykeep.com/pubs/dissertation.pdf

[2]: https://www.youtube.com/watch?v=Os7FE3J-U5Q

[3]: https://github.com/AdaCore/langkit/issues/668

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

#25
Maybe I'm missing the point of this article? Writing a simple compiler is not difficult. It's not something for beginners, but towards the end of a serious CS degree program it is absolutely do-able. Parsing, transforming into some lower-level representation, even optimizations - it's all fun really not that difficult. I still have my copy of the "Dragon Book", which is where I originally learned about this stuff.

In fact, inventing new programming languages and writing compilers for them used to be so much of a trend that people created YACC (Yet Another Compiler Compiler) to make it easier.

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

#26

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

Awesome course! finished it while i was doing my final CS year because I had to wait on a bunch of classes (and frankly had no one to talk to before classes). I haven't tried nanopass, but there's other links that work, so I'll give it a go.

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

#29
post #7

I wonder if it makes sense to do the nand2tetris course for an absolute beginner since it too has compiler creation in it.

I highly recommend nand2tetris to everyone. For me, nothing ever explained the whole domain from logic gates and inner workings of a CPU to compilers better than this course.

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

#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 functions (was particularly helpful for whitespace sensitive parsing/line-fold handling), and it removes the tedious lexer/parser split you get with traditional parsing approaches.

Post reply on HN