{"id":17723,"library":"jison","title":"Jison Parser Generator","description":"Jison is a JavaScript parser generator that creates bottom-up parsers from user-defined grammars. It supports grammars defined in either a JSON format or a Bison-style syntax, outputting a standalone JavaScript file capable of parsing the specified language. The API is intentionally designed to be similar to Bison's, making it approachable for developers familiar with traditional parser generators like Yacc or Bison. As of its latest release, 0.4.18, published in 2014, the project appears to be largely unmaintained. It generates parsers that can be used as command-line tools or programmatically within a CommonJS environment. Its primary differentiator is providing a Bison-like grammar definition and parser generation workflow targeting JavaScript.","status":"abandoned","version":"0.4.18","language":"javascript","source_language":"en","source_url":"git://github.com/zaach/jison","tags":["javascript","jison","bison","yacc","parser","generator","lexer","flex","tokenizer"],"install":[{"cmd":"npm install jison","lang":"bash","label":"npm"},{"cmd":"yarn add jison","lang":"bash","label":"yarn"},{"cmd":"pnpm add jison","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Jison 0.4.18 is a CommonJS module and does not support ES module `import` syntax. Attempting to use `import` will result in a runtime error.","wrong":"import { Parser } from 'jison';","symbol":"Parser","correct":"const Parser = require('jison').Parser;"},{"note":"The `jison` executable is typically installed globally via `npm install -g jison` and run directly from the command line. It's not intended to be executed directly with `node`.","wrong":"node jison mygrammar.jison","symbol":"jison CLI","correct":"jison mygrammar.jison"},{"note":"This imports the entire Jison module object, which contains the `Parser` class and other internal utilities. Primarily used for programmatic generation.","wrong":"import jison from 'jison';","symbol":"Whole module","correct":"const jison = require('jison');"}],"quickstart":{"code":"const Parser = require(\"jison\").Parser;\n\n// A basic calculator grammar in JSON format\nconst grammar = {\n    \"lex\": {\n        \"rules\": [\n           [\"\\s+\", \"/* skip whitespace */\"],\n           [\"([0-9]+(\\.[0-9]+)?)\\b\", \"return 'NUMBER';\"],\n           [\"\\*\", \"return '*';\"],\n           [\"/\", \"return '/';\"],\n           [\"-\", \"return '-';\"],\n           [\"\\+\", \"return '+';\"],\n           [\"\\^\", \"return '^';\"],\n           [\"\\(\", \"return '(';\"],\n           [\"\\)\", \"return ')';\"],\n           [\"$$\", \"return 'EOF';\"]\n        ]\n    },\n\n    \"bnf\": {\n        \"expressions\" :[\n            [\"e EOF\", \"return $1;\" ]\n        ],\n        \"e\" :[\n            [\"e + e\", \"$$ = $1 + $3;\"],\n            [\"e - e\", \"$$ = $1 - $3;\"],\n            [\"e * e\", \"$$ = $1 * $3;\"],\n            [\"e / e\", \"$$ = $1 / $3;\"],\n            [\"e ^ e\", \"$$ = Math.pow($1, $3);\"],\n            [\"-\n            \", \"$$ = -$2;\"],\n            [\"(\n            )\", \"$$ = $2;\"],\n            [\"NUMBER\", \"$$ = Number($1);\"]\n        ]\n    }\n};\n\nconst parser = new Parser(grammar);\n\n// Parse a simple arithmetic expression\nconst result = parser.parse(\"2 + 3 * (4 - 1)\");\nconsole.log(`Parsed result: ${result}`); // Expected: 11\n\ntry {\n    parser.parse(\"2 + 3 $ 5\"); // Should throw a lexical error\n} catch (e) {\n    console.error(`Error parsing invalid input: ${e.message}`);\n}\n\n// Demonstrate generation (optional, usually written to file)\nconst parserSource = parser.generate();\n// console.log(parserSource.substring(0, 200) + '...'); // Output first 200 chars of generated parser source","lang":"javascript","description":"This quickstart demonstrates how to programmatically define a grammar, instantiate a Jison parser, and use it to parse an arithmetic expression, including error handling."},"warnings":[{"fix":"Consider alternative, actively maintained parser generator libraries for JavaScript (e.g., Nearley, PEG.js) for new development. For existing projects, thoroughly test compatibility and consider vendoring a patched version.","message":"Jison version 0.4.18 was released in 2014 and is no longer actively maintained. It may have compatibility issues with modern Node.js versions, security vulnerabilities, or unaddressed bugs. Use with caution in new projects.","severity":"breaking","affected_versions":">=0.4.18"},{"fix":"Always use `const Parser = require('jison').Parser;` syntax. If your project is pure ESM, you may need to use a wrapper or a dynamic `import()` call if `jison` is the only CJS dependency.","message":"Jison is a CommonJS-only package. It cannot be imported directly using ES module `import` syntax in modern JavaScript environments. Attempting to do so will result in `ReferenceError: require is not defined` or similar import errors.","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"Familiarize yourself with the concepts of parser generators and context-free grammars. Refer to the official Jison documentation or the Bison manual for fundamental understanding before writing complex grammars.","message":"The documentation and examples primarily use Bison-style or JSON-encoded grammars. While powerful, understanding context-free grammars and LALR/SLR parsing algorithms is essential for effective use and debugging of Jison-generated parsers.","severity":"gotcha","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure your file is treated as CommonJS (e.g., `.js` file without `\"type\": \"module\"` in `package.json`, or specifically use a CJS environment). If you must use Jison in an ESM context, consider a dynamic import: `const { Parser } = await import('jison');`.","cause":"Attempting to use `require()` in an ES Module context or using `import` for a CommonJS-only package.","error":"ReferenceError: require is not defined"},{"fix":"Install jison globally: `npm install -g jison`. If already installed, ensure your `PATH` environment variable includes the npm global bin directory.","cause":"The `jison` command-line interface (CLI) is not installed globally or is not in your system's PATH.","error":"jison: command not found"},{"fix":"Review your input string against the grammar rules. If the input is valid according to your intent, debug your grammar definition for ambiguities, missing rules, or incorrect token definitions. Use Jison's debug mode (`jison -t`) for more detailed parser output.","cause":"The input string does not conform to the grammar defined for the parser, or there's an ambiguity/error in the grammar itself.","error":"Error: Parse error on line X: [...] Unexpected 'TOKEN'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}