@fauton/cfg
Version:
A package to work with context free grammars and LL1 parsers
23 lines (22 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeEmptyProduction = void 0;
const populateCfg_1 = require("./utils/populateCfg");
const removeProductionRules_1 = require("./utils/removeProductionRules");
/**
* Removes productions that has no rules and updates rules to remove those rules that references empty production variables
* @param cfg Variables array and production rules record of cfg
* @returns New production rules and variables without empty rule variables
*/
function removeEmptyProduction(inputCfg) {
const cfg = (0, populateCfg_1.populateCfg)(inputCfg);
const { productionRules, variables } = cfg;
// Filtering all the variables which dont have any production rules
const emptyProductionVariables = variables.filter((variable) => productionRules[variable].length === 0);
return (0, removeProductionRules_1.removeProductionRules)({
productionRules,
removedVariables: emptyProductionVariables,
variables,
});
}
exports.removeEmptyProduction = removeEmptyProduction;