Hacker News Viewer

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

by downbad_ on 4/15/2026, 9:41:19 AM

https://prog21.dadgum.com/30.html

Comments

by: jll29

*Donald Knute -&gt; Donald Ervin Knuth is the author of the book &quot;The Art of Computer Programming&quot; (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).<p>I disagree with the author&#x27;s point: the &quot;Dragon book&quot;&#x27;s (&quot;Compilers: Principles, Techniques, and Tools&quot; 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.<p>Another fantastic intro to compiler writing is the short little book &quot;Compilers&quot; 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 &lt;100 pages total (99).<p>(I learned enough from these two sources to write a compiler in high school.)

4/15/2026, 10:49:12 AM


by: soegaard

An Incremental Approach to Compiler Construction<p>Abdulaziz Ghuloum<p><a href="http:&#x2F;&#x2F;scheme2006.cs.uchicago.edu&#x2F;11-ghuloum.pdf" rel="nofollow">http:&#x2F;&#x2F;scheme2006.cs.uchicago.edu&#x2F;11-ghuloum.pdf</a><p>Abstract<p>Compilers are perceived to be magical artifacts, carefully crafted by the wizards, and unfathomable by the mere mortals. Books on compilers are better described as wizard-talk: written by and for a clique of all-knowing practitioners. Real-life compilers are too complex to serve as an educational tool. And the gap between real-life compilers and the educational toy compilers is too wide. The novice compiler writer stands puzzled facing an impenetrable barrier, “better write an interpreter instead.”<p>The goal of this paper is to break that barrier. We show that building a compiler can be as easy as building an interpreter. 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 assume that the reader is familiar with the basic computer architecture: its components and execution model. Detailed knowledge of the Intel-x86 architecture is not required.<p>The development of the compiler is described in detail in an extended tutorial. Supporting material for the tutorial such as an automated testing facility coupled with a comprehensive test suite are provided with the tutorial. It is our hope that current and future implementors of Scheme find in this paper the motivation for developing high-performance compilers and the means for achieving that goal.

4/15/2026, 11:07:44 AM


by: morphle

Compiler writing has progressed a lot. Notably in meta compilers [1] written in a few hundred lines of code and adaptive compilation [3] and just in time compilers. Alan Kay&#x27;s research group VPRi tackled the problems of complexity (in writing compilers) [4].<p>[1] Ometa <a href="https:&#x2F;&#x2F;tinlizzie.org&#x2F;VPRIPapers&#x2F;tr2007003_ometa.pdf" rel="nofollow">https:&#x2F;&#x2F;tinlizzie.org&#x2F;VPRIPapers&#x2F;tr2007003_ometa.pdf</a><p>[2] Other ometa papers <a href="https:&#x2F;&#x2F;tinlizzie.org&#x2F;IA&#x2F;index.php&#x2F;Papers_from_Viewpoints_Research_Institute" rel="nofollow">https:&#x2F;&#x2F;tinlizzie.org&#x2F;IA&#x2F;index.php&#x2F;Papers_from_Viewpoints_Re...</a><p>[3] Adaptive compilation <a href="https:&#x2F;&#x2F;youtu.be&#x2F;CfYnzVxdwZE?t=4575" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;CfYnzVxdwZE?t=4575</a><p>the PhD thesis <a href="https:&#x2F;&#x2F;www.researchgate.net&#x2F;publication&#x2F;309254446_Adaptive_compilation_for_an_object-oriented_and_reconfigurable_architecture" rel="nofollow">https:&#x2F;&#x2F;www.researchgate.net&#x2F;publication&#x2F;309254446_Adaptive_...</a><p>[4] Is it really &quot;Complex&quot;? Or did we just make it &quot;Complicated&quot;? Alan Kay <a href="https:&#x2F;&#x2F;youtu.be&#x2F;ubaX1Smg6pY?t=3605" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;ubaX1Smg6pY?t=3605</a>

4/15/2026, 11:07:44 AM


by: teleforce

The latest edition (3rd Edition) of Introduction to Compiler Design by Mogensen has new topics on SSA form, garbage collection, polymorphism and translation of pattern matching [1].<p>[1] Introduction to Compiler Design:<p><a href="https:&#x2F;&#x2F;link.springer.com&#x2F;book&#x2F;10.1007&#x2F;978-3-031-46460-7" rel="nofollow">https:&#x2F;&#x2F;link.springer.com&#x2F;book&#x2F;10.1007&#x2F;978-3-031-46460-7</a>

4/17/2026, 7:57:34 AM


by: armchairhacker

Nowadays I’ve heard recommended Crafting Interpreters. (<a href="https:&#x2F;&#x2F;craftinginterpreters.com" rel="nofollow">https:&#x2F;&#x2F;craftinginterpreters.com</a>)<p>The Nanopass paper link doesn’t work.

4/15/2026, 10:20:18 AM


by: stupefy

One nice piece of advice that I received is that books are like RAMs, you do not have to go through them sequentially, but can do random access to the parts of it you need. With this in mind I find it doable to get one the thick books and only read the part that I need for my task.<p>But, to also be fair, the above random access method does not work when you don&#x27;t know what you don&#x27;t know. So I understand why having a light, but good introduction to the topic is important, and I believe that&#x27;s what the author is pointing out.

4/15/2026, 12:23:29 PM


by: omcnoe

Been working on a toy compiler for fun recently.<p>I have ignored all the stuff about parsing theory, parser generators, custom DSL&#x27;s, formal grammers etc. and instead have just been using the wonderful Megaparsec parser combinator library. I can easily follow the parsing logic, it&#x27;s unambiguous (only one successful parse is possible, even if it might not be what you intended), it&#x27;s easy to compose and re-use parser functions (was particularly helpful for whitespace sensitive parsing&#x2F;line-fold handling), and it removes the tedious lexer&#x2F;parser split you get with traditional parsing approaches.

4/15/2026, 11:05:37 AM


by: GCUMstlyHarmls

Nanopass paper seems to be dead but can be found here at least <a href="https:&#x2F;&#x2F;stanleymiracle.github.io&#x2F;blogs&#x2F;compiler&#x2F;docs&#x2F;extra&#x2F;nanopass-framework.pdf" rel="nofollow">https:&#x2F;&#x2F;stanleymiracle.github.io&#x2F;blogs&#x2F;compiler&#x2F;docs&#x2F;extra&#x2F;n...</a>

4/15/2026, 10:21:02 AM


by: WalterBright

What taught me how to write a compiler was the BYTE magazine 1978-08 .. 09 issues which had a listing for a Tiny Pascal compiler. Reading the listing was magical.<p>What taught me how to write an optimizer was a Stanford summer course taught by Ullman and Hennessy.<p>The code generator was my own concoction, and is apparently quite unlike any other one out there!<p>I have the Dragon Book, but have never actually read it. So sue me.

4/15/2026, 4:02:13 PM


by: blueybingo

the article&#x27;s framing around nanopass is undersold: the real insight isn&#x27;t the number of passes but that each pass has an explicit input and output language, which forces you to think about what invariants hold at each stage. that discipline alone catches a suprising number of bugs before you even run the compiler. crenshaw is fantastic but this structural thinking is what separates toy compilers from ones you can actaully extend later.

4/15/2026, 1:06:17 PM


by: itsmemattchung

It&#x27;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&#x27;ve taken.

4/15/2026, 9:51:44 AM


by: georgehm

I have fond memories of implementing an optimizing compiler for the CS241 compiler course offered back then by Prof Michael Franz who was a student of Niklaus Wirth, probably the most exhilarating course during my time at UC Irvine. This was in 2009 so my memory is vague but I recall he provided a virtual machine for a simple architecture called DLX and the compiler was to generate byte code for it.<p>Google search points me to <a href="https:&#x2F;&#x2F;github.com&#x2F;cesarghali&#x2F;PL241-Compiler&#x2F;blob&#x2F;master&#x2F;DLX.pdf" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cesarghali&#x2F;PL241-Compiler&#x2F;blob&#x2F;master&#x2F;DLX...</a> for a description of the architecture and possibly <a href="https:&#x2F;&#x2F;bernsteinbear.com&#x2F;assets&#x2F;img&#x2F;linear-scan-ra-context-ssa.pdf" rel="nofollow">https:&#x2F;&#x2F;bernsteinbear.com&#x2F;assets&#x2F;img&#x2F;linear-scan-ra-context-...</a> for the register allocation algorithm

4/15/2026, 4:28:52 PM


by: khat

The biggest issue with technical books is they spend the first 1-2 chapters vaguely describing some area and then follow up with but that&#x27;s for a later more advanced discussion or we&#x27;ll cover that in that last 1-2 chapters. Don&#x27;t vaguely tell me about something you&#x27;re not gonna go into detail about, because now all I&#x27;m thinking about reading the subsequent chapters is all the questions I have about that topic.

4/15/2026, 5:52:05 PM


by: LiamPowell

See also, Andy Keep&#x27;s dissertation [1] and his talk at Clojure&#x2F;Conj 2013 [2].<p>I think that the nanopass architecture is especially well suited for compilers implemented by LLMs as they&#x27;re excellent at performing small and well defined pieces of work. I&#x27;d love to see Anthropic try their C compiler experiment again but with a Nanopass framework to build on.<p>I&#x27;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].<p>[1]: <a href="https:&#x2F;&#x2F;andykeep.com&#x2F;pubs&#x2F;dissertation.pdf" rel="nofollow">https:&#x2F;&#x2F;andykeep.com&#x2F;pubs&#x2F;dissertation.pdf</a><p>[2]: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=Os7FE3J-U5Q" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=Os7FE3J-U5Q</a><p>[3]: <a href="https:&#x2F;&#x2F;github.com&#x2F;AdaCore&#x2F;langkit&#x2F;issues&#x2F;668" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;AdaCore&#x2F;langkit&#x2F;issues&#x2F;668</a>

4/15/2026, 10:50:49 AM


by: kuharich

Past comments: <a href="http:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=2927784">http:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=2927784</a>, <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10786842">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10786842</a>

4/15/2026, 3:43:35 PM


by: aldousd666

I learned from the Dragon Book, decades ago. I already knew a lot of programming at that point, but I think most people writing compilers do. I&#x27;m curious if there really is an audience of people whose first introduction to programming is writing a compiler... I would think not, actually.

4/15/2026, 2:06:21 PM


by: krtkush

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

4/15/2026, 10:01:09 AM


by: petcat

And Nystrom&#x27;s book

4/15/2026, 10:14:59 AM


by: bradley13

Maybe I&#x27;m missing the point of this article? Writing a simple compiler is not difficult. It&#x27;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&#x27;s all fun really not that difficult. I still have my copy of the &quot;Dragon Book&quot;, which is where I originally learned about this stuff.<p>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.

4/15/2026, 10:53:24 AM


by: ahaferburg

I liked this series of lectures on Youtube.<p>Compilers - Alex Aiken | Stanford<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLEAYkSg4uSQ3yc_zf_f1GOxl5CZo0LVBb" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLEAYkSg4uSQ3yc_zf_f1G...</a><p>Mentioned in another comment, but with a different link.

4/16/2026, 8:25:57 AM


by: fzeindl

A similarly scoped book series is „AI game programming wisdom“, which contains a multitude of chapters that focus on diverse, individual algorithms that can be practically used in games for a variety of usecases.

4/15/2026, 10:40:18 AM


by: rahen

I&#x27;m also writing a compiler and CS6120 from Cornell has helped me a lot: <a href="https:&#x2F;&#x2F;www.cs.cornell.edu&#x2F;courses&#x2F;cs6120&#x2F;2025fa&#x2F;self-guided&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.cs.cornell.edu&#x2F;courses&#x2F;cs6120&#x2F;2025fa&#x2F;self-guided...</a>

4/15/2026, 6:32:36 PM


by: mzs

archive of forth translation of Crenshaw’s howto<p><a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20190712115536&#x2F;http:&#x2F;&#x2F;home.iae.nl&#x2F;users&#x2F;mhx&#x2F;crenshaw&#x2F;tiny.html" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20190712115536&#x2F;http:&#x2F;&#x2F;home.iae.n...</a>

4/15/2026, 2:27:34 PM


by: notnullorvoid

I might be in the minority, but I think the best way to learn how to write a compiler is to try writing one without books or tutorials. Keep it very small in scope at first, small enough that you can scrap the entire implementation and rewrite in an afternoon or less.

4/15/2026, 2:33:42 PM


by: dgan

If i had a euro for every time I started writing a compiler, and got lost in the parser weeds, i d have ... At least couple of euros

4/15/2026, 10:50:52 PM


by: cdcarter

All you really need is a copy of &quot;The Unix Programming Environment&quot;, where you can implement `hoc` in a couple hours.

4/15/2026, 4:17:34 PM


by: downbad_

<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10786842">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=10786842</a>

4/15/2026, 9:41:36 AM


by: ape4

Would a practical approach be parsing the source into clang&#x27;s AST format. Then let it make the actual executable.

4/15/2026, 11:45:35 AM


by: aurohacker

Any tips on reading material for code generation and scheduling for parallel engines?

4/15/2026, 4:11:48 PM


by: msla

fanf2 on Dec 25, 2015 [dead] | parent | prev | next [–]<p>I quite like &quot;understanding and writing compilers&quot; by Richard Bornat - written in the 1970s using BCPL as the implementation language, so rather old-fashioned, but it gives a friendly gentle overview of how to do it, without excessive quantities of parsing theory.

4/15/2026, 9:48:14 AM


by: deterministic

Whatever you do don&#x27;t waste your time on the &quot;Dragon&quot; book.<p>Google &quot;recursive descent parsing&quot; and it will tell you everything you need to know about the front-end of a compiler.<p>Google &quot;My First Language Frontend with LLVM&quot; and it will teach you the other half.

4/16/2026, 5:41:44 AM


by: zahlman

&gt; The best source for breaking this myth is Jack Crenshaw&#x27;s series, Let&#x27;s Build a Compiler!<p>Right, I&#x27;ve heard of that...<p>&gt; , which started in 1988.<p>... Oh. Huh.<p>(Staring at the red dragon book on my bookshelf, which was my course textbook in the early 00s.)

4/15/2026, 7:04:45 PM


by: voidUpdate

I&#x27;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?

4/15/2026, 11:42:02 AM


by: anthk

<a href="https:&#x2F;&#x2F;t3x.org" rel="nofollow">https:&#x2F;&#x2F;t3x.org</a> has literal books on that, from a simple C compiler to Scheme (you might heard of s9) and T3X0 itself which can run under Unix, Windows, DOS, CP&#x2F;M and whatnot.<p>PD: Klong&#x27;s intro to statisticks, even if the compiler looks like a joke, it isn&#x27;t. It can be damn useful. Far easier than Excel. And it comes with a command to output a PS file with your chart being embedded.<p><a href="https:&#x2F;&#x2F;t3x.org&#x2F;klong&#x2F;" rel="nofollow">https:&#x2F;&#x2F;t3x.org&#x2F;klong&#x2F;</a><p>Intro to statistics with Klong<p><a href="https:&#x2F;&#x2F;t3x.org&#x2F;klong&#x2F;klong-intro.txt.html" rel="nofollow">https:&#x2F;&#x2F;t3x.org&#x2F;klong&#x2F;klong-intro.txt.html</a><p><a href="https:&#x2F;&#x2F;t3x.org&#x2F;klong&#x2F;klong-ref.txt.html" rel="nofollow">https:&#x2F;&#x2F;t3x.org&#x2F;klong&#x2F;klong-ref.txt.html</a><p>On S9, well, it has Unix, Curses, sockets and so on support with an easy API. So it&#x27;s damn easy to write something if you know Scheme&#x2F;Ncurses and try stuff in seconds. You can complete the &quot;Concrete Abstractions&quot; book with it, and just adapt the graphic functions to create the (frame) one for SICP (and a few more).<p>And as we are doing compilers... with SICP you create from some simulator to some Scheme interpreter in itself.

4/15/2026, 3:39:24 PM


by: felishiagreen12

[dead]

4/16/2026, 1:18:37 PM


by: zionpi

[dead]

4/15/2026, 10:56:30 AM


by: baarse

[dead]

4/15/2026, 12:37:15 PM


by: blueybingo

[dead]

4/15/2026, 7:12:02 PM


by: consomida

[dead]

4/15/2026, 10:24:34 AM


by: imrozim

[dead]

4/15/2026, 10:30:01 AM


by: rdevilla

[flagged]

4/15/2026, 10:30:59 AM


by: lateforwork

These days there&#x27;s an even easier way to learn to write a compiler. Just ask Claude to write a simple compiler. Here&#x27;s a simple C compiler (under 1500 lines) written by Claude: <a href="https:&#x2F;&#x2F;github.com&#x2F;Rajeev-K&#x2F;c-compiler" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Rajeev-K&#x2F;c-compiler</a> It can compile and run C programs for sorting and searching. The code is very readable and very easy to understand.

4/15/2026, 1:16:58 PM