/// <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]); var tokenStream = this.lexer.Analyse(); // 语法分析 if (tokenStream.Count > 0) { this.parser.SetTokenStream(this.scenario, tokenStream); this.parser.Parse(line); } } // 语义分析 var r = this.Semanticer(this.parseTree); this.rootScene = this.ConstructScene(r); string il = this.ILGenerator(this.rootScene); if (itype == InterpreterType.DEBUG) { return(this.rootScene); } return(il); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw; } }
/////////////////////////////////////////////////////////////////////// public static bool HasFlags( InterpreterType flags, InterpreterType hasFlags, bool all ) { if (all) { return((flags & hasFlags) == hasFlags); } else { return((flags & hasFlags) != InterpreterType.None); } }
/// <summary> /// Returns the first parent interpreter that correspond to the specified <see cref="InterpreterType"/> /// </summary> /// <param name="interpreterType">The interpreter type</param> /// <param name="allowCurrent">Defines if we can consider the current interpreter as the next first parent</param> /// <returns>Returns the corresponding interpreter</returns> internal Interpret GetFirstNextParentInterpreter(InterpreterType interpreterType, bool allowCurrent = true) { if (InterpreterType == InterpreterType.ProgramInterpreter) { return(null); } if (allowCurrent && InterpreterType == interpreterType) { return(this); } var parent = this; do { parent = parent.GetParentInterpreter(); } while (parent != null && parent.InterpreterType != interpreterType); return(parent); }
/// <summary> /// 进行编译 /// </summary> /// <param name="itype">编译类型</param> /// <param name="threadN">进程数</param> public void Dash(InterpreterType itype, int threadN = 4) { this.compileType = itype; this.threadPool = new List <Thread>(); this.LoadAndSplit(); }
/// <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; } }
/// <summary> /// 进行编译 /// </summary> /// <param name="itype">编译类型</param> /// <param name="threadNum">进程数</param> public void Dash(InterpreterType itype, int threadNum = 1) { this.isMultiThread = (this.threadNum = (threadNum > 8 ? 8 : threadNum)) > 1; this.compileType = itype; this.threadPool = new List<Thread>(); this.LoadAndSplit(); }