public static void Test() { Word2Unit w = new Word2Unit(@"1.txt"); foreach (string i in w.Result()) { Console.WriteLine(UnitRegex(i)); } }
static void Main(string[] args) { Stack <int> status = new Stack <int>(); string arch = ""; Processer pr = new Processer(); List <string> standby = new Word2Unit(@"1.txt").Result(); standby.Add("$"); status.Push(0); for (int i = 0; i < standby.Count; i++) { standby[i] = UnitRegex(standby[i]); } Console.WriteLine("栈\t当前\t操作说明\t待移入"); while (pr.Action[status.Peek()][standby[0]].num != -1) { ActionResponse ac = pr.Action[status.Peek()][standby[0]]; bool Return = ac.Return; //移入// if (!Return) { status.Push(ac.num); string ts = standby[0]; if (standby[0] != "$") { arch = arch + standby[0]; standby.RemoveAt(0); } Console.WriteLine($"{OutStack(status)}\t{arch}\t移入{ts}进入{ac.num.ToString()}状态\t{OutList(standby)}"); } else//规约// { string g = Grammar(ac.num, arch)[1]; int popNum = int.Parse(Grammar(ac.num, arch)[2]); arch = Grammar(ac.num, arch)[0]; for (int i = 0; i < popNum; i++) { status.Pop(); } //Goto// status.Push(pr.Goto[status.Peek()][g]); Console.WriteLine($"{OutStack(status)}\t{arch}\t规约回退为{status.Peek()}状态\t{OutList(standby)}"); } } }