Пример #1
0
 /// <summary>
 /// <para>进行一趟用户脚本编译,并把所有语句子树规约到一个共同的根节点上</para>
 /// <para>并返回语义分析、流程逻辑处理和代码优化后的场景实例</para>
 /// </summary>
 /// <param name="sourceCodeItem">以行分割的源代码字符串向量</param>
 /// <param name="sceneName">场景文件的名称,不带路径和后缀名</param>
 /// <param name="itype">编译类型,决定返回的实例</param>
 /// <returns>Debug模式返回Scene实例,Release时返回该剧本的IL</returns>
 public object StartDash(List<string> sourceCodeItem, string sceneName, InterpreterType itype)
 {
     try
     {
         // 初期化
         this.Reset(sceneName);
         for (int line = 0; line < sourceCodeItem.Count; line++)
         {
             // 词法分析
             this.lexer.Init(this.scenario, sourceCodeItem[line]);
             List<Token> tokenStream = this.lexer.Analyse();
             // 语法分析
             if (tokenStream.Count > 0)
             {
                 this.parser.SetTokenStream(this.scenario, tokenStream);
                 this.parser.Parse(line);
             }
         }
         // 语义分析
         KeyValuePair<SceneAction, List<SceneFunction>> r = this.Semanticer(this.parseTree);
         this.rootScene = this.ConstructScene(r);
         string il = this.ILGenerator(this.rootScene);
         if (itype == InterpreterType.DEBUG)
         {
             return this.rootScene;
         }
         else
         {
             return il;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         return null;
     }
 }
Пример #2
0
 /// <summary>
 /// 将场景做IL序列化
 /// </summary>
 /// <param name="scene">场景实例</param>
 /// <returns>IL字符串</returns>
 private string ILGenerator(PackageScene scene)
 {
     List<SceneFunction> sf = scene.FuncContainer;
     SceneAction mainSa = scene.Ctor;
     StringBuilder sb = new StringBuilder();
     sb.AppendLine(scene.GetILSign());
     sb.Append(this.ILGenerator(mainSa));
     foreach (SceneFunction scenefunc in sf)
     {
         sb.Append(this.ILGenerator(scenefunc.Sa));
     }
     return sb.ToString();
 }