public void fchar_Vn(Production p) { char key = p.Left; char fchar = p.Right[0]; foreach (char c in FirstSets[fchar]) { if (c != Empty) { Changed |= FirstSets[key].Add(c); } } int i; for (i = 0; i < p.Right.Length; ++i) { char ch = p.Right[i]; if (cfg.isVn(ch) && FirstSets[fchar].Contains(Empty)) { foreach (char c in FirstSets[ch]) { if (c != Empty) { Changed |= FirstSets[key].Add(c); } } } else { break; } } if (i == p.Right.Length) { Changed |= FirstSets[key].Add(Empty); } }
public Item(Production p, int i, Char s) { Production = p; Index = i; if (p.Right == System.Configuration.ConfigurationManager.AppSettings["Empty"][0].ToString()) { Production.Right = ""; Index = 0; } Symbol = s; }
public void AnalyseProduction(Production p) { char key = p.Left; char fchar = p.Right[0]; if (cfg.isVn(fchar)) { fchar_Vn(p); } else { Changed |= FirstSets[key].Add(fchar); } }
public void Build(string[] Input) { try { Start = Input[0][0]; foreach (string s in Input) { if (s == string.Empty) { continue; } string[] tp = s.Split(new String[] { "→" }, StringSplitOptions.None); if (tp.Length != 2) { throw new Exception("产生式应该有且仅有一个→"); } if (tp[0].Length != 1 || !isVn(tp[0][0])) { throw new Exception("产生式左边应该是一个非终结符"); } char left = tp[0][0]; char empty= System.Configuration.ConfigurationManager.AppSettings["Empty"][0]; Vn.Add(left); string[] right = tp[1].Split('|'); for (int i = 0; i < right.Count(); ++i) { string part = right[i]; foreach (char c in part) { if (isVn(c)) { Vn.Add(c); } else { Vt.Add(c); } } Production p = new Production(left,part); if (!ProductionsMap.ContainsKey(p)) { Productions.Add(p); ProductionsMap.Add(p, ProductionsMap.Count() + 1); _ProductionsMap.Add(_ProductionsMap.Count() + 1, p); } } } } catch (Exception ) { throw new Exception("输入不合法\n"); } }