/// <summary> /// Initializes a new instance of the ParseState class. /// </summary> /// <param name="concrete">The concrete used to parse.</param> public ParseState(Concrete concrete) { this.concrete = concrete; this.startCat = concrete.GetStartCat(); this.items = new Trie(); this.chart = new Chart(concrete); ConcreteCategory tempcat = concrete.GetStartCat(); for (int fid = tempcat.FirstFID; fid <= tempcat.LastFID; fid++) { var prods = this.chart.ExpandForest(fid); foreach (ProductionApply k in prods) { k.Function.FixSymbols(); int lbl = 0; foreach (Symbol[] sym in k.Function.Sequences) { var activeItem = new ActiveItem(0, 0, k.Function, sym.ToList<Symbol>(), k.Domain().ToList<int>(), fid, lbl); this.items.Value.Add(activeItem); lbl++; } } } this.items.InsertChain(new List<string>(), this.items); }
/// <summary> /// Initializes a new instance of the Chart class. /// </summary> /// <param name="concrete">The concrete grammar we want to use.</param> public Chart(Concrete concrete) { this.active = new Dictionary<int, Dictionary<int, List<ActiveItem>>>(); this.actives = new List<Dictionary<int, Dictionary<int, List<ActiveItem>>>>(); this.passive = new Dictionary<string, int>(); this.Forest = new Dictionary<int, List<Production>>(); this.NextId = concrete.FId; // TODO fix so that it uses totalFID instead this.Offset = 0; // TODO check if we need to copy or not (copy now to be safe) foreach (KeyValuePair<int, List<Production>> entry in concrete.Productions) { var temp = new List<Production>(); foreach (Production p in entry.Value) { temp.Add(p); } this.Forest.Add(entry.Key, temp); } }