コード例 #1
0
        /// <summary>
        /// 运行用户代码,调用后端编译器进行词法、语法、语义分析
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Run_Click(object sender, RoutedEventArgs e)
        {
            // 重置输出和debug窗口
            output.Text   = "";
            debugBox.Text = "";

            // 更新解释器的源代码属性
            this.interpreter.SourceCode = input.Text;

            // 获取所有断点行号
            List <int> bpList = new List <int>();

            foreach (int key in breakPoints.Keys)
            {
                bpList.Add(key);
            }

            // 运行词法和语法分析程序
            InterpretResult result = interpreter.Run(bpList);

            // 出错处理
            if (!result.IsSuccess)
            {
                this.debugBox.Text = result.GetErrorString();
                return;
            }
            //SentenceAnalysis.nodeAnalysis(result.SyntacticAnalyseResult.Root);
            Constant.scopeTables = new List <ScopeTable>();
            Thread thread = new Thread(new ParameterizedThreadStart(threadMethod));
            object obj    = result.SyntacticAnalyseResult.Root;

            thread.Start(obj);
        }
コード例 #2
0
        /// <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);
        }