jParser grammar

I’ve been asked how I generate the JavaScript parse table for jParser, so I’m posting the grammar file here for anyone else who’s interested.

↓ JavaScript grammar file for jParser

This file is in a (probably non-standard) variant of BNF notation. I’m not generating the tables with a tool like ANTLR primarily because I don’t write C. I should also point out that I don’t come from a formalized computer science background, so don’t expect this to be 100% conventional.

I’ve developed a native PHP parse table generator that in turn uses a parser (based on itself) to parse this BNF grammar into a table. If you understand grammar files like this you’ll notice something a bit odd – The terminal symbols don’t go right down to individual characters, the grammar expects the source code to already have been tokenized into significant chunks, such as J_NUMBER representing an already identified numeric token. This was done deliberately to be compatibile with PHP’s own Tokenizer functions. The underlying parser framework was designed such that PHP token based grammars could also be developed.