Live data from Hacker News

Learning to write a compiler

stackoverflow.com

21–30 of 42 posts

Re: Learning to write a compiler

#21
post #15
post #2

I'm upvoting this just to hopefully start a discussion and hear more about this topic from fellow HNers. I hear the Dragon Book mentioned almost daily around here; I'm intrigued. Do you think this book could be read by someone who's not actually interested in writing a compiler? Does the book stand by itself? I'm interested in reading it, but I don't really think I have the motivation to start writing my own compiler…

DO NOT READ THE DRAGON BOOK. It's not a very good introduction to compilers. Read Engineering a Compiler by Cooper and Torczon. The Appel book is also very good, and contains some stuff about functional and logic languages that are generally missing from most compiler texts. If you're an enthusiast, but not in it to build a compiler, I really enjoy Programming Language Pragmatics. For more advanced material, use the…

I started picking at Muchnick. From the look of it, it is almost all back-end stuff.

mouth waters

Re: Learning to write a compiler

#22
post #12
post #2

I'm upvoting this just to hopefully start a discussion and hear more about this topic from fellow HNers. I hear the Dragon Book mentioned almost daily around here; I'm intrigued. Do you think this book could be read by someone who's not actually interested in writing a compiler? Does the book stand by itself? I'm interested in reading it, but I don't really think I have the motivation to start writing my own compiler…

When did reading books become a purely utilitarian thing? Interested in reading it? Read it. It's a good book. You don't have to do the exercises.

"When did reading books become a purely utilitarian thing?"

When the answer to the question "How do I learn to do X?" is "Read this book."

Nice sentiment, wrong place. "Read this book even though it won't help you learn X" translates directly to "Don't read this book." in this context.

Re: Learning to write a compiler

#23
post #11

Here is an earlier incarnation of the "writing a compiler" thread: http://news.ycombinator.com/item?id=1608129

Oops, I downvoted you when I meant to upvote. There is probably another incarnation or three before the one you linked, too. I'd recommend Appel's "Modern Compiler Implementation in ML" over the dragon book.

I noticed there are a few versions, including for Java and C. Any reason why the ML version is better (not against ML; just don't know it well enough (at all actually)).

Re: Learning to write a compiler

#24
post #12
post #2

I'm upvoting this just to hopefully start a discussion and hear more about this topic from fellow HNers. I hear the Dragon Book mentioned almost daily around here; I'm intrigued. Do you think this book could be read by someone who's not actually interested in writing a compiler? Does the book stand by itself? I'm interested in reading it, but I don't really think I have the motivation to start writing my own compiler…

When did reading books become a purely utilitarian thing? Interested in reading it? Read it. It's a good book. You don't have to do the exercises.

When we started having to prioritize our time.

i.e., around high school, with a significant increase after college / marriage.

Re: Learning to write a compiler

#25
post #15
post #2

I'm upvoting this just to hopefully start a discussion and hear more about this topic from fellow HNers. I hear the Dragon Book mentioned almost daily around here; I'm intrigued. Do you think this book could be read by someone who's not actually interested in writing a compiler? Does the book stand by itself? I'm interested in reading it, but I don't really think I have the motivation to start writing my own compiler…

DO NOT READ THE DRAGON BOOK. It's not a very good introduction to compilers. Read Engineering a Compiler by Cooper and Torczon. The Appel book is also very good, and contains some stuff about functional and logic languages that are generally missing from most compiler texts. If you're an enthusiast, but not in it to build a compiler, I really enjoy Programming Language Pragmatics. For more advanced material, use the…

>I get the impression that most people who recommend the Dragon book haven't read it.

These days you can usually tell that they haven't read it if they refer to it as "the Dragon book" and don't say anything about the edition. The same thing goes for "Knuth", "the Appel book", etc.

Re: Learning to write a compiler

#26
post #20

Earlier quoted context omitted.

Couldn't agree more, I hack on compilers a fair bit (one of my own, plus the JITs in PyPy and Unladen Swallow) and the Dragon Book was impossible for me to get anything out of.

IMO, the format of this book makes sense for the context it was intended for: Stanford's course on optimizations and program analysis, where the problem sets and reading provide theoretical knowledge and the projects -- hacking on the joeq VM/compiler-infrastructure -- provide implementation experience. These distinct experiences make for a well-rounded education in advanced compiling techniques. (Disclaimer: I have…

I think there more obvious problems with the dragon book:

in particular, ~300+ pages are spent focusing on techniques for doing parsing and lexing.

Now if I want to write a baby yacc [sic], this might be useful. But in this modern era, parsing is a very well understood problem, with lots of easy to use tool. Yes in a production compiler helpful syntax and type error messages are key, but when you're learning the compiling part, you want a book that doesn't spend half of its volume on that topic. Also, the 2nd edition doesn't seem to have a single level reader in mind.

The intro book people should look at is (as mentioned elsewhere), should be the intro to compilers in ml book by appel, and for advanced stuff folks should look at stuff like appel's compiling with continuations, the munchnick (spelling?) book, and one or two others.

I think the point is that 1) most exposure to the dragon book for most folks predates the 2nd edition, and in your experience, most of the learning sounds like it was from the lecture notes and problems sets rather than the text (presumably used as a reference supplement in practice?)

Re: Learning to write a compiler

#27
post #2

I'm upvoting this just to hopefully start a discussion and hear more about this topic from fellow HNers. I hear the Dragon Book mentioned almost daily around here; I'm intrigued. Do you think this book could be read by someone who's not actually interested in writing a compiler? Does the book stand by itself? I'm interested in reading it, but I don't really think I have the motivation to start writing my own compiler…

I think the Dragon book is pretty approachable for someone with basic CS background. It's also quite extensive in its coverage of compiler implementation techniques. However, as others have already pointed out, certain aspects are not covered in full and implementation details are not always provided.

My suggestion? Read it. True to its title, "Principles, Techniques and Tools", it delivers just that. I don't think you'll find its contents impenetrable, but perhaps it will seem too abstract in case you're looking for implementation guidelines.

Some things that might bug you about the Dragon Book: 1) extensive coverage of lexical analysis and related techniques, 2) it's not suited for a more pragmatic course - this is better left to books like Muchnick's "Advanced Compiler Design and Implementation" and friends 3) it omits certain important advances in the field, such as the work of Pager, A Practical General Method for Constructing LR(k) Parsers. Acta Informatica 7, 249-268., 1977 (in all fairness to the book authors, all work after yacc was out in 1973 has apparently gone unnoticed by all).

Disclaimer: I've only read the Pearson International Edition, which according to what I hear, is identical to the first edition. I don't know to what extent this is true. Maybe someone can confirm/refute this?

Re: Learning to write a compiler

#28
post #20

Earlier quoted context omitted.

IMO, the format of this book makes sense for the context it was intended for: Stanford's course on optimizations and program analysis, where the problem sets and reading provide theoretical knowledge and the projects -- hacking on the joeq VM/compiler-infrastructure -- provide implementation experience. These distinct experiences make for a well-rounded education in advanced compiling techniques. (Disclaimer: I have…

I think there more obvious problems with the dragon book: in particular, ~300+ pages are spent focusing on techniques for doing parsing and lexing. Now if I want to write a baby yacc [sic], this might be useful. But in this modern era, parsing is a very well understood problem, with lots of easy to use tool. Yes in a production compiler helpful syntax and type error messages are key, but when you're learning the comp…

You make a good point; it does spend a lot of time on the front-end. As pointed out elsewhere, Muchnick is more thorough on back-end topics, which it appears we both agree are far more interesting. I've definitely heard of those other books before, and in particular, Appel's _Compiling with Continuations_ will be especially interesting when I look into compiling functional languages.

Actually, I don't have any personal experience with the Stanford course. I am reading the book for fun really. (For all its faults, it is quite engrossing!) I just thought it would be relevant to investigate under what context this book is generally used.

Re: Learning to write a compiler

#29
post #27
post #2

I'm upvoting this just to hopefully start a discussion and hear more about this topic from fellow HNers. I hear the Dragon Book mentioned almost daily around here; I'm intrigued. Do you think this book could be read by someone who's not actually interested in writing a compiler? Does the book stand by itself? I'm interested in reading it, but I don't really think I have the motivation to start writing my own compiler…

I think the Dragon book is pretty approachable for someone with basic CS background. It's also quite extensive in its coverage of compiler implementation techniques. However, as others have already pointed out, certain aspects are not covered in full and implementation details are not always provided. My suggestion? Read it. True to its title, "Principles, Techniques and Tools", it delivers just that. I don't think y…

> It's also quite extensive in its coverage of compiler implementation techniques.

With only two pages about SSA ? (which is the internal representation used by most compilers this days)

Re: Learning to write a compiler

#30
post #23

Earlier quoted context omitted.

Oops, I downvoted you when I meant to upvote. There is probably another incarnation or three before the one you linked, too. I'd recommend Appel's "Modern Compiler Implementation in ML" over the dragon book.

I noticed there are a few versions, including for Java and C. Any reason why the ML version is better (not against ML; just don't know it well enough (at all actually)).

I think that ML has some features (such as pattern matching) that makes it a better fit for writing a compiler than Java or C.
Post reply on HN