Hacker News Comments on
Retargetable C Compiler, A: Design and Implementation
·
7
HN comments
- This course is unranked · view top recommended courses
Hacker News Stories and Comments
All the comments and stories posted to Hacker News that reference this book.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.
⬐ randomifcpfanSmall-C was the best one with open source, but there were many others. This one was my favorite: https://www.bdsoft.com/resources/bdsc.html⬐ pjmlpWhat I got back in the day came in book form, it was also another flavour."A book on C"
https://link.springer.com/book/10.1007/978-1-349-10233-4
It uses a K&R C subset with bytecodes and a bytecode-> machine language translation.
I just never bothered to type it in though.
This might be relevantA 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.
⬐ jacquesmHappy new year to you Ravi!⬐ plinkplonkThanks Jacques. Same to you, (and everyone on HN!)
A Retargetable C Compiler: Design and Implementationhttps://www.amazon.com/Retargetable-Compiler-Design-Implemen...
A most excellent grimoire.
⬐ useanaliasMisread this as "A Regretable C Compiler" -- likely what would happen to me without a text like this!
I wouldn't go so far to say that the Dragon Book is outdated and irrelevant. (I'm assuming you're referring to the 2nd edition from 2006.) Unless you're focusing on back-end optimization and code generation techniques (something a new compiler writer typically does NOT do), the bulk of the theory and material you'd cover in a first semester 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 a recursive descent approach (no flex/lex or bison/yacc). I have some experience augmenting this compiler, so I can vouch for the book's ability to clearly convey their design.
Compiler Design in C, by Allen Holub (http://www.holub.com/software/compiler.design.in.c.html). Downloadable PDF at that link as well. A book from 1990 in which Holub constructs his own version of lex and yacc, and then builds a subset-C compiler which generates intermediate code.
Practical Compiler Construction, by Nils Holm (http://www.lulu.com/shop/nils-m-holm/practical-compiler-cons...). A recent book which documents the construction of a SubC (subset of C) compiler and generates x86 code on the back end.
⬐ sklogicIt is actually an outdated view, to split a compiler into dedicated monolithic front-end and back-end parts. The more modern approach is very much the opposite. It is a nearly continuous, very long sequence of very simple transforms, rewriting a code seamlessly, all the way down from a front-end (i.e., a parser) to a back-end or multiple back-ends. And this approach is very alien to anything you'd find in the Dragon Book.As for parsing, as I already said elsewhere in this thread, all the techniques from Dragon Book are not practical any more and are not used in the modern compilers. There are far better ways, which are not covered in the book, and they're far simpler, not even deserving a dedicated book at all.
lcc(1) the C compiler. As well as having readable C source, you'd learn something about the innards of C, how it is implemented, and there's a good accompanying book by Fraser and Hanson that covers the complete source as a "literate program". https://github.com/drh/lcc/blob/master/src/lex.c http://www.amazon.com/exec/obidos/ASIN/0805316701/mqq-20
Search the net for one or another of the SmallC compilers (Ron Cain wrote the original one) published in Dr. Dobbs Journal. Later authors tarted up the original code adding more of C to the mix to make it more useful and managed to confuse things.Chris Fraser and Dave Hanson's A Retargetable Compiler is another good example system with code to read and modify.
http://www.amazon.com/Retargetable-Compiler-Design-Implement...
10 years ago, I loved Hanson and Fraser:http://www.amazon.com/exec/obidos/ASIN/0805316701
This is a good tour of front-end and back-end stuff, a decent intro to code gen, and is built on a hand-written recursive-descent C parser. That it's specific to one C compiler made it better to read straight through, but I rarely refer back to it.
So far this year, I've been liking Muchnick:
http://www.amazon.com/exec/obidos/ASIN/1558603204
This is pretty heavy on the backend and codegen, which is where my head is at these days.
Compilers is a big topic. What part interests you most? Parsing? Optimization? Semantics and error detection? Code generation?