public ComplexMachine(RegExpTree tree) { tree.Positions = new Dictionary<String, List<RegExpTreeItem>>(); Machines = new Dictionary<string, Machine>(); int currentState = 0; foreach (String name in tree.Roots.Keys) { if (!allowed.Contains(name)) continue; tree.Positions.Add(name, new List<RegExpTreeItem>()); tree.Roots[name].Calculate(tree.Positions[name]); tree.Roots[name].CalculateFollow(tree.Positions[name]); Machine machine = new Machine(tree.Positions[name]); machine.STATE = currentState; machine.TryAdd(tree.Positions[name][tree.Positions[name].Count - 1].FirstPos); while (machine.HasUnmarked()) machine.GetUnmarked().MoveForward(); Machines.Add(name, machine); currentState = machine.STATE; } }
public static Object SetLexic(String text) { RegExpTree tree = new RegExpTree(); tree.Roots = new Dictionary<string, RegExpTreeItem>(); ComplexMachine machine = new ComplexMachine(tree); try { foreach (string line in text.Split('\n').Select(l => l.Trim() + "#")) { if (string.IsNullOrEmpty(line)) continue; int i = 0; while (line[i] != '=' && i < line.Length - 1) i++; if (line[i] != '=') continue; String name = line.Substring(0, i); String val = line.Substring(i + 1, line.Length - i - 1); tree.Roots[name] = tree.Load(val); } machine = new ComplexMachine(tree); } catch (Exception e) { return null; } UserSession us = HttpContext.Current.Session["UserSession"] as UserSession; if (us == null) { us = new UserSession(); HttpContext.Current.Session.Add("UserSession", us); } us.Tree = tree; us.Machine = machine; string ret = String.Empty; foreach (var m in machine.Machines.Keys) ret = ret + "<br/>" + machine.Machines[m].ToTable(m); return ret; }