Friday, 23 March, 2001
Let's Build a Compiler!
When I was going to college, one of the most popular Computer Science electives was compiler design. We went through all the theory talking about LALR(1) parsers, terminals, non-terminals, peephole optimization, and all that, and then wrote the front end for a small Pascal-like language. Over the years, I've had reason to implement parsers for many different "languages," none even as difficult as the toy Pascal we worked with in college. And every time I need a parser construction reference I look not at the Dragon Book or any of the other mainstream compiler texts, but instead I turn to my faded printouts of Jack Crenshaw's Let's Build a Compiler. In this series of articles, Jack Crenshaw dispenses with most of the theory and gets right to the heart of creating a scanner and a parser. I followed this series while Jack was working on it, and even did a C conversion of the code (Jack's examples are in Pascal) for the first 8 installments. If you're at all interested in writing a parser of any type, you should take a look at this series.
I mention this today because I'm writing a parser for a client project. I got stuck, looked at my bookshelf, passed over the 5 different compiler construction books I have there, and dug through the closet (working at home today) looking for the 3-ring binder that contains the old printouts. Dot matrix printout of a fixed font. It's hardly pretty, but there's tons of good information on those pages. Check it out. It's worth your time.