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

Does anyone have recommendations for good resources on writing your first compiler?

If you're just getting comfortable with it (as I am) then something a little lighter weight than a course seems like a reasonable approach. Also, for me at least, at this point the distinction between interpreter and compiler isn't as important, and there are some very high quality interpreter resources out there. [0], [1], [2] are easy to get started with and great to work through. At the very least it seems like these should be good preparation for something more rigorous.

As for compiler resources, I've put a respectable dent in [3] and so far I've found it to be pretty accessible.

[0] https://craftinginterpreters.com [1] https://interpreterbook.com [2] http://www.buildyourownlisp.com [3] https://holub.com/compiler/

This paper is a great starting point: http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf

"The compiler we construct accepts a large subset of the Scheme programming language and produces assembly code for the Intel x86 architecture, the dominant architecture of personal computing. The development of the compiler is broken into many small incremental steps. Every step yields a fully working compiler for a progressively expanding subset of Scheme. Every compiler step produces real assembly code that can be assembled then executed directly by the hardware."

"We do not assume that the reader knows anything about assembly language beyond the knowledge of the computer organization, memory, and data structures. The reader is assumed to have very limited or no experience in writing compilers."

> Does anyone have recommendations for good resources on writing your first compiler?

Have a look at the books and compilers at http://t3x.org. For a first glance, I would recommend https://t3x.org/t3x/book.html. If you are only interested in the source code, it is in the public domain and can be downloaded on that page.


I took Alex Aiken's course in my first year when I started to learn writing code, was feasible back then and pretty interesting.

Also curious, what is the modern equivalent of the "Dragon Book"? A lot has changed since the old times, e.g. JIT compilers, and garbage collected VMs and such. Also CPUs have changed a lot, e.g. speculative execution, deep pipelining, large memory cache hierarchies, GPUs, etc. Is there a compiler book that addresses it all?

Modern Compiler in ML/Java. Dragon book is nearly useless and could be useful only for lexer/parser implementation.

Eh. Dragon still has good material on pipelining and local dataflow analysis frameworks. The version two stuff on bdds is the most poorly aged part, IMO.

> Dragon book is nearly useless

Why's that?

Wirth's book on Compiler Construction, in my opinion, is still a paradigm of lucid and concise writing, presenting a whole compiler in 130 pages. First edition was published in Pascal in 1977, the third edition (in Oberon) is available free online:


David Beazley hosts a pretty good compiler class. I wrote my first one there.


Registration is open for Startup School 2019. Classes start July 22nd.

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