/// <summary> /// 解释器核心运行 /// 包括调用词法、语法、语义分析 /// 以及出错处理程序 /// </summary> /// <param name="bpList">breakPoint列表,所有断点所在行数</param> public InterpretResult Run(List <int> bpList) { // 解释器最终结果 InterpretResult result = new InterpretResult(); // 词法分析 TokenResult tokenResult = WordAnalyse(); result.WordAnalyseResult = tokenResult; result.Period = InterpretPeriod.Word; if (!tokenResult.IsSuccess) { // 如果词法分析失败,则给出失败原因 result.IsSuccess = false; result.ErrorInfos = tokenResult.ErrorInfos; return(result); } // 语法分析 this.syntacticAnalyser = new SyntacticAnalyser(); ParseTree parseTree = SyntacticAnalyse(tokenResult, bpList); result.SyntacticAnalyseResult = parseTree; result.Period = InterpretPeriod.Syntactic; if (!parseTree.IsSuccess) { result.IsSuccess = false; result.ErrorInfos = parseTree.ErrorInfos; return(result); } return(result); }
/// <summary> /// 利用CMM源码,初始化解释器 /// </summary> /// <param name="sourceCode">CMM源码</param> public Interpreter(string sourceCode) { this.SourceCode = sourceCode; this.syntacticAnalyser = new SyntacticAnalyser(); }