public override string ToString() { string result = "{\"函数名\":\"" + functionname + "\",\n\"语句列表\":["; for (int i = 0; i < sentences.Count; i++) { Sentence s = sentences[i]; if (s is IfElse) { IfElse ifelse = s as IfElse; result += ifelse.ToString() + (i == sentences.Count - 1 ? "" : ","); } else if (s is While) { While @while = s as While; result += @while.ToString() + (i == sentences.Count - 1 ? "" : ","); } else { result += s.ToString() + (i == sentences.Count - 1 ? "" : ","); } } result += "],\n\"参数列表\":["; for (int i = 0; i < parametername.Count; i++) { result += "\"" + parametername[i].ToString() + "\"" + (i == parametername.Count - 1 ? "" : ","); } result += "],\n\"深度\":" + index + "}"; return(result); }
private Data getSentenceRes(Sentence sentence) { Data res = new Data(0); if (sentence is While) { While w = sentence as While; while (getSentenceRes(w.judgesentence.toks).num == 1) { foreach (Sentence s in w.sentences) { getSentenceRes(s); } } } else if (sentence is IfElse) { IfElse w = sentence as IfElse; foreach (Branch b in w.branchs) { if (b.judgesentence == null || getSentenceRes(b.judgesentence.toks).num == 1) { foreach (Sentence s in b.sentences) { getSentenceRes(s.toks); } break; } } } else if (sentence is Sentence) { res = getSentenceRes(sentence.toks); } else { throw new SyntaxErrorException("程序编译时出错"); } return(res); }