Building a Parser Generator

I wonder how many software developers have ever built a parser generator.  I recently got to do just that.


My company has a proprietary language, I’ll call it MO, that compiles to M (MUMPS).  I am part of a project that involves creating a new compiler for MO that will compile not only to M but also to Java.  Pretty cool.  This is not your typical business software application development.  It is more computer-science-ish.


The current compiler is hand-written and single phase.  It writes out M code as it reads in MO code.  The new compiler will use a generated parser, which meant we needed a parser generator.  However, a requirement is that the parser be written in MO itself.  Of course, no existing parser generators generate a parser in MO, so we had to write our own.

The parser generator I built closely follows YACC (in terms of grammar specification and error handling).  Like YACC, it generates LALR(1) parsers.  Building it was great fun for me, and I really enjoyed cracking open Compilers: Principles, Techniques, and Tools by Aho et al (“The Dragon Book”).

The parser generator is written in MO itself.  This was done somewhat arbitrarily.  One (minor) advantage is that it lets you do everything in the MO environment.  It also let me explore using new OO features in MO.  I think it could be written just as well in Java.  Maybe I’ll do that for comparison.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: