private string Trans2Syn(string s) { JudgeChar jc = new JudgeChar(); Stack<char> ts = new Stack<char> { }; for (int i = 0; i < s.Length; ++i) { if (jc.isDigit(s[i])) { if (ts.Count == 0 || ts.Peek() != 'i') { ts.Push('i'); } } else { ts.Push(s[i]); } } string tmp = ""; for (int i = ts.Count - 1; i >= 0;--i ) { tmp += ts.ElementAt(i); } return tmp; }
public bool SynAna(string buf) { int count2 = 0; //循环扫描所有算术表达式 while (count2 < buf.Length) { while (buf[count2] != '=' && count2 < buf.Length) { count2++; if (count2 == buf.Length) break; } if (count2 == buf.Length) break; JudgeChar jc = new JudgeChar(); if (jc.isAlphabet(buf[count2 - 1])) { count2++; string part = ""; //判断是算术表达式 while ((buf[count2] >= '0' && buf[count2] <= '9') || this.IsOpt(buf[count2])) { part += buf[count2]; count2++; } if (part != "") { //加入数组中 parts.Add(part); continue; } else continue; } else count2++; } try { for (int i = 0; i < parts.Count; ++i) { //对第i个串分析 Analyse(parts[i]); } return true; } catch { return false; } }