Hand Rolling


steamroller

Steam Roller • We’re gonna be rolling machines.

In this book we used mpc to do all the parsing, but in this appendix we’re going to replace mpc with our own hand rolled parser. The choice to use mpc has by far been the main source of complaints by readers of this book, and before we dive into the details of hand-rolling I want to talk about some of the reasons I decided on using a parsing library in the first place.

The main reason was that when I was learning about programming languages, I found the theory of formal languages fascinating. I really enjoyed getting into the mind set of thinking about languages more abstractly. I think this is a fun thing to teach, as it opens up a lot of new avenues of exploration.

Another reason is that it gives new programmers a chance to learn how to use a library. It gets them comfortable early on with weird interfaces, and other peoples’ code.

And finally, perhaps most importantly, using a library for the parsing allowed me to delay the topics of memory management and pointers for as long as possible - by which point readers should be much more comfortable with the C constructs they’d encountered so far.

But that doesn’t really matter - writing a parser by hand is a great thing to do, and although one with all the bells and whistles can be a complicated thing to get right, because our Lisp is so simple, for us it wont be too difficult.

Can I do this if I’ve not finished the book?

If you’ve not completed all the chapters of this book it is probably not a good idea to attempt this appendix. It may be possible to complete this appendix if you’re already past Chapter 9 • S-Expressions, but if you’re not completed this chapter already it might not make much sense. Sorry!