@fauton/cfg
Version:
A package to work with context free grammars and LL1 parsers
28 lines (27 loc) • 919 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.populateCfg = void 0;
const extractTerminalsFromCfg_1 = require("../extractTerminalsFromCfg");
/**
* Populates the variables and terminals of cfg via extraction
* @param cfg Cfg to populate
* @returns Populated cfg
*/
function populateCfg(cfg) {
// TODO: Loop through all the production rules and extract variables from them
if (!cfg.variables) {
cfg.variables = Object.keys(cfg.productionRules);
}
if (!cfg.startVariable) {
// eslint-disable-next-line
cfg.startVariable = cfg.variables[0];
}
if (!cfg.terminals) {
cfg.terminals = (0, extractTerminalsFromCfg_1.extractTerminalsFromCfg)({
productionRules: cfg.productionRules,
variables: cfg.variables,
});
}
return cfg;
}
exports.populateCfg = populateCfg;