Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
Jison
https://github.com/zaach/jison
Admin
Bison in JavaScript.
Tokens:
738
Snippets:
11
Trust Score:
9.4
Update:
1 year ago
Context
Chat
Benchmark
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Installing Dependencies with npm (Shell) Source: https://github.com/zaach/jison/blob/master/CONTRIBUTING.md Before running tests or building the site, you need to install the project's dependencies using npm. This command should be run once after cloning the repository. ```Shell npm install ``` -------------------------------- ### Running Tests with Make (Shell) Source: https://github.com/zaach/jison/blob/master/CONTRIBUTING.md After installing dependencies, use this command to execute the project's test suite. Ensure Node.js and npm are installed prerequisites. ```Shell make test ``` -------------------------------- ### Previewing Site with Make (Shell) Source: https://github.com/zaach/jison/blob/master/CONTRIBUTING.md After building the site, use this command to preview it locally. This requires the 'adsf' gem to be installed. ```Shell make preview ``` -------------------------------- ### Navigating to Jison Examples Directory Source: https://github.com/zaach/jison/blob/master/README.md Changes the current directory to the `examples` subdirectory within the cloned Jison repository. This is typically done to access sample grammar files. ```shell cd jison/examples ``` -------------------------------- ### Installing Jison Globally via npm Source: https://github.com/zaach/jison/blob/master/README.md Installs the Jison command-line tool globally using the Node Package Manager (npm). This makes the `jison` command available in the system's PATH. ```shell npm install jison -g ``` -------------------------------- ### Building Site and Browser Version with Make (Shell) Source: https://github.com/zaach/jison/blob/master/CONTRIBUTING.md This command builds the project website and a Browserified version of Jison. It requires the 'nanoc' gem to be installed. ```Shell make site ``` -------------------------------- ### Cloning Jison Repository Source: https://github.com/zaach/jison/blob/master/README.md Clones the Jison project repository from GitHub to the local machine. This is useful for accessing examples or contributing. ```shell git clone git://github.com/zaach/jison.git ``` -------------------------------- ### Generating and Using Jison Parser Programmatically Source: https://github.com/zaach/jison/blob/master/README.md Demonstrates how to use the Jison API within a Node.js or CommonJS environment to define a grammar in JSON format, create a `Parser` instance, generate the parser source code, and directly parse input strings in memory. ```javascript // 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"); ``` -------------------------------- ### Creating Input File for Parser Source: https://github.com/zaach/jison/blob/master/README.md Creates a simple text file named `testcalc` containing an arithmetic expression. This file will be used as input for the generated parser. ```shell echo "2^32 / 1024" > testcalc ``` -------------------------------- ### Generating Parser from Grammar File Source: https://github.com/zaach/jison/blob/master/README.md Uses the Jison command-line tool to generate a JavaScript parser file (`calculator.js`) from a Jison grammar file (`calculator.jison`). ```shell jison calculator.jison ``` -------------------------------- ### Running Generated Parser on Input File Source: https://github.com/zaach/jison/blob/master/README.md Executes the generated JavaScript parser (`calculator.js`) using Node.js, providing the `testcalc` file as input. The parser will process the input and produce output based on its grammar rules. ```shell node calculator.js testcalc ```