News for hackers. Stuff that matters.
Re:Want to Write a Compiler? Just Read These Two Papers. by praptak on Friday August 26, 2011 @05:09AM (#2927893)
"I decided to do it by hand, for its educational value, rather than use a parser generator."

My experience was quite different. I am glad for having started with a parser generator - this got the tedious part out of the way so that I could think of how to generate code.

I later learned the theory behind various kinds of parsers, but I think that a beginner in compilers can safely leave it out.

Re:Want to Write a Compiler? Just Read These Two Papers. by perlgeek on Friday August 26, 2011 @05:23AM (#2927909)
One of the very interesting lessons from Crenshaw's "Let's build a compiler" is that writing a simple, recursive descending parser isn't hard at all.
Re:Want to Write a Compiler? Just Read These Two Papers. by silentbicycle on Friday August 26, 2011 @08:47AM (#2928277)
Niklaus Wirth has been saying that for quite a while. :)

His _Compiler Construction_ book is short, sweet, and has a free PDF online (http://www.inf.ethz.ch/personal/wirth/books/CompilerConstruc...). Uses Oberon.

Re:Want to Write a Compiler? Just Read These Two Papers. by buff-a on Friday August 26, 2011 @05:57AM (#2927965)
Fair point. But I have been in the situation where I've got a RDP that outputs what I originally wanted, but now I want, e.g., to output an intermediate form, and I'm fucked.

So writing it isn't all that hard. But changing it after you've written it is a recipe for disaster. I did that a couple of times and looked for A Better Way.

A tool like ANTLR, OTOH, makes re-purposing (and initial development and testing) easy, but at the expense of runtime performance.

Perhaps the lesson is, "write a few RDPs to get the hang of it and then make life easy on yourself"?

Re:Want to Write a Compiler? Just Read These Two Papers. by WalterBright on Friday August 26, 2011 @05:58AM (#2927966)
I find it easier to write a parser by hand than use a parser generator. For most languages (C++ is a notable exception) writing a lexer & parser is a weekend job, and is far and away the easiest part.
Re:Want to Write a Compiler? Just Read These Two Papers. by pja on Friday August 26, 2011 @06:48AM (#2928047)
C++ looks like it ought to be OK to parse, but turns out to be completely evil. (flamebait mode on) Bit like the rest of the language really. (flamebait apologia: I spend most of my time coding C++; sometimes I even enjoy it...)
Re:Want to Write a Compiler? Just Read These Two Papers. by WalterBright on Friday August 26, 2011 @02:50PM (#2929491)
Just lexing C++ is a major project, because of the 'phases of translation', the preprocessor, the preprocessor tokens, etc., and then trying to make it fast.
Re:Want to Write a Compiler? Just Read These Two Papers. by sb on Friday August 26, 2011 @04:35PM (#2929874)
I agree and there used to be (maybe it's still the case) problems with parser generators if you wanted to have good error recovery and reporting to the user. It's also very telling that sometimes--contrary to what people might expect--parsers pose a substantial problem in production systems: http://cacm.acm.org/magazines/2010/2/69354-a-few-billion-lin...:

Law: You can't check code you can't parse. Checking code deeply requires understanding the code's semantics. The most basic requirement is that you parse it. Parsing is considered a solved problem. Unfortunately, this view is naïve, rooted in the widely believed myth that programming languages exist.