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

This book appears to be more of a "compiler-compiler design in C"; it goes through how to write a lexer and parser generator, then writes a compiler using them, and I think the resulting compiler is a bit of a letdown: it does not much more than translate C into a linearised subset of C, and so the IMHO more "interesting" and important parts of the back-end like register allocation and instruction selection are completely absent.

It's a good if somewhat outdated book if you're interested mostly in parsing and lexing, but for all the claims it makes in the preface about being practical instead of theoretical and all the source code presented throughout, I found the lack of actual Asm code generation (or any mentions of this compiler being able to compile itself) disappointing.

Parser/lexer generators also seem to have fallen out of favour for the creation of actual compilers, both big and small, at least for C-like languages; techniques based on recursive-descent (RD) are quite popular now.

On the "big, production-quality" side, gcc used a generated parser but moved to a handwritten RD-based one, and Clang always used RD. EDG's front-end, used in Intel's and other commercial compilers, is also handwritten RD. On the small "toy compiler"/hobbyist/experimentation side, there's TCC/OTCC, CC500 ( https://news.ycombinator.com/item?id=8576068 ), C4 ( https://news.ycombinator.com/item?id=8558822 ), SubC ( http://www.t3x.org/subc/ ), and many others, all based on RD parsers.

In fact I can't think of any C compilers at the moment that are using a generated parser/lexer...




"...for all the claims it makes in the preface about being practical instead of theoretical..."

It's important to view this book in the context of its time. At that time, there were no books that showed you both the theory and complete running code for even this much. The compiler books (Dragon, 1st ed.; etc.) showed toy snippets but not a full lexer, parser, and code generator. There were only the articles in Dr. Dobb's about Small-C to show the way. So, at the time, Holub's book was a godsend. It married theory and implementation in a way that simply had not been done before. Hanson's and Fraser's 1995 book on a retargetable C compiler was a similar milestone, although it came out several years later.

After those two landmark books, explanations of full compiler implementations were no longer a rarity.


This underscores what David Conroy used to say when writing the MWC compiler: Yacc makes the hard part harder and the easy part easier.

And I agree for all its thoroughly-written tutorial approach, I don't find myself going back to it very often.


Care to expose any good book explaining more modern approach for compilers from the practical point of view (including RD)?


Practical Compiler Construction: http://www.t3x.org/reload/index.html

This explains the SubC compiler I mentioned in the original post.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: