
-----------------------------------
ttm
Sun Mar 18, 2012 5:58 pm

Moose -- LR Parser Generator
-----------------------------------
Moose -- LR Parser Generator in C++

Intro
Over the March break I had a lot of free time (and a copy of the It is capable of recognizing grammars of class Also, I don't understand how SDTs work yet so the generated parser might be a bit different from other parser generators. Basically new'd a lot, queue's being arrays with index hacks, you get the idea). I gave up after almost half finishing, but always meant to finish it. Fast forward to March break Tuesday morning, I remembered it and decided it would be a good idea to restart, but this time, in C++. (spoiler: SUCCESS)The Grammar Definition
The grammar definition is the main input to the parser generator. Much like almost any other parser generator in existence, it uses a modified form of C-style comments. (//-style comments are NOT VALID)
The start symbol is automatically the left-hand-side of the first production in the file.
Productions start with  : and end with ;
Productions can use boolean OR with the vertical bar |
Terminals start with $
Terminals are defined as ($APPOSA : "(\'?a?)";)
That's pretty much all you need to know. Fancy helpers like (), *, +, and ? are not provided, not only because you can write an equivalent grammar not requiring those, but also because it complicates things in the AST (and totally not because I CBA).
(There is, however, 1 other useful feature not shown above. You'll see it in the next example.)
(Be careful when writing your grammars -- the parser generator doesn't yet tell you your grammar's errors and thus may enter an infinite loop or crash if you mess up.)


Usage
The command line arguments are dead-simple. Here they are:
Example -- Calculator
Here is an example grammar you can input into the generator to get a math expression parser:
The %autowhitespace is a regex that the lexer optionally checks after each token and ignores. I wish I had more time to write a full tutorial, but March break is over. For now, enjoy!
