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_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 void addBaseFun(ICLS_Expression baseFun, int tbegin, int tend, int lbegin, int lend) { if (expr_runtime == null) { expr_runtime = baseFun; } else if (!(expr_runtime is CLS_Expression_Block)) { CLS_Expression_Block baseBlock = new CLS_Expression_Block(tbegin, tend, lbegin, lend); baseBlock.listParam.Add(baseFun); baseBlock.listParam.Add(expr_runtime); expr_runtime = baseBlock; } else { expr_runtime.listParam.Insert(0, baseFun); } }
// 可以搞出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_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) { //LogError(tlist, "括号块识别失败", 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 { LogError(tlist, "表达式编译失败", expbegin, expend); 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 { LogError(tlist, "表达式编译失败", expbegin, expend); return(false); } } begin = end + 1; }while (begin <= posend); if (values.Count == 1) { value = values[0]; } else if (values.Count > 1) { CLS_Expression_Block block = new CLS_Expression_Block(pos, end, tlist[pos].line, tlist[end].line); foreach (var v in values) { block.listParam.Add(v); } value = block; } return(true); }