A parser generator with Bison's API for creating bottom-up parsers from grammar definitions
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Internal system for processing and analyzing grammar definitions including production rules, nonterminals, and operator precedence. These APIs are primarily used internally by Jison but may be useful for advanced grammar analysis.
Core method for processing raw grammar definitions into internal representation.
/**
* Process a grammar definition into internal representation
* @param grammar - Raw grammar object containing lex, bnf/ebnf, operators, etc.
*/
processGrammar(grammar);This method:
Usage Examples:
const generator = new jison.Generator(grammar);
// processGrammar is called internally during construction
// Access processed components
console.log(generator.nonterminals); // Nonterminal objects
console.log(generator.productions); // Production rule array
console.log(generator.symbols); // All grammar symbolsBuilds production rules from BNF grammar definitions with semantic actions.
/**
* Build production rules from BNF grammar
* @param bnf - BNF grammar object with nonterminal -> productions mapping
* @param productions - Production array to populate
* @param nonterminals - Nonterminal symbol objects
* @param symbols - All grammar symbols array
* @param operators - Operator precedence rules
*/
buildProductions(bnf, productions, nonterminals, symbols, operators);This method processes:
$variable)Adds the accept production and required symbols to complete the grammar.
/**
* Augment grammar with accept production and required symbols
* @param grammar - Original grammar definition
*/
augmentGrammar(grammar);This method:
$accept production as grammar start$end (EOF) terminal symbolRepresents individual production rules in the grammar.
/**
* Production rule constructor
* @param symbol - Left-hand side nonterminal
* @param handle - Right-hand side symbol array
* @param id - Unique production identifier
*/
function Production(symbol, handle, id);
/**
* Production instance properties and methods
*/
class Production {
symbol: string; // Left-hand side nonterminal
handle: string[]; // Right-hand side symbols
id: number; // Production identifier
nullable: boolean; // Whether production can derive epsilon
first: string[]; // First set for this production
precedence: number; // Operator precedence level
/**
* Convert production to string representation
* @returns String in "A -> B C D" format
*/
toString(): string;
}Usage Examples:
// Productions are created internally during grammar processing
const generator = new jison.Generator(grammar);
generator.productions.forEach(production => {
console.log(`${production.symbol} -> ${production.handle.join(' ')}`);
console.log(`Precedence: ${production.precedence}`);
console.log(`Nullable: ${production.nullable}`);
});Represents nonterminal symbols with their associated productions and computed sets.
/**
* Nonterminal symbol constructor
* @param symbol - Symbol name
*/
function Nonterminal(symbol);
/**
* Nonterminal instance properties and methods
*/
class Nonterminal {
symbol: string; // Symbol name
productions: Set; // Associated production rules
first: string[]; // First set
follows: string[]; // Follow set
nullable: boolean; // Whether symbol can derive epsilon
/**
* Convert nonterminal to string with debug information
* @returns Detailed string representation
*/
toString(): string;
}Usage Examples:
const generator = new jison.Generator(grammar);
// Access nonterminal information
for (const symbolName in generator.nonterminals) {
const nt = generator.nonterminals[symbolName];
console.log(`Symbol: ${nt.symbol}`);
console.log(`Nullable: ${nt.nullable}`);
console.log(`First: [${nt.first.join(', ')}]`);
console.log(`Follow: [${nt.follows.join(', ')}]`);
console.log(`Productions: ${nt.productions.size()}`);
}Methods for computing First, Follow, and Nullable sets used in parsing algorithms.
Compute First sets for symbols and symbol sequences.
/**
* Compute First sets for all productions and nonterminals
*/
firstSets();
/**
* Get First set for a symbol or sequence of symbols
* @param symbol - Single symbol (string) or array of symbols
* @returns Array of terminal symbols that can begin derivations
*/
first(symbol);Compute Follow sets for nonterminal symbols.
/**
* Compute Follow sets for all nonterminals
*/
followSets();Determine which symbols and productions can derive the empty string.
/**
* Compute nullable properties for all symbols and productions
*/
nullableSets();
/**
* Check if a symbol or sequence can derive epsilon
* @param symbol - Single symbol (string) or array of symbols
* @returns True if symbol/sequence is nullable
*/
nullable(symbol);Usage Examples:
const generator = new jison.Generator(grammar);
// Lookahead sets are computed automatically for LR/LL generators
// Manual computation (if extending generators)
generator.computeLookaheads();
// Check specific symbols
const firstOfE = generator.first('e');
const isENullable = generator.nullable('e');
const firstOfSequence = generator.first(['e', '+', 'e']);Process operator precedence and associativity declarations.
/**
* Process operator precedence declarations
* @param ops - Array of operator declarations
* @returns Object mapping operators to precedence/associativity
*/
function processOperators(ops);Operator declarations format:
const operators = [
['left', '+', '-'], // Left associative, precedence 1
['left', '*', '/'], // Left associative, precedence 2
['right', '^'], // Right associative, precedence 3
['nonassoc', '==', '!='] // Non-associative, precedence 4
];Enable detailed processing information during grammar analysis.
/**
* Output trace information (no-op unless debug mode enabled)
* @param ...args - Arguments to trace
*/
trace(...args);
/**
* Output warning messages
* @param ...args - Warning message components
*/
warn(...args);
/**
* Throw formatted error
* @param msg - Error message
* @throws Error with formatted message
*/
error(msg);Usage Examples:
// Enable debug mode during construction
const generator = new jison.Generator(grammar, { debug: true });
// Debug output will show:
// - Grammar processing steps
// - Symbol table construction
// - First/Follow set computation
// - Conflict resolution detailsGrammar processing can fail with various error conditions:
try {
const parser = new jison.Parser(grammar);
} catch (error) {
if (error.message.includes('Grammar error')) {
// Handle grammar-specific errors
console.error('Grammar processing failed:', error.message);
}
}