JS/CC, a LALR(1) parser generator for JavaScript written in JavaScript

"mailings@jmksf.com" <mailings@jmksf.com>
Thu, 27 Sep 2007 22:20:53 +0200

          From comp.compilers

Related articles
JS/CC, a LALR(1) parser generator for JavaScript written in JavaScript mailings@jmksf.com (mailings@jmksf.com) (2007-09-27)
| List of all articles for this month |

From: "mailings@jmksf.com" <mailings@jmksf.com>
Newsgroups: comp.compilers
Date: Thu, 27 Sep 2007 22:20:53 +0200
Organization: Compilers Central
Keywords: parse, tools, available
Posted-Date: 28 Sep 2007 12:18:55 EDT

Hello to everybody!


I just wanted to inform 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.


To get JS/CC, visit the official project website at http://jscc.jmksf.com


Thanks a lot!


Best regards,
Jan Max


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.