Пример #1
0
        public static ICQ_Expression Compiler_Expression_Lambda(IList <Token> tlist, int pos, int posend)
        {
            int b1;
            int fs1 = pos;
            int fe1 = FindCodeAny(tlist, ref fs1, out b1);
            CQ_Expression_Lambda value = new CQ_Expression_Lambda(pos, posend, tlist[pos].line, tlist[posend].line);

            int testbegin = fs1 + 1;

            if (b1 != 1)
            {
                return(null);
            }
            //(xxx)=>{...}
            CQ_Expression_Block block = new CQ_Expression_Block(fs1, fe1, tlist[fs1].line, tlist[fe1].line);

            do
            {
                int fe2 = FindCodeAny(tlist, ref testbegin, out b1);

                ICQ_Expression subvalue;
                bool           succ = Compiler_Expression(tlist, testbegin, fe2, out subvalue);
                if (!succ)
                {
                    break;
                }
                if (subvalue != null)
                {
                    block._expressions.Add(subvalue);
                    testbegin = fe2 + 2;
                }
                else
                {
                    block._expressions.Add(null);
                    testbegin = fe2 + 2;
                }
            }while(testbegin <= fe1);

            value._expressions.Add(block);
            //(...)=>{}
            ICQ_Expression subvalueblock;

            int  b2;
            int  fs2    = fe1 + 2;
            int  fecode = FindCodeAny(tlist, ref fs2, out b2);
            bool succ2  = Compiler_Expression_Block(tlist, fs2, fecode, out subvalueblock);

            if (succ2)
            {
                //value.tokenEnd = fecode;
                //value.lineEnd = tlist[fecode].line;
                value._expressions.Add(subvalueblock);
                return(value);
            }
            return(null);
        }
Пример #2
0
        public static bool Compiler_Expression_Block(IList <Token> tlist, int pos, int posend, out ICQ_Expression value)
        {
            int begin = pos;

            value = null;
            List <ICQ_Expression> values = new List <ICQ_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)
                {
                    //DebugUtil.LogError(tlist, "括号块识别失败", expbegin, expend);
                    return(true);
                }
                if (bdep == 2) //编译块表达式
                {
                    expbegin++;
                    expend--;
                    ICQ_Expression subvalue;
                    bool           bsucc = Compiler_Expression_Block(tlist, expbegin, expend, out subvalue);
                    if (bsucc)
                    {
                        if (subvalue != null)
                        {
                            values.Add(subvalue);
                        }
                    }
                    else
                    {
                        DebugUtil.LogError(tlist, "表达式编译失败", expbegin, expend);
                        return(false);
                    }
                }
                else
                {
                    ICQ_Expression subvalue;
                    bool           bsucc = Compiler_Expression(tlist, expbegin, expend, out subvalue);
                    if (bsucc)
                    {
                        if (subvalue != null)
                        {
                            values.Add(subvalue);
                        }
                    }
                    else
                    {
                        DebugUtil.LogError(tlist, "表达式编译失败", expbegin, expend);
                        return(false);
                    }
                }

                begin = end + 1;
            }while(begin <= posend);
            if (values.Count == 1)
            {
                value = values[0];
            }
            else if (values.Count > 1)
            {
                CQ_Expression_Block block = new CQ_Expression_Block(pos, end, tlist[pos].line, tlist[end].line);
                foreach (var v in values)
                {
                    block._expressions.Add(v);
                }
                value = block;
            }
            return(true);
        }