UNPKG

@fauton/cfg

Version:

A package to work with context free grammars and LL1 parsers

21 lines (20 loc) 980 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeUselessProduction = void 0; const removeNonTerminableProduction_1 = require("./removeNonTerminableProduction"); const removeUnreachableProduction_1 = require("./removeUnreachableProduction"); const populateCfg_1 = require("./utils/populateCfg"); /** * Reduces an input cfg by removing non terminable and non reachable variables * @param cfg Variables, start symbol and production rules of a cfg * @returns An array of terminable and reachable variables */ function removeUselessProduction(inputCfg) { const cfg = (0, populateCfg_1.populateCfg)(inputCfg); const terminableVariables = (0, removeNonTerminableProduction_1.removeNonTerminableProduction)(cfg); return (0, removeUnreachableProduction_1.removeUnreachableProduction)({ ...cfg, variables: terminableVariables, }); } exports.removeUselessProduction = removeUselessProduction;