Exemple #1
0
        //---------------------------------------------------------------------
        public object doFile(string file_name)
        {
            string code;

            mMapFile.TryGetValue(file_name, out code);
            if (code == null)
            {
                EbLog.Error("EbScriptMgr.runScript() Error! 读取文件失败,File=" + file_name);
                return(null);
            }

            if (mContent == null)
            {
                mContent = mEnvironment.CreateContent();
            }

            try
            {
                var tokens = mEnvironment.tokenParser.Parse(code);
                var expr   = mEnvironment.Expr_CompilerToken(tokens);
                return(mEnvironment.Expr_Execute(expr, mContent));
            }
            catch (Exception ec)
            {
                EbLog.Error("EbScriptMgr.runScript() Error!");
                EbLog.Error(ec.ToString());
                EbLog.Error(mContent.DumpValue());
                EbLog.Error(mContent.DumpStack(null));
            }

            return(null);
        }
Exemple #2
0
        private void __Run(string code, CSLE.CLS_Content content)
        {
            var tokens = env.tokenParser.Parse(code);
            var expr   = env.Expr_CompilerToken(tokens);

            env.Expr_Execute(expr, content);
        }
Exemple #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            listLog.Items.Clear();

            tokensResult = null;
            try
            {
                tokensResult = this.scriptService.ParserToken(richTextBox_Code.Text);
                using (System.IO.Stream fiels = System.IO.File.OpenWrite(curCodeFile + ".bytes"))
                {
                    this.scriptService.tokenParser.SaveTokenList(tokensResult, fiels);
                }
            }
            catch (Exception err)
            {
                Log_Error("词法识别失败");
            }
            using (System.IO.Stream fiels = System.IO.File.OpenRead(curCodeFile + ".bytes"))
            {
                tokensResult = this.scriptService.tokenParser.ReadTokenList(fiels);
            }
            if (tokensResult != null && tokensResult.Count > 0)
            {
                compilerResult = scriptService.Expr_CompilerToken(tokensResult);


                //if (compilerResult == null)
                //{
                //    Log("尝试作为表达式编译");
                //    compilerResult = scriptService.CompilerToken(tokens, true);
                //}
                //compilerResult = compiler.Optimize(compilerResult);
                ShowExp(compilerResult);
            }
        }