Simple JavaScript Lexer/Parser based on the 'dragon book'

This is something of a learning exercise to understand the concepts of Compilers: Principles, Techniques, and Tools. Currently, the lexer does not use the NFA techniques of the book - it uses iterative matching of native JavaScript regular expressions. There are two parses - a simple one based on iterative pattern matching of the production expressions (supporting precedence), and an automaton based on SLR (supporting precedence and associativity).

For the trivial time-unit-dsl expression langauge I've been testing with, regex hacking was a lot faster and easier (one evening) than the full fledged automaton techniques of the book (a couple of weekends) However, I did finally get it working, and it the resulting parser passes the - probably very insufficient - set of tests I threw at it. It operates off of data structures, and additional grammars can be fed in to parse additional languages. Over time, I expect to add at least one language for testing - SillyScript - and try out other parse construction methods.

Other methods I know of

Know Bugs

  • The simple parser doesn't support associativity
  • 'Unit Tests' are sorely lacking
  • Precedence assignment is implicit; overrides are possible but are fragile and require understanding the implicit assignment algorithm.