use crate::{Cfg, Pr, Symbol, SymbolAttribute, generate_name};
pub fn augment_grammar(cfg: &Cfg) -> Cfg {
let start_symbol_production_count = cfg.matching_productions(&cfg.st).len();
if start_symbol_production_count == 1 {
return cfg.clone();
}
let mut new_cfg = cfg.clone();
let new_start = generate_name(cfg.get_non_terminal_set().iter(), cfg.st.clone());
new_cfg.st.clone_from(&new_start);
new_cfg.pr.insert(
0,
Pr::new(
&new_start,
vec![Symbol::N(cfg.st.clone(), SymbolAttribute::None, None, None)],
),
);
new_cfg
}