3 ms·
Ask HN: Which compiler book to pick?
Hi,
For years I have been interested in programming languages and their implementation. I have made many attempts over time to create my own (experimental) programming languages, mostly interpreters.
The problem is, my knowledge of this area of computer science is fragmented, to say the least. I picked up things here and there, but I never learned how to properly implement a compiler, interpreter, virtual machine, or even a parser.
So, I have decided to pick a book and work my way through it. I just don't know which book. They all seem equally intimidating. A few candidates that I am considering are:
- The Dragon Book (new version, 2006); seems awfully big though, making me wonder whether I should pick a book that is a bit less comprehensive first, then come back to this one later;
- The Dragon Book (old version, 1986)
- Engineering a Compiler, by Keith Cooper and Linda Torczon
- Parsing Techniques - A Practical Guide, by Dick Grune; focuses on parsing though rather than the whole package
So my question is, which of these books, or any others, do people recommend? (My main interests would be interpreters and languages that compile to bytecode, either custom or targeting existing VMs. "Traditional" compilers that produce a standalone executable, not so much.)
Thanks in advance!
- runT1ME 16y agoPossibly my favorite programming book is Shared Source CLI essentials. It walks you through the internals of a functioning Virtual Machine for the .NET platform. You get JIT (compiling), GC, class loading, etc. It's presented very straightforward and there is lots of code to look at. http://www.amazon.com/gp/product/059600351X/ref=pd_lpo_k2_dp_sr_1?pf_rd_p=486539851&pf_rd_s=lpo-top-stripe-1&pf_rd_t=201&pf_rd_i=0321159837&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=0QBCT9069JX6E4MRFGJS http://www.amazon.com/gp/product/059600351X/ref=pd_lpo_k2_dp...
- silentbicycle 16y agoActually, before you worry about the other resources in this comment - start with _Let's Build a Compiler_ (http://compilers.iecc.com/crenshaw/ http://compilers.iecc.com/crenshaw/) - it'll make compilers seem much less intimidating. Follow along in Python, Ruby, Lua, whatever. Earlier today, somebody asked about parsing. There's much overlap with my answer to that (http://news.ycombinator.com/item?id=1820858 http://news.ycombinator.com/item?id=1820858), though I would doubly recommend getting one of the Appel books. I'm Not A Fan of the old Dragon book. I haven't read the new one or _Engineering a Compiler_ (yet), though. I highly recommend _Essentials of Programming Languages_, though it focuses on interpreters rather than compilers. There's a chapter at the end of the first printing (they cut it from the second and third editions, le sigh) about taking a CPS-based interpreter and turning it into a compiler, too. Very cool. _Lisp in Small Pieces_ has good content about compiling "dynamic" languages (with a Lisp-y flavor, of course). The Rabbit and Orbit papers at http://library.readscheme.org/page8.html http://library.readscheme.org/page8.html are good, too. Also, since you seem to have the same quirky, self-taught background I do - I found tinkering with low-level implementations of Forth to be very helpful in understanding virtual machines. Read the source to jonesforth (http://www.annexia.org/forth http://www.annexia.org/forth) and/or write a Forth in C, it will teach you quite a bit. Also, read about Lua's virtual machine - it's small, clean, and very well engineered.
- zephyrfalcon 16y ago"Read the source to jonesforth (http://www.annexia.org/forth http://www.annexia.org/forth) and/or write a Forth in C, it will teach you quite a bit." :) That is actually what I did last month. (The assembler source doesn't always translate well to C, so it required a lot of careful thinking about what is going on and how to expres it in C.) I think I ended up writing three Forths, and I did indeed learn a lot. I did some of the other things too... used to have LiSP, worked through the first few chapters of EOPL, did the Crenshaw tutorial too back in the day. I still feel that the way I do things are, well, hackish, and incomplete, and suboptimal. I was kind of hoping that there would be a Book that would solve these problems...
- silentbicycle 16y agoDefinitely check out the Appel's _Modern Compiler Implementation in ML_, then. And don't forget to do the exercises, then you'll know you know what you know. :)
- drallison 16y agoSearch 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-Implementation/product-reviews/0805316701/ref=dp_top_cm_cr_acr_txt?ie=UTF8&showViewpoints=1 http://www.amazon.com/Retargetable-Compiler-Design-Implement...