node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org ยป



NodeBNF is a script language parsing library. Programmed in JavaScript and tested with nodeJS. It was made to work with another project as a dependency for sub language processing in node.


NodeBNF is both a framework for an interpreter, , BNF compiler, and a language parser. It can use BNF or a custom JavaScript mark-up which was molded after BNF.

Working Parts

  • BNF compiler: Optionally taking raw BNF and turning it into a cached JavaScript file used by the language parser.
  • Language parser: Using a custom JavaScript mark-up, the language parser converts scripts into a pre-interpreted collection of tokens, while at the same time checking for syntax correctness.
  • Interpreter framework: Every interpreter wants to be different, and should be, as no language compiles or understands tokens in the same way. The framework binds actions to the tokens, and then calls the actions, which is a basic parsing style. The framework try's to speed this process up by putting the tokens in a tree shaped data pool.

Road Map

  • I personally like normal BNF, but I know ABNF offers some great advantages to writing a scripting language, so ABNF is going to be supported.
  • Parsing text will be able to be done with regular expressions.
  • The OR operation should set the syntax into groups so as only process each syntax layer only once.

Example of Use


npm install bnf

Basic setup and usage:

var Compiler = requre( "bnf" );
var scriptText = "rule";
var events = { "rule":function( token ){ console.log( "found rule" ); } };
var parser = null;
var script = null;
var compiler = new Compiler( );
compiler.CompileScript( "./languagefile.bnf", "cacheid", function( interpreter ){
    parser = compiler.CreateParser( interpreter, events );
    script = parser.ParseScriptString(scriptText);
} );

Multiple scripting language in one script:

parser = compiler.CreateParser( interpreter, events );
parser.IncludeLanguage( anotherParser );

<syntax> ::= <myscript> #otherScript | <myscript>

See examples:



Copyright (c) 2011 by Steven Adams.