Squirrel Parser Generator
Squirrel is a simple
packrat parser
implemented in Java 5.0.
It is intended primarily for educational use. Ease-of-use is the primary
design criterion. I employ it in my Programming Practicum course (CSCI 250).
Here are its noteworthy features:
- The parser is built by calling methods of the squirrel.Grammar class; no
explicit parser generation step is necessary.
- The parser is invoked using a single method call.
- It generates an abstract syntax tree without any additional
programming.
- It allows for some simple uses of left recursion.
- The lookahead symbols "!" and "&" from parsing expression grammars are
implemented and fully functional. Prefixing a term with "!" rejects
a string that matches the term without consuming input; prefixing with
"&" rejects a string that fails to match the term, again without
consuming input.
Drawbacks:
- Only an incompatible subset of the syntax for
parsing expression grammars (and context-free grammars) is recognized:
- Square brackets can only be used to make a single symbol optional
at a time; to make a group of symbols optional when seen together
requires the introduction of an additional nonterminal. The question
mark ("?") is not used for optional productions.
- Parentheses for grouping alternatives are not recognized; again,
additional nonterminals must be introduced to compensate for this.
- The regex-like syntax (* and +) for iteration is not included at all;
only recursion may be used to describe a sequence.
- Neither the bar ("|") nor the slash ("/") is used for alternation;
instead, alternatives are expressed as multiple arguments to the
production creating method.
- The parser halts after the first syntax error; it cannot recover and
continue.
- The error messages cannot be customized; they are expressed in terms of
a mismatch to a grammar production name.
- The only way to use the parser is to generate a parse tree for
an entire input string, followed by walking the tree to generate
any additional data structure needed.
Squirrel is still under development, but a prototype is available for
downloading. It is distributed under a permissive BSD-style open source
software licence.
You can find my email address at my
home page.
Downloads