JS/CC LALR(1) Parser Generator

Version
0.40.1 (2016)
Project state active
Download Check official project website
Official project site
/ Git repository
http://jscc.brobston.com/
https://github.com/abrobston/jscc
License BSD open source license
Contributors Andrew Brobston (new maintainer)
Jan Max Meyer (initial author)
Sergiy Shatunov
Louis P. Santillan

Overview

Image showing the JS/CC LogoJS/CC, JavaScript Compiler-Compiler, is one of the first available parser development system for JavaScript and ECMAScript-derivates. It has been developed, both, with the intention of building a productive compiler development system and with the intention of creating an easy-to-use academic environment for people interested in how parse table generation is done general in bottom-up parsing.

The platform-independent software unions a regular expression-based lexical analyzer generator matching individual tokens from the input character stream and a LALR(1) parser generator, computing the parse tables for a given context-free grammar specification and building a stand-alone, working parser. The context-free grammar fed to JS/CC is defined in a Backus-Naur-Form-based meta language, and allows the insertion of individual semantic code to be evaluated on a rule's reduction.

To use JS/CC and for understanding its internals and behavior, knowledge on context-free grammars, bottom-up parsing techniques and compiler construction theory, in general, is assumed.

Development Status

JS/CC is another LALR(1) Parser Generator project that was initially launched by Phorward Software Technologies, in 2007.

JS/CC was developed detached from the C-based Phorward software toolchain, as some kind of "casual project". Due the development of the UniCC LALR(1) Parser Generator, the development on JS/CC by Phorward Software Technologies has been abandoned within the last time, but some free developers extended it to the current development version 0.40.1. JS/CC is not a direct competitor of UniCC, and also provides different, interesting approaches and potentials, that had already been used by several projects from other developers.

The project is not maintained anymore by Phorward Software Technologies, but is continued by Andrew Brobston. Special thanks to him, and all other contributiors.

System Requirements

JS/CC itself has been entirely written in ECMAScript so it can be executed in many different ways: as platform-independent, browser-based JavaScript embedded on a Website, as a Windows Script Host Application, as a compiled JScript.NET executable, as a Mozilla/Rhino or Mozilla/Spidermonkey interpreted application, as a V8 shell script on Windows®, Linux® and other systems, or as server based NodeJS hosted web-application. However, for productive execution, it is recommended to use the command-line versions. These versions are capable of assembling a complete compiler from a JS/CC parser specification, which is then stored to a .js JavaScript source file.

Example

A simple four-function expression calculator is defined with the following few lines of augmented grammar definition to be fed to JS/CC.

              
/~  Expression calculator written in JS/CC ~/

/~  Tokens to be ignored (e.g. whitespace, comments) ~/
!   ' |\t'
    ;

/~  Grammar tokens            ~/
    '\+'
    '\-'
    '\*'
    '/'
    '\('
    '\)'
    '[0-9]+'      INT  [* %match = parseInt( %match );  *]
    '[0-9]+\.[0-9]*|[0-9]*\.[0-9]+'  FLOAT [* %match = parseFloat( %match ); *]
    ;
##

/~     The non-terminal "program" is the entry symbol, because it is the
first one! ~/

program
: expr [* print( %1 ); *] ; /~ Don't confuse with the tokens: Here, we use the unescaped values because these are not interpreted as regular expressions at this
position! ~/
expr: expr '+' term [* %% = %1 + %3; *] | expr '-' term [* %% = %1 - %3; *] | term /~ Default semantic action fits here! ~/ ; term: term '*' factor [* %% = %1 * %3; *] | term '/' factor [* %% = %1 / %3; *] | factor /~ Default semantic action fits here! ~/ ; factor: '(' expr ')' [* %% = %2; *] | INT /~ Default semantic action fits here! ~/ | FLOAT /~ Default semantic action fits here! ~/ ; /~ This is the parser entry point; Because this entry point could be
very individual, the compiler programmer has to decide which way he
wants to read the source, parse it and report the errors, if there
are any. ~/
[* var error_offsets = new Array(); var error_lookaheads = new Array(); var error_count = 0; var str = new String( arguments[0] ); if( ( error_count = __parse( str, error_offsets, error_lookaheads ) ) > 0 ) { for( i = 0; i < error_count; i++ ) print( "Parse error near \"" + str.substr( error_offsets[i] ) + "\", expecting \"" + error_lookaheads[i].join() + "\"" ); } *]

Projects

JS/CC has already been used in the following projects.