public ICLS_Expression Compiler(IList<Token> tlist, ICLS_Environment content) { ICLS_Expression value; int expbegin = 0; int expend = FindCodeBlock(tlist, expbegin); if (expend != tlist.Count - 1) { LogError(tlist, "CodeBlock 识别问题,异常结尾", expbegin, expend); return null; } bool succ = Compiler_Expression_Block(tlist, content, expbegin, expend, out value); if (succ) { if (value == null) { logger.Log_Warn("编译为null:"); } return value; } else { LogError(tlist, "编译失败:", expbegin, expend); return null; } }
public Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { var pnames = lambda.paramNames; var expr = lambda.expr_func; NonVoidDelegate dele = delegate(T param0, T1 param1, T2 param2) { if (expr != null) { CLS_Content content = lambda.content.Clone(); content.DepthAdd(); content.DefineAndSet(pnames[0], typeof(T), param0); content.DefineAndSet(pnames[1], typeof(T1), param1); content.DefineAndSet(pnames[2], typeof(T2), param2); CLS_Content.Value retValue = expr.ComputeValue(content); content.DepthRemove(); return((ReturnType)retValue.value); } return(default(ReturnType)); }; Delegate d = dele as Delegate; return(Delegate.CreateDelegate(this.type, d.Target, d.Method)); }
public ICLS_Expression Compiler_Expression_NegativeLogic(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { int expbegin = pos; int bdep; int expend2 = FindCodeAny(tlist, ref expbegin, out bdep); if (expend2 > posend) expend2 = posend; ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, expbegin, expend2, out subvalue); if (succ && subvalue != null) { if (tlist[expbegin].text != "(" && (subvalue is CLS_Expression_Math2Value || subvalue is CLS_Expression_Math2ValueAndOr || subvalue is CLS_Expression_Math2ValueLogic)) { var pp = subvalue.listParam[0]; CLS_Expression_NegativeLogic v = new CLS_Expression_NegativeLogic(pp.tokenBegin, pp.tokenEnd, pp.lineBegin, pp.lineEnd); v.listParam.Add(pp); subvalue.listParam[0] = v; return subvalue; } else { CLS_Expression_NegativeLogic v = new CLS_Expression_NegativeLogic(pos, expend2, tlist[pos].line, tlist[expend2].line); v.listParam.Add(subvalue); return v; } } else { LogError(tlist, "无法识别的取反表达式:", expbegin, posend); return null; } }
public ICLS_Expression Compiler_Expression_Function(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { CLS_Expression_Function func = new CLS_Expression_Function(pos, posend, tlist[pos].line, tlist[posend].line); func.funcname = tlist[pos].text; int begin = pos + 2; int dep; int end = FindCodeAnyInFunc(tlist, ref begin, out dep); if (tlist[pos + 1].type == TokenType.PUNCTUATION && tlist[pos + 1].text == "(") { do { ICLS_Expression param; bool succ = Compiler_Expression(tlist, content, begin, end, out param); if (succ && param != null) { func.listParam.Add(param); func.tokenEnd = end; func.lineEnd = tlist[end].line; } begin = end + 2; end = FindCodeAnyInFunc(tlist, ref begin, out dep); }while (end < posend && begin <= end); return(func); } //一般函数 return(null); }
public Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { CLS_Content content = new CLS_Content(env); DeleFunction _func = delefunc; Action <T, T1, T2> dele = (T param0, T1 param1, T2 param2) => { content.DepthAdd(); content.CallThis = _func.callthis; content.CallType = _func.calltype; content.function = _func.function; var func = _func.calltype.functions[_func.function]; content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0); content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1); content.DefineAndSet(func._paramnames[2], func._paramtypes[2].type, param2); func.expr_runtime.ComputeValue(content); content.DepthRemove(); }; Delegate d = dele as Delegate; if ((Type)this.type != typeof(Action <T, T1, T2>)) { return(Delegate.CreateDelegate(this.type, d.Target, d.Method)); } else { return(dele); } }
public Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { DeleFunction _func = delefunc; Delegate _dele = delefunc.cacheFunction(null); if (_dele != null) { return(_dele); } NonVoidDelegate dele = delegate(T param0, T1 param1, T2 param2) { var func = _func.calltype.functions[_func.function]; if (func.expr_runtime != null) { CLS_Content content = new CLS_Content(env); content.DepthAdd(); content.CallThis = _func.callthis; content.CallType = _func.calltype; content.function = _func.function; content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0); content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1); content.DefineAndSet(func._paramnames[2], func._paramtypes[2].type, param2); CLS_Content.Value retValue = func.expr_runtime.ComputeValue(content); content.DepthRemove(); return((ReturnType)retValue.value); } return(default(ReturnType)); }; _dele = Delegate.CreateDelegate(this.type, dele.Target, dele.Method); return(delefunc.cacheFunction(_dele)); }
public ICLS_Expression Compile(IList <Token> tlist, ICLS_Environment content) { ICLS_Expression value; int expbegin = 0; int expend = FindCodeBlock(tlist, expbegin); if (expend != tlist.Count - 1) { LogError(tlist, "CodeBlock 识别问题,异常结尾", expbegin, expend); return(null); } bool succ = Compiler_Expression_Block(tlist, content, expbegin, expend, out value); if (succ) { if (value == null) { logger.Log_Warn("编译为null:"); } return(value); } else { LogError(tlist, "编译失败:", expbegin, expend); return(null); } }
public override Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { Action <T, T1> dele; if (lambda.expr_func != null) { dele = (T param0, T1 param1) => { #if UNITY_EDITOR try{ #endif lambda.content.DepthAdd(); lambda.content.DefineAndSet(lambda.paramNames[0], typeof(T), param0); lambda.content.DefineAndSet(lambda.paramNames[1], typeof(T1), param1); lambda.expr_func.ComputeValue(lambda.content); lambda.content.DepthRemove(); #if UNITY_EDITOR }catch (System.Exception ex) { lambda.content.environment.logger.Log_Error(ex.Message + "\n" + lambda.content.DumpStack() + ex); } #endif }; } else { dele = (T param0, T1 param1) => { }; } if (this.sysType != typeof(Action <T, T1>)) { return(Delegate.CreateDelegate(this.sysType, dele.Target, dele.Method)); } else { return(dele); } }
public ICLS_Expression Compiler_Expression_NegativeValue(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { int expbegin = pos; int bdep; int expend2 = FindCodeAny(tlist, ref expbegin, out bdep); if (expend2 != posend) { LogError(tlist,"无法识别的负号表达式:" ,expbegin , posend); return null; } else { ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist,content, expbegin, expend2, out subvalue); if (succ && subvalue != null) { CLS_Expression_NegativeValue v = new CLS_Expression_NegativeValue(pos, expend2, tlist[pos].line, tlist[expend2].line); v.listParam.Add(subvalue); return v; } else { LogError(tlist, "无法识别的负号表达式:", expbegin, posend); return null; } } }
public Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { CLS_Content content = lambda.content.Clone(); var pnames = lambda.paramNames; var expr = lambda.expr_func; Action <T, T1, T2> dele = (T param0, T1 param1, T2 param2) => { content.DepthAdd(); content.DefineAndSet(pnames[0], typeof(T), param0); content.DefineAndSet(pnames[1], typeof(T1), param1); content.DefineAndSet(pnames[2], typeof(T2), param2); expr.ComputeValue(content); content.DepthRemove(); }; Delegate d = dele as Delegate; if ((Type)this.type != typeof(Action <T, T1, T2>)) { return(Delegate.CreateDelegate(this.type, d.Target, d.Method)); } else { return(dele); } }
public ICLS_Expression Compiler_Expression_NegativeBit(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { int expbegin = pos; int bdep; int expend2 = FindCodeAny(tlist, ref expbegin, out bdep); if (expend2 != posend) { LogError(tlist, "无法识别的按位取反表达式:", expbegin, posend); return(null); } else { ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, expbegin, expend2, out subvalue); if (succ && subvalue != null) { CLS_Expression_NegativeBit v = new CLS_Expression_NegativeBit(pos, expend2, tlist[pos].line, tlist[expend2].line); v.listParam.Add(subvalue); return(v); } else { LogError(tlist, "无法识别的按位取反表达式:", expbegin, posend); return(null); } } }
public override Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { NonVoidDelegate dele; if (lambda.expr_func != null) { dele = delegate(T param0, T1 param1, T2 param2) { #if UNITY_EDITOR try{ #endif lambda.content.DepthAdd(); lambda.content.DefineAndSet(lambda.paramNames[0], typeof(T), param0); lambda.content.DefineAndSet(lambda.paramNames[1], typeof(T1), param1); lambda.content.DefineAndSet(lambda.paramNames[2], typeof(T2), param2); CLS_Content.Value retValue = lambda.expr_func.ComputeValue(lambda.content); lambda.content.DepthRemove(); return((ReturnType)retValue.value); #if UNITY_EDITOR }catch (System.Exception ex) { lambda.content.environment.logger.Log_Error(ex.Message + "\n" + lambda.content.DumpStack() + ex); return(default(ReturnType)); } #endif }; } else { dele = delegate(T param0, T1 param1, T2 param2) { return(default(ReturnType)); }; } return(Delegate.CreateDelegate(this.type, dele.Target, dele.Method)); }
public Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { CLS_Content content = new CLS_Content(env); DeleFunction _func = delefunc; Action dele = () => { content.DepthAdd(); content.CallThis = _func.callthis; content.CallType = _func.calltype; content.function = _func.function; var func = _func.calltype.functions[_func.function]; //content.DefineAndSet(function._paramnames[0], function._paramtypes[0].type, param0); func.expr_runtime.ComputeValue(content); content.DepthRemove(); }; Delegate d = dele as Delegate; if ((Type)this.type != typeof(Action)) { return Delegate.CreateDelegate(this.type, d.Target, d.Method); } else { return dele; } }
public ICLS_Expression Compiler_Expression_Function(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { CLS_Expression_Function func = new CLS_Expression_Function(pos, posend, tlist[pos].line, tlist[posend].line); func.funcname = tlist[pos].text; int begin = pos + 2; int dep; int end = FindCodeAnyInFunc(tlist, ref begin, out dep); if (tlist[pos + 1].type == TokenType.PUNCTUATION && tlist[pos + 1].text == "(") { do { ICLS_Expression param; bool succ = Compiler_Expression(tlist, content, begin, end, out param); if (succ && param != null) { func.listParam.Add(param); func.tokenEnd = end; func.lineEnd = tlist[end].line; } begin = end + 2; end = FindCodeAnyInFunc(tlist, ref begin, out dep); } while (end < posend && begin <= end); return func; } return null; }
public override Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { NonVoidDelegate dele; if (lambda.expr_func != null) { dele = delegate() { #if UNITY_EDITOR try{ #endif CLS_Content.Value retValue = lambda.expr_func.ComputeValue(lambda.content); return((ReturnType)retValue.value); #if UNITY_EDITOR }catch (System.Exception ex) { lambda.content.environment.logger.Log_Error(ex.Message + "\n" + lambda.content.DumpStack() + ex); return(default(ReturnType)); } #endif }; } else { dele = delegate() { return(default(ReturnType)); }; } return(Delegate.CreateDelegate(this.type, dele.Target, dele.Method)); }
public Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { var pnames = lambda.paramNames; var expr = lambda.expr_func; Action dele = () => { if (expr != null) { CLS_Content content = lambda.content.Clone(); content.DepthAdd(); //content.DefineAndSet(pnames[0], typeof(T), param0); expr.ComputeValue(content); content.DepthRemove(); } }; Delegate d = dele as Delegate; if ((Type)this.type != typeof(Action)) { return(Delegate.CreateDelegate(this.type, d.Target, d.Method)); } else { return(dele); } }
public Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { CLS_Content content = lambda.content.Clone(); var pnames = lambda.paramNames; var expr = lambda.expr_func; NonVoidDelegate dele = delegate(T param) { if (expr != null) { try { content.DepthAdd(); content.DefineAndSet(pnames[0], typeof(T), param); CLS_Content.Value retValue = expr.ComputeValue(content); content.DepthRemove(); return((ReturnType)retValue.value); } catch (Exception err) { env.logger.Log(content.Dump()); throw err; } } return(default(ReturnType)); }; Delegate d = dele as Delegate; return(Delegate.CreateDelegate(this.type, d.Target, d.Method)); }
public Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { var pnames = lambda.paramNames; var expr = lambda.expr_func; Action dele = () => { if (expr != null) { CLS_Content content = lambda.content.Clone(); content.DepthAdd(); //content.DefineAndSet(pnames[0], typeof(T), param0); expr.ComputeValue(content); content.DepthRemove(); } }; Delegate d = dele as Delegate; if ((Type)this.type != typeof(Action)) { return Delegate.CreateDelegate(this.type, d.Target, d.Method); } else { return dele; } }
public Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { DeleFunction _func = delefunc; NonVoidDelegate dele = delegate() { var func = _func.calltype.functions[_func.function]; if (func.expr_runtime != null) { CLS_Content content = new CLS_Content(env); content.DepthAdd(); content.CallThis = _func.callthis; content.CallType = _func.calltype; content.function = _func.function; CLS_Content.Value retValue = func.expr_runtime.ComputeValue(content); content.DepthRemove(); return((ReturnType)retValue.value); } return(default(ReturnType)); }; Delegate d = dele; return(Delegate.CreateDelegate(this.type, d.Target, d.Method)); }
public ICLS_Expression Compiler_Expression_DefineAndSet(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { int expbegin = pos + 3; int bdep; int expend = FindCodeAny(tlist, ref expbegin, out bdep); if (expend != posend) { expend = posend; } ICLS_Expression v; bool succ = Compiler_Expression(tlist, content, expbegin, expend, out v); if (succ && v != null) { CLS_Expression_Define define = new CLS_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line); if (tlist[pos].text == "bool") { define.value_type = typeof(bool); } else { ICLS_Type type = content.GetTypeByKeyword(tlist[pos].text); define.value_type = type.type; } define.value_name = tlist[pos + 1].text; define.listParam.Add(v); return(define); } LogError(tlist, "不正确的定义表达式:", pos, posend); return(null); }
public override Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { Action dele; if (lambda.expr_func != null) { dele = () => { #if UNITY_EDITOR try{ #endif lambda.expr_func.ComputeValue(lambda.content); #if UNITY_EDITOR }catch (System.Exception ex) { lambda.content.environment.logger.Log_Error(ex.Message + "\n" + lambda.content.DumpStack() + ex); } #endif }; } else { dele = () => { }; } if (this.sysType != typeof(Action)) { return(Delegate.CreateDelegate(this.sysType, dele.Target, dele.Method)); } else { return(dele); } }
public override Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { Action dele; if (lambda.expr_func != null) { dele = () => { #if UNITY_EDITOR try{ #endif lambda.expr_func.ComputeValue(lambda.content); #if UNITY_EDITOR }catch (System.Exception ex) { lambda.content.environment.logger.Log_Error(ex.Message + "\n" + lambda.content.DumpStack() + ex); } #endif }; } else { dele = () => { }; } if (this.sysType != typeof(Action)) { return Delegate.CreateDelegate(this.sysType, dele.Target, dele.Method); } else { return dele; } }
public Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { DeleFunction _func = delefunc; Delegate _dele = delefunc.cacheFunction(this._type, null); if (_dele != null) { return(_dele); } Action <T, T1, T2> dele = (T param0, T1 param1, T2 param2) => { var func = _func.calltype.functions[_func.function]; if (func.expr_runtime != null) { CLS_Content content = new CLS_Content(env, true); try { content.DepthAdd(); content.CallThis = _func.callthis; content.CallType = _func.calltype; content.function = _func.function; content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0); content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1); content.DefineAndSet(func._paramnames[2], func._paramtypes[2].type, param2); func.expr_runtime.ComputeValue(content); content.DepthRemove(); } catch (Exception err) { string errinfo = "Dump Call in:"; if (_func.calltype != null) { errinfo += _func.calltype.Name + "::"; } if (_func.function != null) { errinfo += _func.function; } errinfo += "\n"; env.logger.Log(errinfo + content.Dump()); throw err; } } }; Delegate d = dele as Delegate; if ((Type)this.type != typeof(Action)) { _dele = Delegate.CreateDelegate(this.type, d.Target, d.Method); } else { _dele = dele; } return(delefunc.cacheFunction(this._type, _dele)); }
public ICLS_Expression Optimize(ICLS_Expression value, ICLS_Environment env) { ICLS_Expression expr = value as ICLS_Expression; if (expr == null) return value; else return OptimizeDepth(expr, CLS_Content.NewContent(env)); }
public ICLS_Expression Compiler_Expression_Lambda(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { int b1; int fs1 = pos; int fe1 = FindCodeAny(tlist, ref fs1, out b1); CLS_Expression_Lambda value = new CLS_Expression_Lambda(pos, posend, tlist[pos].line, tlist[posend].line); int testbegin = fs1 + 1; if (b1 != 1) { return(null); } //(xxx)=>{...} CLS_Expression_Block block = new CLS_Expression_Block(fs1, fe1, tlist[fs1].line, tlist[fe1].line); do { int fe2 = FindCodeAny(tlist, ref testbegin, out b1); ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, testbegin, fe2, out subvalue); if (!succ) { break; } if (subvalue != null) { block.listParam.Add(subvalue); testbegin = fe2 + 2; } else { block.listParam.Add(null); testbegin = fe2 + 2; } }while (testbegin <= fe1); value.listParam.Add(block); //(...)=>{} ICLS_Expression subvalueblock; int b2; int fs2 = fe1 + 2; int fecode = FindCodeAny(tlist, ref fs2, out b2); bool succ2 = Compiler_Expression_Block(tlist, content, fs2, fecode, out subvalueblock); if (succ2) { //value.tokenEnd = fecode; //value.lineEnd = tlist[fecode].line; value.listParam.Add(subvalueblock); return(value); } return(null); }
public ICLS_Expression Compiler_Expression_Loop_ForEach(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { int b1; int fs1 = pos + 1; int fe1 = FindCodeAny(tlist, ref fs1, out b1); CLS_Expression_LoopForEach value = new CLS_Expression_LoopForEach(pos, fe1, tlist[pos].line, tlist[fe1].line); //int testbegin = fs1 + 1; if (b1 != 1) { return null; } for (int i = fs1 + 1; i <= fe1 - 1; i++) { if (tlist[i].text == "in" && tlist[i].type == TokenType.KEYWORD) { //添加 foreach 定义变量部分 { ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, fs1 + 1, i - 1, out subvalue); if (!succ) return null; if (subvalue != null) { value.listParam.Add(subvalue); } } //添加 foreach 列表部分 { ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, i + 1, fe1 - 1, out subvalue); if (!succ) return null; if (subvalue != null) { value.listParam.Add(subvalue); } } break; } } ICLS_Expression subvalueblock; int b2; int fs2 = fe1 + 1; int fecode = FindCodeAny(tlist, ref fs2, out b2); bool succ2 = Compiler_Expression_Block(tlist, content, fs2, fecode, out subvalueblock); if (succ2) { value.tokenEnd = fecode; value.lineEnd = tlist[fecode].line; value.listParam.Add(subvalueblock); return value; } return null; }
public ICLS_Expression Compiler_Expression_Loop_For(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { int b1; int fs1 = pos + 1; int fe1 = FindCodeAny(tlist, ref fs1, out b1); CLS_Expression_LoopFor value = new CLS_Expression_LoopFor(pos, posend, tlist[pos].line, tlist[posend].line); int testbegin = fs1 + 1; if (b1 != 1) { return(null); } do { int fe2 = FindCodeAny(tlist, ref testbegin, out b1); ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, testbegin, fe2, out subvalue); if (!succ) { return(null); } if (subvalue != null) { value.listParam.Add(subvalue); testbegin = fe2 + 2; } else { value.listParam.Add(null); testbegin = fe2 + 2; } }while (testbegin <= fe1); if (value.listParam.Count != 3) { return(null); } ICLS_Expression subvalueblock; int b2; int fs2 = fe1 + 1; int fecode = FindCodeAny(tlist, ref fs2, out b2); bool succ2 = Compiler_Expression_Block(tlist, content, fs2, fecode, out subvalueblock); if (succ2) { value.tokenEnd = fecode; value.lineEnd = tlist[fecode].line; value.listParam.Add(subvalueblock); return(value); } return(null); }
public CLS_Content(ICLS_Environment environment,bool useDebug) { this.environment = environment; this.useDebug = useDebug; if(useDebug) { stackExpr = new Stack<ICLS_Expression>(); stackContent = new Stack<CLS_Content>(); } }
public ICLS_Expression Compiler_Expression_DefineArray(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { CLS_Expression_Define define = new CLS_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line); { ICLS_Type type = content.GetTypeByKeyword(tlist[pos].text+"[]"); define.value_type = type.type; } define.value_name = tlist[pos + 3].text; return define; }
public CLS_Content(ICLS_Environment environment, bool useDebug = true) { this.environment = environment; this.useDebug = useDebug; if (useDebug) { stackExpr = new Stack <ICLS_Expression>(); stackContent = new Stack <CLS_Content>(); } }
public ICLS_Expression Compiler_Expression_DefineArray(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { CLS_Expression_Define define = new CLS_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line); { ICLS_Type type = content.GetTypeByKeyword(tlist[pos].text + "[]"); define.value_type = type.type; } define.value_name = tlist[pos + 3].text; return(define); }
public ICLS_Expression Compiler_Expression_Loop_For(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { int b1; int fs1 = pos + 1; int fe1 = FindCodeAny(tlist, ref fs1, out b1); CLS_Expression_LoopFor value = new CLS_Expression_LoopFor(pos, posend, tlist[pos].line, tlist[posend].line); int testbegin = fs1 + 1; if (b1 != 1) { return null; } do { int fe2 = FindCodeAny(tlist, ref testbegin, out b1); ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, testbegin, fe2, out subvalue); //if (!succ) return null; if (subvalue != null) { value.listParam.Add(subvalue); testbegin = fe2 + 2; } else { value.listParam.Add(null); testbegin = fe2 + 2; } } while (testbegin <= fe1); if (value.listParam.Count != 3) { return null; } ICLS_Expression subvalueblock; int b2; int fs2 = fe1 + 1; int fecode = FindCodeAny(tlist, ref fs2, out b2); bool succ2 = Compiler_Expression_Block(tlist, content, fs2, fecode, out subvalueblock); if (succ2) { value.tokenEnd = fecode; value.lineEnd = tlist[fecode].line; value.listParam.Add(subvalueblock); return value; } return null; }
public Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { DeleFunction _func = delefunc; Delegate _dele = delefunc.cacheFunction(this._type, null); if (_dele != null) { return(_dele); } NonVoidDelegate dele = delegate(T param0, T1 param1, T2 param2) { var func = _func.calltype.functions[_func.function]; if (func.expr_runtime != null) { CLS_Content content = new CLS_Content(env, true); try { content.DepthAdd(); content.CallThis = _func.callthis; content.CallType = _func.calltype; content.function = _func.function; content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0); content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1); content.DefineAndSet(func._paramnames[2], func._paramtypes[2].type, param2); CLS_Content.Value retValue = func.expr_runtime.ComputeValue(content); content.DepthRemove(); return((ReturnType)retValue.value); } catch (Exception err) { string errinfo = "Dump Call in:"; if (_func.calltype != null) { errinfo += _func.calltype.Name + "::"; } if (_func.function != null) { errinfo += _func.function; } errinfo += "\n"; env.logger.Log(errinfo + content.Dump()); throw err; } } return(default(ReturnType)); }; _dele = Delegate.CreateDelegate(this.type, dele.Target, dele.Method); return(delefunc.cacheFunction(this._type, _dele)); }
public ICLS_Expression Compiler_Expression_Lambda(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { int b1; int fs1 = pos; int fe1 = FindCodeAny(tlist, ref fs1, out b1); CLS_Expression_Lambda value = new CLS_Expression_Lambda(pos, posend, tlist[pos].line, tlist[posend].line); int testbegin = fs1 + 1; if (b1 != 1) { return null; } //(xxx)=>{...} CLS_Expression_Block block = new CLS_Expression_Block(fs1, fe1, tlist[fs1].line, tlist[fe1].line); do { int fe2 = FindCodeAny(tlist, ref testbegin, out b1); ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, testbegin, fe2, out subvalue); if (!succ) break; if (subvalue != null) { block.listParam.Add(subvalue); testbegin = fe2 + 2; } else { block.listParam.Add(null); testbegin = fe2 + 2; } } while (testbegin <= fe1); value.listParam.Add(block); //(...)=>{} ICLS_Expression subvalueblock; int b2; int fs2 = fe1 + 2; int fecode = FindCodeAny(tlist, ref fs2, out b2); bool succ2 = Compiler_Expression_Block(tlist, content, fs2, fecode, out subvalueblock); if (succ2) { //value.tokenEnd = fecode; //value.lineEnd = tlist[fecode].line; value.listParam.Add(subvalueblock); return value; } return null; }
public ICLS_Expression Optimize(ICLS_Expression value, ICLS_Environment env) { ICLS_Expression expr = value as ICLS_Expression; if (expr == null) { return(value); } else { return(OptimizeDepth(expr, new CLS_Content(env))); } }
public ICLS_Expression Compiler_Expression_Loop_Return(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { CLS_Expression_LoopReturn value = new CLS_Expression_LoopReturn(pos, posend, tlist[pos].line, tlist[posend].line); ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, pos + 1, posend, out subvalue); if (succ) { value.listParam.Add(subvalue); } return(value); }
public ICLS_Expression Compiler_Expression_Define(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { CLS_Expression_Define define = new CLS_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line); if (tlist[pos].text == "bool") { define.value_type = typeof(bool); } else { ICLS_Type type = content.GetTypeByKeyword(tlist[pos].text); define.value_type = type.type; } define.value_name = tlist[pos+1].text; return define; }
public static CLS_Content NewContent(ICLS_Environment environment) { if (s_contentPool.size > 0) { CLS_Content content = s_contentPool.Pop(); content.environment = environment; return(content); } else { CLS_Content content = new CLS_Content(); content.environment = environment; return(content); } }
public static CLS_Content NewContent(ICLS_Environment environment) { if (s_contentPool.size > 0) { CLS_Content content = s_contentPool.Pop(); content.environment = environment; return content; } else { CLS_Content content = new CLS_Content(); content.environment = environment; return content; } }
public static void RegWithDelegate(ICLS_Environment env, Delegate _dele, string keyword) { var pp = _dele.Method.GetParameters(); if (_dele.Method.ReturnType == typeof(void)) { if (pp.Length == 0) { env.RegType(new RegHelper_DeleAction(_dele.GetType(), keyword)); } else if (pp.Length == 1) { var gtype = typeof(RegHelper_DeleAction <>).MakeGenericType(new Type[] { pp[0].ParameterType }); env.RegType(gtype.GetConstructors()[0].Invoke(new object[] { _dele.GetType(), keyword }) as ICLS_Type); } else if (pp.Length == 2) { var gtype = typeof(RegHelper_DeleAction <,>).MakeGenericType(new Type[] { pp[0].ParameterType, pp[1].ParameterType }); env.RegType(gtype.GetConstructors()[0].Invoke(new object[] { _dele.GetType(), keyword }) as ICLS_Type); } else if (pp.Length == 3) { var gtype = typeof(RegHelper_DeleAction <, ,>).MakeGenericType(new Type[] { pp[0].ParameterType, pp[1].ParameterType, pp[2].ParameterType }); env.RegType(gtype.GetConstructors()[0].Invoke(new object[] { _dele.GetType(), keyword }) as ICLS_Type); } } else { Type gtype = null; if (pp.Length == 0) { gtype = typeof(RegHelper_DeleNonVoidAction <>).MakeGenericType(new Type[] { _dele.Method.ReturnType }); } else if (pp.Length == 1) { gtype = typeof(RegHelper_DeleNonVoidAction <,>).MakeGenericType(new Type[] { _dele.Method.ReturnType, pp[0].ParameterType }); } else if (pp.Length == 2) { gtype = typeof(RegHelper_DeleNonVoidAction <, ,>).MakeGenericType(new Type[] { _dele.Method.ReturnType, pp[0].ParameterType, pp[1].ParameterType }); } else if (pp.Length == 3) { gtype = typeof(RegHelper_DeleNonVoidAction <, , ,>).MakeGenericType(new Type[] { _dele.Method.ReturnType, pp[0].ParameterType, pp[1].ParameterType, pp[2].ParameterType }); } env.RegType(gtype.GetConstructors()[0].Invoke(new object[] { _dele.GetType(), keyword }) as ICLS_Type); } }
public ICLS_Expression Compiler_Expression_Loop_Dowhile(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { int b1; int fs1 = pos + 1; int fe1 = FindCodeAny(tlist, ref fs1, out b1); CLS_Expression_LoopDowhile value = new CLS_Expression_LoopDowhile(pos, fe1, tlist[pos].line, tlist[fe1].line); //do(xxx)while(...) { ICLS_Expression subvalue; bool succ = Compiler_Expression_Block(tlist, content, fs1, fe1, out subvalue); if (succ) { value.tokenEnd = fe1; value.lineEnd = tlist[fe1].line; value.listParam.Add(subvalue); } else { return(null); } } //do{...]while(yyy); if (tlist[fe1 + 1].text != "while") { return(null); } int b2; int fs2 = fe1 + 2; int fe2 = FindCodeAny(tlist, ref fs2, out b2); { ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, fs2, fe2, out subvalue); if (succ) { value.tokenEnd = fe2; value.lineEnd = tlist[fe2].line; value.listParam.Add(subvalue); } else { return(null); } } return(value); }
public Delegate CreateDelegate(ICLS_Environment env, DeleLambda lambda) { CLS_Content content = lambda.content.Clone(); var pnames = lambda.paramNames; var expr = lambda.expr_func; Action <T, T1, T2> dele = (T param0, T1 param1, T2 param2) => { if (expr != null) { try { content.DepthAdd(); content.DefineAndSet(pnames[0], typeof(T), param0); content.DefineAndSet(pnames[1], typeof(T1), param1); content.DefineAndSet(pnames[2], typeof(T2), param2); expr.ComputeValue(content); content.DepthRemove(); } catch (Exception err) { string errinfo = "Dump Call lambda in:"; if (content.CallType != null) { errinfo += content.CallType.Name + "::"; } if (content.function != null) { errinfo += content.function; } errinfo += "\n"; env.logger.Log(errinfo + content.Dump()); throw err; } } }; Delegate d = dele as Delegate; if ((Type)this.type != typeof(Action <T, T1, T2>)) { return(Delegate.CreateDelegate(this.type, d.Target, d.Method)); } else { return(dele); } }
public ICLS_Expression Compiler_Expression_Define(IList <Token> tlist, ICLS_Environment content, int pos, int posend) { CLS_Expression_Define define = new CLS_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line); if (tlist[pos].text == "bool") { define.value_type = typeof(bool); } else { ICLS_Type type = content.GetTypeByKeyword(tlist[pos].text); define.value_type = type.type; } define.value_name = tlist[pos + 1].text; return(define); }
public ICLS_Expression Compiler_Expression_NegativeValue(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, pos, posend, out subvalue); if (succ && subvalue != null) { CLS_Expression_NegativeValue v = new CLS_Expression_NegativeValue(pos, posend, tlist[pos].line, tlist[posend].line); v.listParam.Add(subvalue); return v; } else { LogError(tlist, "无法识别的负号表达式:", pos, posend); return null; } }
public override Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { Delegate _dele = delefunc.cacheFunction(null); if (_dele != null) { return(_dele); } var func = delefunc.calltype.functions[delefunc.function]; Action <T, T1, T2> dele; if (func.expr_runtime != null) { dele = (T param0, T1 param1, T2 param2) => { CLS_Content content = CLS_Content.NewContent(env); #if UNITY_EDITOR try{ #endif content.CallThis = delefunc.callthis; content.CallType = delefunc.calltype; content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0); content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1); content.DefineAndSet(func._paramnames[2], func._paramtypes[2].type, param2); func.expr_runtime.ComputeValue(content); CLS_Content.PoolContent(content); #if UNITY_EDITOR }catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); } #endif }; } else { dele = (T param0, T1 param1, T2 param2) => { }; } if (this.sysType != typeof(Action <T, T1, T2>)) { _dele = Delegate.CreateDelegate(this.sysType, dele.Target, dele.Method); } else { _dele = dele; } return(delefunc.cacheFunction(_dele)); }
public ICLS_Expression Compiler_Expression_FunctionThrow(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { CLS_Expression_Throw func = new CLS_Expression_Throw(pos, posend, tlist[pos].line, tlist[posend].line); ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, pos + 1, posend, out subvalue); if (succ) { func.listParam.Add(subvalue); } return func; //trace ,单值直接dump,否则按逗号分隔的表达式处理 //return null; }
public Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { DeleFunction _func = delefunc; Delegate _dele = delefunc.cacheFunction(null); if (_dele != null) { return(_dele); } Action <T> dele = (T param0) => { var func = _func.calltype.functions[_func.function]; if (func.expr_runtime != null) { CLS_Content content = new CLS_Content(env); try { content.DepthAdd(); content.CallThis = _func.callthis; content.CallType = _func.calltype; content.function = _func.function; content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0); func.expr_runtime.ComputeValue(content); content.DepthRemove(); } catch (Exception err) { env.logger.Log(content.Dump()); throw err; } } }; Delegate d = dele as Delegate; if ((Type)this.type != typeof(Action)) { _dele = Delegate.CreateDelegate(this.type, d.Target, d.Method); } else { _dele = dele; } return(delefunc.cacheFunction(_dele)); }
public ICLS_Expression Compiler_Expression_Loop_Dowhile(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { int b1; int fs1 = pos + 1; int fe1 = FindCodeAny(tlist, ref fs1, out b1); CLS_Expression_LoopDowhile value = new CLS_Expression_LoopDowhile(pos, fe1, tlist[pos].line, tlist[fe1].line); //do(xxx)while(...) { ICLS_Expression subvalueblock; bool succ = Compiler_Expression_Block(tlist, content, fs1, fe1, out subvalueblock); if (succ) { value.tokenEnd = fe1; value.lineEnd = tlist[fe1].line; value.listParam.Add(subvalueblock); } else { return null; } } //do{...]while(yyy); if (tlist[fe1 + 1].text != "while") return null; int b2; int fs2 = fe1 + 2; int fe2 = FindCodeAny(tlist, ref fs2, out b2); { ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, fs2, fe2, out subvalue); if (succ) { value.tokenEnd = fe2; value.lineEnd = tlist[fe2].line; value.listParam.Add(subvalue); } else { return null; } } return value; }
public ICLS_Expression Compiler_Expression_FunctionTrace(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { if (tlist[pos + 1].type == TokenType.PUNCTUATION && tlist[pos + 1].text == "(") return Compiler_Expression_Function(tlist, content, pos, posend); int begin = pos + 1; int dep; int end = FindCodeAnyInFunc(tlist, ref begin, out dep); if (end != posend) { return null; } CLS_Expression_Function func = new CLS_Expression_Function(pos, end, tlist[pos].line, tlist[end].line); func.funcname = "trace"; do { ICLS_Expression param; bool succ = Compiler_Expression(tlist, content, begin, end, out param); if (succ && param != null) { func.listParam.Add(param); func.tokenEnd = end; func.lineEnd = tlist[end].line; } begin = end + 2; end = FindCodeAnyInFunc(tlist, ref begin, out dep); } while (end < posend && begin <= end); //ICLS_Expression param0; //bool succ = Compiler_Expression(tlist,content, begin, end, out param0); //if(succ&¶m0!=null) //{ // func.listParam.Add(param0); // return func; //} return func; //trace ,单值直接dump,否则按逗号分隔的表达式处理 //return null; }
public override Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc) { Delegate _dele = delefunc.cacheFunction(null); if (_dele != null) return _dele; var func = delefunc.calltype.functions[delefunc.function]; Action dele; if (func.expr_runtime != null) { dele = () => { CLS_Content content = CLS_Content.NewContent(env); #if UNITY_EDITOR try{ #endif content.CallThis = delefunc.callthis; content.CallType = delefunc.calltype; func.expr_runtime.ComputeValue(content); CLS_Content.PoolContent(content); #if UNITY_EDITOR }catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); } #endif }; } else { dele = () => { }; } if (this.sysType != typeof(Action)) { _dele = Delegate.CreateDelegate(this.sysType, dele.Target, dele.Method); } else { _dele = dele; } return delefunc.cacheFunction(_dele); }
// 可以搞出Block public bool Compiler_Expression_Block(IList<Token> tlist, ICLS_Environment content, int pos, int posend, out ICLS_Expression value) { int begin = pos; value = null; List<ICLS_Expression> values = new List<ICLS_Expression>(); int end = 0; do { if (tlist[begin].type == TokenType.COMMENT) { begin++; continue; } if (tlist[begin].type == TokenType.PUNCTUATION && tlist[begin].text == ";") { begin++; continue; } int bdep; //脱一次壳 end = FindCodeInBlock(tlist, ref begin, out bdep); if (end > posend) { end = posend; } int expend = end; int expbegin = begin; if (expbegin > expend) return true; if (bdep == 2) //编译块表达式 { expbegin++; expend--; ICLS_Expression subvalue; bool bsucc = Compiler_Expression_Block(tlist,content, expbegin, expend, out subvalue); if (bsucc) { if (subvalue != null) values.Add(subvalue); } else { return false; } } else { ICLS_Expression subvalue; bool bsucc = Compiler_Expression(tlist, content,expbegin, expend, out subvalue); if (bsucc) { if (subvalue != null) values.Add(subvalue); } else { return false; } } begin = end + 1; } while (begin <= posend); if (values.Count == 1) { value = values[0]; } else if (values.Count > 1) { value = new CLS_Expression_Block(values, pos, end, tlist[pos].line, tlist[end].line); } return true; }
// 不出Block,必须一次解析完,括号为优先级 public bool Compiler_Expression(IList<Token> tlist, ICLS_Environment environment, int pos, int posend, out ICLS_Expression value) { if (pos > posend) { value = null; return false; } int begin = pos; value = null; List<ICLS_Expression> values = new List<ICLS_Expression>(); do { if (tlist[begin].type == TokenType.COMMENT) { begin++; continue; } if (tlist[begin].type == TokenType.PUNCTUATION && tlist[begin].text == ";") { begin++; continue; } int bdep; //脱一次壳 int end = FindCodeAny(tlist, ref begin, out bdep); if (end > posend) { end = posend; } else if (end < posend) { bool bMath = false; for (int i = end + 1; i <= posend; i++) { if (tlist[i].type == TokenType.COMMENT) continue; if (tlist[i].type == TokenType.PUNCTUATION && tlist[i].text == ";") continue; bMath = true; break; } if (bMath) { end = posend; //如果表达式一次搞不完,那肯定是优先级问题 value = Compiler_Expression_Math(tlist,environment, begin, posend); return true; } } int expend = end; int expbegin = begin; if (expbegin > expend) return true; if (expend == expbegin) { if (tlist[expbegin].type == TokenType.KEYWORD) { if (tlist[expbegin].text == "return") { ICLS_Expression subvalue = Compiler_Expression_Loop_Return(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); } else if (tlist[expbegin].text == "break") { ICLS_Expression subvalue = Compiler_Expression_Loop_Break(tlist, expbegin); if (null == subvalue) return false; else values.Add(subvalue); } else if (tlist[expbegin].text == "continue") { ICLS_Expression subvalue = Compiler_Expression_Loop_Continue(tlist, expbegin); if (null == subvalue) return false; else values.Add(subvalue); } else if (tlist[expbegin].text == "true") { values.Add(new CLS_True()); } else if (tlist[expbegin].text == "false") { values.Add(new CLS_False()); } else if (tlist[expbegin].text == "null") { values.Add(new CLS_Null()); } } else { ICLS_Expression subvalue = Compiler_Expression_Value(tlist[expbegin],expbegin); if (null == subvalue) return false; else values.Add(subvalue); } } else if (bdep == 1) //深层表达式 { expbegin++; expend--; ICLS_Expression subvalue; bool bsucc = Compiler_Expression(tlist, environment, expbegin, expend, out subvalue); if (bsucc) { if (subvalue != null) values.Add(subvalue); } else { return false; } } else //尝试各种表达式 { bool bTest = false; // 取反表达式 if (tlist[expbegin].type == TokenType.PUNCTUATION && tlist[expbegin].text == "-") { if (tlist[expend].type == TokenType.VALUE) { // 负数 if (expend == expbegin + 1) { ICLS_Expression subvalue = Compiler_Expression_SubValue(tlist[expend]); if (null == subvalue) return false; else values.Add(subvalue); } else { ICLS_Expression subvalue = Compiler_Expression_Math(tlist, environment, begin, posend); if (null == subvalue) return false; else values.Add(subvalue); } } else { // 负数表达式 ICLS_Expression subvalue = Compiler_Expression_NegativeValue(tlist, environment, expbegin + 1, expend); if (null == subvalue) return false; else values.Add(subvalue); } bTest = true; } // 按位取反表达式 else if (tlist[expbegin].type == TokenType.PUNCTUATION && tlist[expbegin].text == "~") { ICLS_Expression subvalue = Compiler_Expression_NegativeBit(tlist, environment, expbegin + 1, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } // 逻辑反表达式 else if (tlist[expbegin].type == TokenType.PUNCTUATION && tlist[expbegin].text == "!") { ICLS_Expression subvalue = Compiler_Expression_NegativeLogic(tlist, environment, expbegin + 1, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } if (!bTest && tlist[expbegin].type == TokenType.TYPE) { //定义表达式或者定义并赋值表达式 if (tlist[expbegin + 1].type == TokenType.IDENTIFIER) { if (expend == expbegin + 1) { //定义表达式 ICLS_Expression subvalue = Compiler_Expression_Define(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (expend > expbegin + 2 && tlist[expbegin + 2].type == TokenType.PUNCTUATION && tlist[expbegin + 2].text == "=") { //定义并赋值表达式 ICLS_Expression subvalue = Compiler_Expression_DefineAndSet(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else { LogError(tlist,"无法识别的表达式:", expbegin ,expend); return false; } } else if (tlist[expbegin + 1].text == "[" && tlist[expbegin + 2].text == "]" && tlist[expbegin + 3].type == TokenType.IDENTIFIER)//定义表达式或者定义并赋值表达式 { if (expend == expbegin + 3) { //定义表达式 ICLS_Expression subvalue = Compiler_Expression_DefineArray(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (expend > expbegin + 4 && tlist[expbegin + 4].type == TokenType.PUNCTUATION && tlist[expbegin + 4].text == "=") { //定义并赋值表达式 ICLS_Expression subvalue = Compiler_Expression_DefineAndSetArray(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else { LogError(tlist, "无法识别的表达式:", expbegin, expend); return false; } } else if (tlist[expbegin + 1].type == TokenType.PUNCTUATION && tlist[expbegin + 1].text == ".") { //静态调用表达式 ICLS_Expression subvalue = Compiler_Expression_Math(tlist, environment, expbegin, expend); if (subvalue != null) { values.Add(subvalue); bTest = true; } else { return false; } } } if (!bTest && tlist[expbegin].type == TokenType.IDENTIFIER) { if (expend == expbegin + 1)//一元表达式 { ICLS_Expression subvalue = Compiler_Expression_MathSelf(tlist, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } if (!bTest && tlist[expbegin + 1].type == TokenType.PUNCTUATION && tlist[expbegin + 1].text == "=")//赋值表达式 { ICLS_Expression subvalue = Compiler_Expression_Set(tlist, environment,expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } } if (!bTest && (tlist[expbegin].type == TokenType.IDENTIFIER || tlist[expbegin].type == TokenType.VALUE || tlist[expbegin].type == TokenType.STRING)) { //算数表达式 ICLS_Expression subvalue = Compiler_Expression_Math(tlist, environment, expbegin, expend); if (null != subvalue) { values.Add(subvalue); bTest = true; } } if (!bTest && tlist[expbegin].type == TokenType.KEYWORD) { if (tlist[expbegin].text == "for") { ICLS_Expression subvalue = Compiler_Expression_Loop_For(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (tlist[expbegin].text == "foreach") { ICLS_Expression subvalue = Compiler_Expression_Loop_ForEach(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (tlist[expbegin].text == "while") { ICLS_Expression subvalue = Compiler_Expression_Loop_While(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (tlist[expbegin].text == "do") { ICLS_Expression subvalue = Compiler_Expression_Loop_Dowhile(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (tlist[expbegin].text == "if") { ICLS_Expression subvalue = Compiler_Expression_Loop_If(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (tlist[expbegin].text == "return") { ICLS_Expression subvalue = Compiler_Expression_Loop_Return(tlist, environment,expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (tlist[expbegin].text == "throw") { ICLS_Expression subvalue = Compiler_Expression_FunctionThrow(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if(tlist[expbegin].text=="true"||tlist[expbegin].text=="false"||tlist[expbegin].text=="null") { //算数表达式 ICLS_Expression subvalue = Compiler_Expression_Math(tlist, environment, expbegin, expend); if (null != subvalue) { values.Add(subvalue); bTest = true; } } else if(tlist[expbegin].text=="new") { //new 表达式 if (tlist[expbegin + 1].type == TokenType.TYPE) { ICLS_Expression subvalue = Compiler_Expression_FunctionNew(tlist, environment, pos, posend); values.Add(subvalue); bTest = true; } } else if (tlist[expbegin].text == "yield") { ICLS_Expression subvalue = Compiler_Expression_FunctionYield(tlist, environment, expbegin, expend); if (null == subvalue) return false; else values.Add(subvalue); bTest = true; } else if (tlist[expbegin].text == "try") { LogError(tlist, "try 表达式不支持也没必要", expbegin, expend); return false; } else { LogError(tlist, "无法识别的表达式:", expbegin, expend); return false; } } if (!bTest) { LogError(tlist, "无法识别的表达式:", expbegin, expend); return false; } } begin = end + 1; } while (begin <= posend); if (values.Count == 1) { value = values[0]; } else if (values.Count > 1) { LogError(tlist, "异常表达式", pos, posend); } return true; }
IList<ICLS_Type> _FileCompiler(string filename, IList<Token> tokens, bool embDeubgToken, ICLS_Environment env, bool onlyGotType = false) { m_curFileName = filename; List<ICLS_Type> typelist = new List<ICLS_Type>(); for (int i = 0; i < tokens.Count; i++) { if (tokens[i].type == TokenType.PUNCTUATION && tokens[i].text == ";") continue; if (tokens[i].type == TokenType.KEYWORD && tokens[i].text == "class") { string className = tokens[i + 1].text; // 在这里检查继承 List<string> baseClassNames = null; int ibegin = i + 2; if (onlyGotType) { while (tokens[ibegin].text != "{") { ibegin++; } } else { if (tokens[ibegin].text == ":") { baseClassNames = new List<string>(); ibegin++; } while (tokens[ibegin].text != "{") { if (tokens[ibegin].type == TokenType.TYPE) { baseClassNames.Add(tokens[ibegin].text); } ibegin++; } } int iend = FindBlock(env, tokens, ibegin); if (iend == -1) { env.logger.Log_Error("查找文件尾失败。"); return null; } if (onlyGotType) { env.logger.Log("(scriptPreParser)findclass:" + className + "(" + ibegin + "," + iend + ")"); } else { env.logger.Log("(scriptParser)findclass:" + className + "(" + ibegin + "," + iend + ")"); } ICLS_Type type = Compiler_Class(env, className, baseClassNames, filename, tokens, ibegin, iend, embDeubgToken, onlyGotType, null); if (type != null) { typelist.Add(type); } i = iend; continue; } } return typelist; }
public IList<ICLS_Type> FileCompiler(ICLS_Environment env,string filename,IList<Token> tlist, bool embDebugToken) { return _FileCompiler(filename, tlist, embDebugToken, env, false); }
ICLS_Type Compiler_Class(ICLS_Environment env, string classname, IList<string> baseTypeNames, string filename, IList<Token> tokens, int ibegin, int iend, bool EmbDebugToken, bool onlyGotType = false, IList<string> usinglist = null) { CLS_Type_Class sClass = env.GetTypeByKeywordQuiet(classname) as CLS_Type_Class; if (sClass == null) sClass = new CLS_Type_Class(classname, filename); sClass.compiled = false; (sClass.function as SType).functions.Clear(); (sClass.function as SType).members.Clear(); if (onlyGotType) return sClass; // 调试Token if (EmbDebugToken) (sClass.function as SType).EmbDebugToken(tokens); bool bStatic = false; int sortIndex = 0; for (int i = ibegin; i <= iend; i++) { if (tokens[i].type == TokenType.KEYWORD && tokens[i].text == "static") { bStatic = true; continue; } if (tokens[i].type == TokenType.ProtoIndex) { sortIndex = int.Parse(tokens[i].text); continue; } if (tokens[i].type == TokenType.TYPE || (tokens[i].type == TokenType.IDENTIFIER && tokens[i].text == classname))//发现类型 { ICLS_Type idtype = env.GetTypeByKeyword("null"); bool bctor = false; if (tokens[i].type == TokenType.TYPE) { if (tokens[i].text == classname && tokens[i + 1].text == "(") { //构造函数 bctor = true; i--; } else if (tokens[i + 1].text == "[" && tokens[i + 2].text == "]") { idtype = env.GetTypeByKeyword(tokens[i].text + "[]"); i += 2; } else if (tokens[i].text == "void") { } else { idtype = env.GetTypeByKeyword(tokens[i].text); } } if (tokens[i + 1].type == CSLE.TokenType.IDENTIFIER || bctor) //类型后面是名称 { string idname = tokens[i + 1].text; if (tokens[i + 2].type == CSLE.TokenType.PUNCTUATION && tokens[i + 2].text == "(")//参数开始,这是函数 { logger.Log("发现函数:" + idname); SType.Function func = new SType.Function(); func.bStatic = bStatic; int funcparambegin = i + 2; int funcparamend = FindBlock(env, tokens, funcparambegin); if (funcparamend - funcparambegin > 1) { int start = funcparambegin + 1; for (int j = funcparambegin + 1; j <= funcparamend; j++) { if (tokens[j].text == "," || tokens[j].text == ")") { string ptype = ""; for (int k = start; k <= j - 2; k++) ptype += tokens[k].text; var pid = tokens[j - 1].text; var type = env.GetTypeByKeyword(ptype); if (type == null) { throw new Exception(filename + ":不可识别的函数头参数:" + tokens[funcparambegin].ToString()); } func._paramnames.Add(pid); func._paramtypes.Add(type); start = j + 1; } } } int funcbegin = funcparamend + 1; if (tokens[funcbegin].text == "{") { bool coroutine = tokens[i].text == "IEnumerator"; int funcend = FindBlock(env, tokens, funcbegin); this.Compiler_Expression_Block(tokens, env, funcbegin, funcend, out func.expr_runtime); // Unity协程判断 if (coroutine) { int yieldCount = 0; if (func.expr_runtime is CLS_Expression_Yield) { yieldCount++; } else { foreach (var v1 in func.expr_runtime.listParam) { if (v1 is CLS_Expression_Yield) { yieldCount++; } else if (v1 is CLS_Expression_LoopIf) { if (v1.listParam[1] is CLS_Expression_Yield) { yieldCount++; } else if (v1.listParam[1] is CLS_Expression_Block) { if (v1.listParam[1].listParam[v1.listParam[1].listParam.Count - 1] is CLS_Expression_Yield) { yieldCount++; } } } else if (v1 is CLS_Expression_LoopFor) { if (v1.listParam[3] is CLS_Expression_Yield) { yieldCount++; } else if (v1.listParam[3] is CLS_Expression_Block) { foreach (var v2 in v1.listParam[3].listParam) { if (v2 is CLS_Expression_Yield) { yieldCount++; } } } } } } // 暂不支持复杂嵌套的yield表达式 if (yieldCount != m_tempYieldCount) { throw new Exception(filename + "暂不支持复杂嵌套的yield表达式: " + tokens[funcbegin].ToString()); } var expr = func.expr_runtime; func.expr_runtime = new CLS_Expression_Coroutine(expr.listParam, expr.tokenBegin, expr.tokenEnd, expr.lineBegin, expr.lineEnd); } m_tempYieldCount = 0; // 判断是否是派生类的构造函数 if (baseTypeNames != null && baseTypeNames.Count > 0 && bctor) { CLS_Expression_Function baseFun = new CLS_Expression_Function(funcbegin, funcend, tokens[funcbegin].line, tokens[funcbegin].line); baseFun.funcname = classname + "->base"; func.addBaseFun(baseFun, funcbegin, funcend, tokens[funcbegin].line, tokens[funcend].line); } (sClass.function as SType).addFun(idname, func); i = funcend; } else if (tokens[funcbegin].text == ";") { func.expr_runtime = null; (sClass.function as SType).addFun(idname, func); i = funcbegin; } else if (tokens[funcbegin].text == ":") { // 添加 :base()的构造函数 支持 int funcbegin2 = funcbegin; for (; funcbegin2 < iend; funcbegin2++) { if (tokens[funcbegin2].text == "{") { CLS_Expression_Function baseFun = (CLS_Expression_Function)this.Compiler_Expression_Function(tokens, env, funcbegin + 1, funcbegin2 - 1); baseFun.funcname = classname + "->base"; int funcend2 = FindBlock(env, tokens, funcbegin2); this.Compiler_Expression_Block(tokens, env, funcbegin2, funcend2, out func.expr_runtime); func.addBaseFun(baseFun, funcbegin, funcend2, tokens[funcbegin].line, tokens[funcend2].line); (sClass.function as SType).addFun(idname, func); i = funcend2; break; } } } else { throw new Exception(filename + "不可识别的函数表达式" + tokens[funcbegin].ToString()); } } else if (tokens[i + 2].type == CSLE.TokenType.PUNCTUATION && tokens[i + 2].text == "{")//语句块开始,这是 getset属性 { logger.Log("发现Get/Set:" + idname); SType.Member member = new SType.Member(); member.bStatic = bStatic; member.sortIndex = sortIndex; member.type = idtype; i += 3; for (int count = 2; count > 0; count--) { if (tokens[i].text == "get") { // get 函数定义 if (tokens[i + 1].text == "{") { member.getFun = "get_" + idname; SType.Function getFunc = new SType.Function(); getFunc.bStatic = bStatic; int funcbegin = i + 1; int funcend = FindBlock(env, tokens, funcbegin); this.Compiler_Expression_Block(tokens, env, funcbegin, funcend, out getFunc.expr_runtime); (sClass.function as SType).addFun(member.getFun, getFunc); i = funcend + 1; } else { i += 2; // get; 模式 } } else if (tokens[i].text == "set") { // set 函数定义 if (tokens[i + 1].text == "{") { member.setFun = "set_" + idname; SType.Function setFunc = new SType.Function(); setFunc.bStatic = bStatic; setFunc._paramnames.Add("value"); setFunc._paramtypes.Add(member.type); int funcbegin = i + 1; int funcend = FindBlock(env, tokens, funcbegin); this.Compiler_Expression_Block(tokens, env, funcbegin, funcend, out setFunc.expr_runtime); (sClass.function as SType).addFun(member.setFun, setFunc); i = funcend + 1; } else { i += 2; // set; 模式 } } else if (tokens[i].text == "}") { // get/set块结束 break; } else { throw new Exception(filename + "不可识别的Get/Set" + tokens[i].ToString()); } } (sClass.function as SType).addMember(idname, member); } else if (tokens[i + 2].type == CSLE.TokenType.PUNCTUATION && (tokens[i + 2].text == "=" || tokens[i + 2].text == ";"))//这是成员定义 { logger.Log("发现成员定义:" + idname); SType.Member member = new SType.Member(); member.bStatic = bStatic; member.sortIndex = sortIndex; member.type = idtype; if (tokens[i + 2].text == "=") { int posend = 0; for (int j = i; j < iend; j++) { if (tokens[j].text == ";") { posend = j - 1; break; } } int jbegin = i + 3; int jdep; int jend = FindCodeAny(tokens, ref jbegin, out jdep); if (jend < posend) { jend = posend; } if (!Compiler_Expression(tokens, env, jbegin, jend, out member.expr_defvalue)) { logger.Log_Error("Get/Set定义错误"); } i = jend; } (sClass.function as SType).addMember(idname, member); } bStatic = false; sortIndex = 0; continue; } else { throw new Exception(filename + "不可识别的表达式" + tokens[i].ToString()); } } } sClass.compiled = true; // 关联基类(目前只支持单继承) if (baseTypeNames != null && baseTypeNames.Count > 0) { SType sBaseType = env.GetTypeByKeywordQuiet(baseTypeNames[0]).function as SType; SType sType = sClass.function as SType; sType.BaseType = sBaseType; bool hasBaseFun = false; foreach (KeyValuePair<string, SType.Function> pair in sBaseType.functions) { if (!sType.functions.ContainsKey(pair.Key)) { if (sBaseType.Name.Equals(pair.Key)) { hasBaseFun = true; sType.functions.Add(sType.Name + "->base", pair.Value); } else { if (pair.Value.ownerType == null) pair.Value.ownerType = sBaseType; sType.functions.Add(pair.Key, pair.Value); } } } foreach (KeyValuePair<string, SType.Member> pair in sBaseType.members) { if (!sType.members.ContainsKey(pair.Key)) sType.members.Add(pair.Key, pair.Value); } foreach (KeyValuePair<string, SType.Member> pair in sBaseType.propertys) { if (!sType.propertys.ContainsKey(pair.Key)) sType.propertys.Add(pair.Key, pair.Value); } // 自动创建可以调用基类函数的构造函数 if (!sType.functions.ContainsKey(sType.Name) && hasBaseFun) { // 处理 自身没构造函数 -- 基类有构造函数 的情况 SType.Function func = new SType.Function(); func.bStatic = false; CLS_Expression_Function baseFun = new CLS_Expression_Function(0, 0, 0, 0); baseFun.funcname = sType.Name + "->base"; func.addBaseFun(baseFun, 0, 0, 0, 0); sType.functions.Add(sType.Name, func); } else if (sType.functions.ContainsKey(sType.Name) && !hasBaseFun) { // 处理 自身有构造函数 -- 基类没有构造函数 的情况 SType.Function func = new SType.Function(); func.bStatic = false; sType.functions.Add(sType.Name + "->base", func); } } return sClass; }
int FindBlock(ICLS_Environment env, IList<CSLE.Token> tokens, int start) { if (tokens[start].type != CSLE.TokenType.PUNCTUATION) { env.logger.Log_Error("(script)FindBlock 没有从符号开始"); } string left = tokens[start].text; string right = "}"; if (left == "{") right = "}"; if (left == "(") right = ")"; if (left == "[") right = "]"; int depth = 0; for (int i = start; i < tokens.Count; i++) { if (tokens[i].type == CSLE.TokenType.PUNCTUATION) { if (tokens[i].text == left) { depth++; } else if (tokens[i].text == right) { depth--; if (depth == 0) { return i; } } } } return -1; }
public ICLS_Expression Compiler_Expression_FunctionYield(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { m_tempYieldCount++; CLS_Expression_Yield func = new CLS_Expression_Yield(pos, posend, tlist[pos].line, tlist[posend].line); ICLS_Expression subvalue; bool succ = Compiler_Expression(tlist, content, pos + 1, posend, out subvalue); if (succ) { func.listParam.Add(subvalue); } return func; }
public ICLS_Expression Compiler_Expression_FunctionNew(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { int begin = pos + 3; int dep; int end = FindCodeAnyInFunc(tlist, ref begin, out dep); if (tlist[pos + 2].type == TokenType.PUNCTUATION && tlist[pos + 2].text == "(") { //一般函数 CLS_Expression_FunctionNew func = new CLS_Expression_FunctionNew(pos, posend, tlist[pos].line, tlist[posend].line); func.type = content.GetTypeByKeyword(tlist[pos + 1].text); do { ICLS_Expression param; bool succ = Compiler_Expression(tlist, content, begin, end, out param); if (succ && param != null) { func.listParam.Add(param); } begin = end + 2; end = FindCodeAnyInFunc(tlist, ref begin, out dep); } while (end < posend && begin <= end); return func; } else if (tlist[pos + 2].type == TokenType.PUNCTUATION && tlist[pos + 2].text == "[")//数组实例化表达式 { CLS_Expression_FunctionNewArray func = new CLS_Expression_FunctionNewArray(pos, posend, tlist[pos].line, tlist[posend].line); func.type = content.GetTypeByKeyword(tlist[pos + 1].text + "[]"); int valuebegin = 0; ICLS_Expression count = null; if (tlist[pos + 3].text == "]") { valuebegin = pos + 4; } else { int nbegin = pos + 3; int dep2; int end2 = FindCodeAny(tlist, ref nbegin, out dep2); bool succ = Compiler_Expression(tlist, content, nbegin, end2, out count); if (!succ) { throw new Exception("数组数量无法识别:" + tlist[pos].ToString()); } valuebegin = end2 + 2; } func.listParam.Add(count); if (tlist[valuebegin].text == "{")//InitValue { int nbegin = valuebegin + 1; do { int dep2; int nend = FindCodeAny(tlist, ref nbegin, out dep2); ICLS_Expression valueI; bool succ = Compiler_Expression(tlist, content, nbegin, nend, out valueI); if (!succ) { //throw new Exception("数组初始值无法识别"); } else { func.listParam.Add(valueI); } if (tlist[nend + 1].text != ",") break; nbegin = nend + 2; } while (nbegin >= pos && nbegin < posend); } return func; } return null; }
public IList<ICLS_Type> FilePreCompiler(ICLS_Environment env, string filename, IList<Token> tlist) { return _FileCompiler(filename, tlist, false, env, true); }
public ICLS_Expression Compiler_Expression_Math(IList<Token> tlist, ICLS_Environment content, int pos, int posend) { IList<int> sps = SplitExpressionWithOp(tlist, pos, posend); int oppos = GetLowestMathOp(tlist, sps); if (oppos < 0) { ////也有可能是类型转换 //if (posend >= pos + 3 && tlist[pos].text == "(" && tlist[pos].type == TokenType.PUNCTUATION && tlist[pos + 2].text == ")" && tlist[pos + 2].type == TokenType.PUNCTUATION // && tlist[pos + 1].type == TokenType.TYPE // ) //{ // ICLS_Expression v; // bool succ = Compiler_Expression(tlist, content, pos + 3, posend, out v); // CLS_Expression_TypeConvert convert = new CLS_Expression_TypeConvert(); // convert.listParam.Add(v); // convert.targettype = content.environment.GetTypeByKeyword(tlist[pos + 1].text).type; // return convert; //} //else if (tlist[pos + 1].type == TokenType.PUNCTUATION && tlist[pos + 1].text == "[")//函数表达式 //{ // return Compiler_Expression_IndexFind(tlist, content, pos, posend); //} if (tlist[pos + 1].type == TokenType.PUNCTUATION && tlist[pos + 1].text == "(")//函数表达式 { return Compiler_Expression_Function(tlist, content, pos, posend); } else { //if (!bTest && tlist[expbegin + 1].type == TokenType.PUNCTUATION && tlist[expbegin + 1].text == "(")//函数表达式 //{ // ICLS_Expression subvalue = Compiler_Expression_Function(tlist,content, expbegin, expend); // if (null == subvalue) return false; // else // values.Add(subvalue); // bTest = true; //} } return null; } Token tkCur = tlist[oppos]; if (tkCur.text == "=>") {//lambda return Compiler_Expression_Lambda(tlist, content, pos, posend); } else if (tkCur.text == "." && pos == oppos - 1 && tlist[pos].type == TokenType.TYPE) { int right = oppos + 1; int rightend = posend; ICLS_Expression valueright; bool succ2 = Compiler_Expression(tlist, content, right, rightend, out valueright); if (succ2) { CLS_Expression_GetValue vg = valueright as CLS_Expression_GetValue; CLS_Expression_Function vf = valueright as CLS_Expression_Function; if (vg != null) { CLS_Expression_StaticFind value = new CLS_Expression_StaticFind(pos, rightend, tlist[pos].line, tlist[rightend].line); value.staticmembername = vg.value_name; value.type = content.GetTypeByKeyword(tlist[pos].text); return value; } else if (vf != null) { CLS_Expression_StaticFunction value = new CLS_Expression_StaticFunction(pos, rightend, tlist[pos].line, tlist[rightend].line); value.functionName = vf.funcname; value.type = content.GetTypeByKeyword(tlist[pos].text); //value.listParam.Add(valueleft); value.listParam.AddRange(vf.listParam.ToArray()); return value; } else if (valueright is CLS_Expression_SelfOp) { CLS_Expression_SelfOp vr = valueright as CLS_Expression_SelfOp; CLS_Expression_StaticMath value = new CLS_Expression_StaticMath(pos, rightend, tlist[pos].line, tlist[rightend].line); value.type = content.GetTypeByKeyword(tlist[pos].text); value.staticmembername = vr.value_name; value.mathop = vr.mathop; return value; } else { throw new Exception("不可识别的表达式:" + tkCur.ToString() + tkCur.SourcePos()); } } else { throw new Exception("不可识别的表达式:" + tkCur.ToString() + tkCur.SourcePos()); } } else { int left = pos; int leftend = oppos - 1; int right = oppos + 1; int rightend = posend; if (tkCur.text == "(") { ICLS_Expression v; if (!Compiler_Expression(tlist, content, oppos + 3, posend, out v)) { LogError(tlist, "编译表达式失败", right, rightend); return null; } CLS_Expression_TypeConvert convert = new CLS_Expression_TypeConvert(pos, posend, tlist[pos].line, tlist[posend].line); convert.listParam.Add(v); convert.targettype = content.GetTypeByKeyword(tlist[oppos + 1].text).type; return convert; } ICLS_Expression valueleft; bool succ1 = Compiler_Expression(tlist, content, left, leftend, out valueleft); ICLS_Expression valueright; if (tkCur.text == "[") { rightend--; if (!Compiler_Expression(tlist, content, right, rightend, out valueright)) { LogError(tlist, "编译表达式失败", right, rightend); return null; } CLS_Expression_IndexFind value = new CLS_Expression_IndexFind(left, rightend, tlist[left].line, tlist[rightend].line); value.listParam.Add(valueleft); value.listParam.Add(valueright); return value; } else if (tkCur.text == "as") { CLS_Expression_TypeConvert convert = new CLS_Expression_TypeConvert(left, oppos + 1, tlist[left].line, tlist[oppos + 1].line); convert.listParam.Add(valueleft); convert.targettype = content.GetTypeByKeyword(tlist[oppos + 1].text).type; return convert; } else if (tkCur.text == "is") { CLS_Expression_TypeCheck check = new CLS_Expression_TypeCheck(left, oppos + 1, tlist[left].line, tlist[oppos + 1].line); check.listParam.Add(valueleft); check.targettype = content.GetTypeByKeyword(tlist[oppos + 1].text).type; return check; } bool succ2 = Compiler_Expression(tlist, content, right, rightend, out valueright); if (succ1 && succ2 && valueright != null && valueleft != null) { if (tkCur.text == "=") { //member set CLS_Expression_MemberFind mfinde = valueleft as CLS_Expression_MemberFind; CLS_Expression_StaticFind sfinde = valueleft as CLS_Expression_StaticFind; CLS_Expression_IndexFind ifinde = valueleft as CLS_Expression_IndexFind; if (mfinde != null) { CLS_Expression_MemberSetValue value = new CLS_Expression_MemberSetValue(left, rightend, tlist[left].line, tlist[rightend].line); value.membername = mfinde.membername; value.listParam.Add(mfinde.listParam[0]); value.listParam.Add(valueright); return value; } else if (sfinde != null) { CLS_Expression_StaticSetValue value = new CLS_Expression_StaticSetValue(left, rightend, tlist[left].line, tlist[rightend].line); value.staticmembername = sfinde.staticmembername; value.type = sfinde.type; //value.listParam.Add(mfinde.listParam[0]); value.listParam.Add(valueright); return value; } else if (ifinde != null) { CLS_Expression_IndexSetValue value = new CLS_Expression_IndexSetValue(left, rightend, tlist[left].line, tlist[rightend].line); value.listParam.Add(ifinde.listParam[0]); value.listParam.Add(ifinde.listParam[1]); value.listParam.Add(valueright); return value; } else { throw new Exception("非法的Member Set表达式" + valueleft); } } else if (tkCur.text == ".") { //FindMember CLS_Expression_GetValue vg = valueright as CLS_Expression_GetValue; CLS_Expression_Function vf = valueright as CLS_Expression_Function; if (vg != null) { CLS_Expression_MemberFind value = new CLS_Expression_MemberFind(left, rightend, tlist[left].line, tlist[rightend].line); value.listParam.Add(valueleft); value.membername = vg.value_name; return value; } else if (vf != null) { CLS_Expression_MemberFunction value = new CLS_Expression_MemberFunction(left, rightend, tlist[left].line, tlist[rightend].line); value.functionName = vf.funcname; value.listParam.Add(valueleft); value.listParam.AddRange(vf.listParam.ToArray()); return value; } else if (valueright is CLS_Expression_SelfOp) { CLS_Expression_SelfOp vr = valueright as CLS_Expression_SelfOp; CLS_Expression_MemberMath value = new CLS_Expression_MemberMath(left, rightend, tlist[left].line, tlist[rightend].line); value.listParam.Add(valueleft); value.membername = vr.value_name; value.mathop = vr.mathop; return value; } throw new Exception("不可识别的表达式" + valueleft + "." + valueright); //value.listParam.Add(valueright); } else if (tkCur.text == "+=" || tkCur.text == "-=" || tkCur.text == "*=" || tkCur.text == "/=" || tkCur.text == "%=") { //if (valueleft is CLS_Expression_MemberFind) //{ // CLS_Expression_MemberFind vf = valueleft as CLS_Expression_MemberFind; // CLS_Expression_MemberMath value = new CLS_Expression_MemberMath(left, rightend, tlist[left].line, tlist[rightend].line); // value.listParam.Add(vf.listParam[0]); // value.membername = vf.membername; // value.mathop = tlist[oppos].text[0]; // value.listParam.Add(valueright); // return value; //} //if ((valueright is CLS_Expression_Lambda ==false) && valueleft is CLS_Expression_StaticFind) //{ // CLS_Expression_StaticFind vf = valueleft as CLS_Expression_StaticFind; // CLS_Expression_StaticMath value = new CLS_Expression_StaticMath(left, rightend, tlist[left].line, tlist[rightend].line); // value.type = vf.type; // value.staticmembername = vf.staticmembername; // value.mathop = tlist[oppos].text[0]; // value.listParam.Add(valueright); // return value; //} //else { CLS_Expression_SelfOpWithValue value = new CLS_Expression_SelfOpWithValue(left, rightend, tlist[left].line, tlist[rightend].line); //value.value_name = ((CLS_Expression_GetValue)valueleft).value_name; value.listParam.Add(valueleft); value.listParam.Add(valueright); value.mathop = tkCur.text[0]; return value; } } else if (tkCur.text == "&&" || tkCur.text == "||") { CLS_Expression_Math2ValueAndOr value = new CLS_Expression_Math2ValueAndOr(left, rightend, tlist[left].line, tlist[rightend].line); value.listParam.Add(valueleft); value.listParam.Add(valueright); value.mathop = tkCur.text[0]; return value; } else if (tkCur.text == ">" || tkCur.text == ">=" || tkCur.text == "<" || tkCur.text == "<=" || tkCur.text == "==" || tkCur.text == "!=") { CLS_Expression_Math2ValueLogic value = new CLS_Expression_Math2ValueLogic(left, rightend, tlist[left].line, tlist[rightend].line); value.listParam.Add(valueleft); value.listParam.Add(valueright); logictoken token = logictoken.not_equal; if (tkCur.text == ">") { token = logictoken.more; } else if (tkCur.text == ">=") { token = logictoken.more_equal; } else if (tkCur.text == "<") { token = logictoken.less; } else if (tkCur.text == "<=") { token = logictoken.less_equal; } else if (tkCur.text == "==") { token = logictoken.equal; } else if (tkCur.text == "!=") { token = logictoken.not_equal; } value.mathop = token; return value; } else { char mathop = tkCur.text[0]; if (mathop == '?') { CLS_Expression_Math3Value value = new CLS_Expression_Math3Value(left, rightend, tlist[left].line, tlist[rightend].line); value.listParam.Add(valueleft); CLS_Expression_Math2Value vvright = valueright as CLS_Expression_Math2Value; if (vvright.mathop != ':') throw new Exception("三元表达式异常" + tkCur.ToString() + tkCur.SourcePos()); value.listParam.Add(vvright.listParam[0]); value.listParam.Add(vvright.listParam[1]); return value; } else { CLS_Expression_Math2Value value = new CLS_Expression_Math2Value(left, rightend, tlist[left].line, tlist[rightend].line); value.listParam.Add(valueleft); value.listParam.Add(valueright); value.mathop = mathop; return value; } } } else { LogError(tlist, "编译表达式失败", right, rightend); } } return null; }