• Stars
    star
    4,338
  • Rank 9,915 (Top 0.2 %)
  • Language
    JavaScript
  • Created almost 15 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bison in JavaScript.

Jison

build status

An API for creating parsers in JavaScript

Jison generates bottom-up parsers in JavaScript. Its API is similar to Bison's, hence the name. It supports many of Bison's major features, plus some of its own. If you are new to parser generators such as Bison, and Context-free Grammars in general, a good introduction is found in the Bison manual. If you already know Bison, Jison should be easy to pickup.

Briefly, Jison takes a JSON encoded grammar or Bison style grammar and outputs a JavaScript file capable of parsing the language described by that grammar. You can then use the generated script to parse inputs and accept, reject, or perform actions based on the input.

Installation

Jison can be installed for Node using npm

Using npm:

npm install jison -g

Usage from the command line

Clone the github repository for examples:

git clone git://github.com/zaach/jison.git
cd jison/examples

Now you're ready to generate some parsers:

jison calculator.jison

This will generate calculator.js in your current working directory. This file can be used to parse an input file, like so:

echo "2^32 / 1024" > testcalc
node calculator.js testcalc

This will print out 4194304.

Full cli option list:

Usage: jison [file] [lexfile] [options]

file        file containing a grammar
lexfile     file containing a lexical grammar

Options:
   -j, --json                    force jison to expect a grammar in JSON format
   -o FILE, --outfile FILE       Filename and base module name of the generated parser
   -t, --debug                   Debug mode
   -m TYPE, --module-type TYPE   The type of module to generate (commonjs, amd, js)
   -p TYPE, --parser-type TYPE   The type of algorithm to use for the parser (lr0, slr, lalr, lr)
   -V, --version                 print version and exit

Usage from a CommonJS module

You can generate parsers programatically from JavaScript as well. Assuming Jison is in your commonjs environment's load path:

// mygenerator.js
var Parser = require("jison").Parser;

// a grammar in JSON
var grammar = {
    "lex": {
        "rules": [
           ["\\s+", "/* skip whitespace */"],
           ["[a-f0-9]+", "return 'HEX';"]
        ]
    },

    "bnf": {
        "hex_strings" :[ "hex_strings HEX",
                         "HEX" ]
    }
};

// `grammar` can also be a string that uses jison's grammar format
var parser = new Parser(grammar);

// generate source, ready to be written to disk
var parserSource = parser.generate();

// you can also use the parser directly from memory

// returns true
parser.parse("adfe34bc e82a");

// throws lexical error
parser.parse("adfe34bc zxg");

More Documentation

For more information on creating grammars and using the generated parsers, read the documentation.

How to contribute

See CONTRIBUTING.md for contribution guidelines, how to run the tests, etc.

Projects using Jison

View them on the wiki, or add your own.

Contributors

Githubbers

Special thanks to Jarred Ligatti, Manuel E. Bermúdez

License

Copyright (c) 2009-2014 Zachary Carter

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

jsonlint

A JSON parser and validator with a CLI.
JavaScript
1,923
star
2

orderly.js

An Orderly compiler in JavaScript
JavaScript
118
star
3

reflect.js

Implementation of Mozilla's Parser API in JavaScript
JavaScript
110
star
4

jsxgettext

Extract gettext calls from JavaScript, EJS, and other template formats.
JavaScript
105
star
5

ebnf-parser

A parser for BNF and EBNF grammars used by jison
JavaScript
80
star
6

jison-lex

generates lexical analyzers. used by jison.
JavaScript
57
star
7

selfie

Take webcam selfies with node.js.
JavaScript
42
star
8

node-fx-sync

Node.js client for Firefox Sync
JavaScript
28
star
9

npm-seal

Verify that packages installed during development match those installed in production
JavaScript
26
star
10

lex-parser

A parser for lexical grammars used by jison.
JavaScript
25
star
11

zii-jsconf2010-talk

Slides and code from my track B talk "Build Your Own Programming Language with JavaScript"
JavaScript
25
star
12

lambdacalc

A simple example of an interpreter in JS. Evaluates lambda calculus expressions.
JavaScript
15
star
13

ukanren.js

µKanren in JavaScript
JavaScript
13
star
14

cafe

Brewing up some JavaScript. (DEPRECATED: use/fork reflect.js)
JavaScript
13
star
15

webrates

#owfa project
CSS
11
star
16

jsonic

A homoiconic language based on LISP 1.5/SICP Scheme interpreters. The syntax is JSON.
JavaScript
10
star
17

dabblescript

Dabble with JavaScript syntax
JavaScript
7
star
18

jison2json

grammar.y -> grammar.json
JavaScript
6
star
19

5edm

end-to-end encrypted messaging on deno
TypeScript
6
star
20

node-webcam-capture

Capture frames from your webcam.
Objective-C
6
star
21

sml-hw

Homework for my Programming Languages class, Fall '08
6
star
22

codetch-ext

Codetch, a code editing extension to Firefox, Flock, etc.
JavaScript
6
star
23

webgl-dump

how does webgl
JavaScript
5
star
24

node-simplepush

JavaScript
5
star
25

dotvim

My vim configuration
Vim Script
4
star
26

jsxgettext-recursive

Recursively extract strings for localization.
JavaScript
4
star
27

json2jison

converts JSON grammars into jison's text format
JavaScript
3
star
28

reflect-unbuilder

An AST-to-source-code serializer for reflect.js
JavaScript
3
star
29

execbin

Execute commands and binary files on Android
3
star
30

narwhal-xpcshell

Run narwhal through xpcshell/xulrunner engine
JavaScript
2
star
31

mixinjs

An attempt at multiple inheritance in JavaScript
JavaScript
2
star
32

ml-coursera-hw

andrew ng machine learning coursera course homework
MATLAB
2
star
33

simplepush-browser-client

rough thing for testing. nothing to see here.
JavaScript
2
star
34

bigint-browserify

bigint-browserify
JavaScript
2
star
35

the-status-quo

the status quo
2
star
36

floop.js

An example FlooP to JavaScript/asm.js compiler
JavaScript
2
star
37

reflect-tree-builder

A more tree-like AST builder for reflect.js
JavaScript
2
star
38

typal

Makes prototypal/classical patterns in JavaScript easier. Plus some AOP sugar.
2
star
39

zaach.github.com

where the heart is
HTML
2
star
40

slingshot

Project generator
Python
1
star
41

reflect-builder

Default AST builder for reflect.js
JavaScript
1
star
42

zaach

1
star
43

5edm-eliza

TypeScript
1
star
44

sjcl-codec-bytes

workaround for the missing bytes codec in sjcl builds
JavaScript
1
star