
A retargetable C compiler
by Christopher W. Fraser · first published 1995
53% recommend41% neutral6% critical
Why HN recommends it
Literate-programming walkthrough of a complete, working C compiler (lcc), showing how a real retargetable compiler is built; recommended to programmers who want to see a full compiler design end to end.
Summarised by Claude from recommending comments
Features: discusses the implementation and design tradeoffs made while constructing a real ANSI C compiler, illustrating the interaction between theory and practice; covers compiler theory only as needed to understand the implementation of Icc, focusing instead on practical, applied issues; encourages a deeper understanding of programming in C, by providing C programmers with a tour of the language from the perspective of compiler authors; includes coverage of code generators for the MIPS R3000, SPARC, and Intel 386 and its successors; and provides access to the full source code for the Icc co
Affiliate links. As an Amazon Associate I earn from qualifying purchases.







…compiler course is fairly static. But if a person is merely looking to bang out a compiler without getting overwhelmed with how to convert NFAs to DFAs for lexing, etc., some good alternative books are: A Retargetable C Compiler: Design and Implementation, by Hanson and Fraser (http://www.amazon.com/Retargetable-Compiler-Design-Implement...). This book constructs and documents the explains the code for a full C compiler with…
on “How I wrote a self-hosting C compiler in 40 days” ↗A Retargetable C Compiler: Design and Implementation https://www.amazon.com/Retargetable-Compiler-Design-Implemen... A most excellent grimoire.
on “Ask HN: What are some books where the reader learns by building one project?” ↗Anyone that wants to write C compilers has two good books for it. "A Retargetable C Compiler: Design and Implementation", from David R. Hanson and Christopher W. Fraser "Compiler Design in C", from by Allen I. Holub A bit old, but there are not significant changes to C since they were written,…
on “Writing a C Compiler, Part 1” ↗This might be relevant A Retargetable C Compiler: Design and Implementation by David Hanson and Chritopher Fraser https://www.amazon.com/Retargetable-Compiler-Design-Implemen... Written in a literate programming style.
on “C Compiler from Scratch” ↗…great C books out there: * C Programming Language - by K&R * The Indispensable Guide to C with Engineering Applications - by Paul Davies * C Interfaces and Implementations - by David Hanson * A Retargetable C Compiler: Design and Implementation - by David Hanson * Graphics Programming Black Book - by Abrash with lots of Quake goodies
on “The myth of the Lisp genius” ↗A number of people have recommended David R. Hanson's C Interfaces and Impementations, so I'll mention his A Retargetable C Compiler: Design and Implementation. I own this book though I haven't read it, but it's about writing a C compiler in C. You should pretty much just go out and buy these two books because they'll eventually go…
on “Ask HN: I use and love Python. What's the best book to learn C ?” ↗> The Plan 9 code has some very clean code I'd love to hear others' recommended "classic" works..? The lcc compiler. It's written as a literate program. Read A Retargetable C Compiler by Hanson and Fraser.
on “Ask HN: I think My code isn't Good enough” ↗If besides the author's book (good work), you want to delve into how others approach the subject, check - Retargetable C Compiler, A: Design and Implementation - Compiler Design in C
on “Writing a C Compiler is a book” ↗* David Hanson: C Interfaces and Implementations * David Hanson: A Retargetable C Compiler * John Lakos: Large-Scale C++ Software Design * VA: Beautiful {Code, Data, Testing} * Design pattern books maybe * Code Complete * Fred Brooks: The Mythical Man Month * Fred Brooks: Design of Design…
on “Ask HN: Suggested software /design/ books?” ↗This is more specific to C, but can still be applied to other areas. I always thought it was a great read. A Retargetable C Compiler: Design and Implementation https://sites.google.com/site/lccretargetablecompiler/
on “Let’s Build a Compiler (1995)” ↗The excellent book "C Interfaces and Implementations: Techniques for Creating Reusable Software" by David Hanson as well as "A Retargetable C Compiler: Design and Implementation" by the same author are both written in the literate programming style. I'd definitely say it's unpopular, but hardly goofy from a pedagogical point of view. C Interfaces…
on “Questions for Donald Knuth” ↗The list is missing "Retargetable C Compiler, A: Design and Implementation", which is one of my favorite programming books. It's a literate program of a full c compiler.
on “Essays on programming I think about a lot” ↗…books really helped me understand where I wanted to be as a programmer. Technology ========== With a stronger focus on technology I recommend: - "Language Implementation Patterns" - Terence Parr - "A Retargetable C Compiler: Design and Implementation" - Hanson, Fraser I found them more helpful than the Red Dragon Book. The latter is good, but as a beginner I felt a little lost and Terence Parr's book was much more helpful.…
on “Ask HN: What language-agnostic programming books should I read?” ↗…version of LCC is here[2]: Not sure if you can regenerate the book out of the current code or not (LCC is written in literate programming style, and the book used to be just the literate part). [1] A Retargetable C Compiler: Design and Implementation (Addison-Wesley, 1995, ISBN 0-8053-1670-1) [2] https://github.com/drh/lcc
on “GNU Compiler Collection Internals [pdf]” ↗Unless you are talking about something like "A Retargetable C Compiler: Design and Implementation", it is definitly not easy. https://www.amazon.com/Retargetable-Compiler-Design-Implemen... During the early 80's, the best home computers could get was Small-C. https://en.wikipedia.org/wiki/Small-C
on “Implementing a LLVM Micro C compiler in Haskell” ↗