/// <summary> /// </summary> static void Main() { //example 1 //String[] par={}; //CCMachine.run_console(par); //example 2 StreamReader rdr = new StreamReader("rule.in"); string rule_i = rdr.ReadToEnd(); rdr.Close(); string rule_o = CCMachine.run_cc(rule_i, Console.Out); Console.WriteLine(rule_o); SAL.cx.SampleVarMgr tvm = new SAL.cx.SampleVarMgr(); SAL.cx.CXMachine.run_cx(tvm, rule_o, Console.Out); Console.WriteLine("-------output--------"); foreach (DictionaryEntry entry in tvm.getHashtable()) { Console.WriteLine(entry.Key + " = " + entry.Value); } Console.WriteLine("---------------"); }
public static void run_stream(string s, StreamWriter _rrw, TextWriter _output) { CCMachine cc = new CCMachine(); cc.output = _output; cc.rw = _rrw; cc.KeySigns.Add('\t', 0); cc.KeySigns.Add('\n', 0); cc.KeySigns.Add('\r', 0); cc.KeySigns.Add(';', -1); cc.KeySigns.Add(' ', 0); cc.KeySigns.Add('=', 1); cc.KeySigns.Add('(', 6); cc.KeySigns.Add(')', 6); cc.KeySigns.Add('*', 4); cc.KeySigns.Add('/', 5); cc.KeySigns.Add('+', 3); cc.KeySigns.Add('-', 3); cc.KeySigns.Add('?', 2); cc.KeySigns.Add(':', 2); cc.KeySigns.Add(',', 2); int beginIndex = 0; //詞的起始位置 int endIndex = 0; //詞的結束位置 List <string> exprLine = new List <string>(); for (int i = 0; i < s.Length; i++) { if (cc.KeySigns.Contains(s[i])) { if (beginIndex < endIndex) { exprLine.Add(s.Substring(beginIndex, endIndex - beginIndex)); } switch ((int)cc.KeySigns[s[i]]) { case -1: cc.proc1opt(exprLine); cc.printList(exprLine); TreeItem f = cc.proc2opt(exprLine, null); cc.travTree(f); exprLine.Clear(); cc.rw.WriteLine(); cc.output.WriteLine(); cc.lineDataCnt = 0; break; case 0: break; case 1: exprLine.Add(s[i].ToString()); break; case 2: exprLine.Add(s[i].ToString()); break; case 3: exprLine.Add(s[i].ToString()); break; case 4: exprLine.Add(s[i].ToString()); break; case 5: exprLine.Add(s[i].ToString()); break; case 6: exprLine.Add(s[i].ToString()); break; } beginIndex = i + 1; endIndex = i + 1; } else { endIndex++; } } cc.rw.Flush(); }