JS/CC Parser and Lexer Generator
I just wanted to anounce you about a new parser generator project I released the last days. It is the JS/CC, a LALR(1) parser generator for JavaScript/ECMAScript, with the feature that it was itself entirely written in JavaScript. The JS/CC parser generator is based on the concepts of the lex/yacc behavior, but unions both a lexical analyzer generator for matching the tokens of a language, and a LALR(1) parser generator for parsing the language structure as defined using a BackusNaur form-based meta language.
The characteristic, that JS/CC is capable to compile and run a complete parser from a grammar definition within a web browser makes it very useful for educational purposes. JS/CC can even be executed via command-line on Microsoft Windows systems using the Windows Script Host or JScript.NET executable to do the job.
JS/CC was released as open source software under the Artistic License.
A simple example grammar to be compiled using JS/CC is this four-function calculator.
/~ -- Token definitions -- ~/
/~ Characters to be ignored ~/
! ' |\t' ;
/~ Non-associative tokens ~/
'\('
'\)'
'[0-9]+' INT [* %match = parseInt( %match ); *]
'[0-9]+\.[0-9]*|[0-9]*\.[0-9]+' FLOAT [* %match = parseFloat( %match ); *]
;
/~ Left-associative tokens, lowest precedence ~/
< '\+'
'\-';
/~ Left-associative tokens, highest precedence ~/
< '\*'
'/';
##
/~ -- Grammar specification -- ~/
p: e [* alert( %1 ); *]
;
e: e '+' e [* %% = %1 + %3; *]
| e '-' e [* %% = %1 - %3; *]
| e '*' e [* %% = %1 * %3; *]
| e '/' e [* %% = %1 / %3; *]
| '-' e &'*' [* %% = %2 * -1; *]
| '(' e ')' [* %% = %2; *]
| INT
| FLOAT
;
When this is put to the JS/CC web-interface, it builds a complete, working parser out of this augmented grammar definition.
Visit the official project website at http://jscc.jmksf.com!
Best regards,
~codepilot

