public Analysis(string[] Input) { CFG = new cfg(Input); FirstSetBuilder first = new FirstSetBuilder(CFG); this.FirstSets = first.FirstSets; this.Va = new Dictionary<int, char>() { }; this.Vg = new Dictionary<int, char>() { }; char empty = System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; char end = System.Configuration.ConfigurationManager.AppSettings["End"][0]; int k = 0; for (int i = 0; i < CFG.Vt.Count; ++i) { char c = CFG.Vt.ElementAt(i); if (c != empty) { Va.Add(k++, c); } } Va.Add(k++, end); for (int i = 0; i < CFG.Vn.Count; ++i) { char c = CFG.Vn.ElementAt(i); Vg.Add(i, c); } TableBuilder tableBuilder = new TableBuilder(CFG, FirstSets); this.Table = tableBuilder.Table; this.ItemSetMap = tableBuilder.ItemSetMap; this._ItemSetMap = tableBuilder._ItemSetMap; }
public FirstSetBuilder(cfg cfg) { FirstSets = new FirstSet(); this.cfg = cfg; Empty=System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; foreach (char c in cfg.Vn) { FirstSets.Add(c, new HashSet<char>()); } Build(); }
public static void Closure(this ItemSet itemset, cfg cfg, FirstSet first) { HashSet <Production> productions = cfg.Productions; bool changed; do { changed = false; char end = System.Configuration.ConfigurationManager.AppSettings["End"][0]; for (int i = 0; i < itemset.Count; ++i) { Item item = itemset.ElementAt(i); int index = item.Index; string right = item.Production.Right; if (index >= right.Length || !cfg.isVn(right[index])) { continue; } foreach (Production production in productions) { if (production.Left != right[index]) { continue; } int length = right.Length; if (index + 1 == right.Length) { Item newItem = new Item(production, 0, item.Symbol); changed |= itemset.AddItem(newItem); continue; } if (index + 1 < right.Length) { char empty = System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; HashSet <char> symbols = first.GetFirst(right[index + 1]); foreach (char c in symbols) { if (c == empty) { Item newItem = new Item(production, 0, item.Symbol); changed |= itemset.Add(newItem); } else { Item newItem = new Item(production, 0, c); changed |= itemset.Add(newItem); } } } } } } while (changed); }
public FirstSetBuilder(cfg cfg) { FirstSets = new FirstSet(); this.cfg = cfg; Empty = System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; foreach (char c in cfg.Vn) { FirstSets.Add(c, new HashSet <char>()); } Build(); }
public static void Closure( this ItemSet itemset,cfg cfg, FirstSet first) { HashSet<Production> productions = cfg.Productions; bool changed; do { changed = false; char end = System.Configuration.ConfigurationManager.AppSettings["End"][0]; for (int i = 0; i < itemset.Count; ++i) { Item item = itemset.ElementAt(i); int index = item.Index; string right = item.Production.Right; if (index >= right.Length || !cfg.isVn(right[index])) { continue; } foreach (Production production in productions) { if (production.Left != right[index]) { continue; } int length = right.Length; if (index + 1 == right.Length) { Item newItem = new Item(production, 0,item.Symbol); changed |= itemset.AddItem(newItem); continue; } if (index + 1 < right.Length) { char empty = System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; HashSet<char> symbols = first.GetFirst(right[index + 1]); foreach (char c in symbols) { if (c == empty) { Item newItem = new Item(production, 0, item.Symbol); changed |= itemset.Add(newItem); } else { Item newItem = new Item(production, 0, c); changed |= itemset.Add(newItem); } } } } } } while (changed); }
public Analysis(string[] Input) { CFG = new cfg(Input); FirstSetBuilder first = new FirstSetBuilder(CFG); this.FirstSets = first.FirstSets; this.Va = new Dictionary <int, char>() { }; this.Vg = new Dictionary <int, char>() { }; char empty = System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; char end = System.Configuration.ConfigurationManager.AppSettings["End"][0]; int k = 0; for (int i = 0; i < CFG.Vt.Count; ++i) { char c = CFG.Vt.ElementAt(i); if (c != empty) { Va.Add(k++, c); } } Va.Add(k++, end); for (int i = 0; i < CFG.Vn.Count; ++i) { char c = CFG.Vn.ElementAt(i); Vg.Add(i, c); } TableBuilder tableBuilder = new TableBuilder(CFG, FirstSets); this.Table = tableBuilder.Table; this.ItemSetMap = tableBuilder.ItemSetMap; this._ItemSetMap = tableBuilder._ItemSetMap; }
public TableBuilder(cfg cfg, FirstSet first) { this.CFG = cfg; this.First = first; Build(); }