Пример #1
0
        public ICLS_Expression Compiler_Expression_Function(IList <Token> tlist, CLS_Content content, int pos, int posend)
        {
            CLS_Expression_Function func = new CLS_Expression_Function(pos, posend);

            func.funcname = tlist[pos].text;
            int begin = pos + 2;
            int dep;
            int end = FindCodeAny(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;
                    }
                    begin = end + 2;
                    end   = FindCodeAnyInFunc(tlist, ref begin, out dep);
                }while (end < posend && begin <= end);


                return(func);
            }
            //一般函数
            return(null);
        }
Пример #2
0
        public ICLS_Expression Compiler_Expression_FunctionStatic(IList<Token> tlist, CLS_Content content, int pos, int posend)
        {
            CLS_Expression_Function func = new CLS_Expression_Function(pos,posend);
            func.funcname = tlist[pos].text;
            int begin = pos + 2;
            int dep;
            int end = FindCodeAny(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;
                    }
                    begin = end + 2;
                    end = FindCodeAny(tlist, ref begin, out dep);

                }
                while (end < posend && begin <= end);

                return func;
            }
            //一般函数
            return null;
        }
Пример #3
0
        public ICLS_Expression Compiler_Expression_FunctionTrace(IList <Token> tlist, CLS_Content 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 = FindCodeAny(tlist, ref begin, out dep);

            if (end != posend)
            {
                return(null);
            }
            CLS_Expression_Function func = new CLS_Expression_Function(pos, end);

            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;
                }
                begin = end + 2;
                end   = FindCodeAny(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&&param0!=null)
            //{
            //    func.listParam.Add(param0);
            //    return func;

            //}
            return(func);
            //trace ,单值直接dump,否则按逗号分隔的表达式处理

            //return null;
        }
Пример #4
0
        public ICLS_Expression Compiler_Expression_Math(IList <Token> tlist, CLS_Content 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);
                }
            }
            else if (tlist[oppos].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);
                        value.staticmembername = vg.value_name;
                        value.type             = content.environment.GetTypeByKeyword(tlist[pos].text);
                        return(value);
                    }
                    else if (vf != null)
                    {
                        CLS_Expression_StaticFunction value = new CLS_Expression_StaticFunction(pos, rightend);
                        value.functionName = vf.funcname;
                        value.type         = content.environment.GetTypeByKeyword(tlist[pos].text);
                        //value.listParam.Add(valueleft);
                        value.listParam.AddRange(vf.listParam.ToArray());
                        return(value);
                    }
                    else
                    {
                        throw new Exception("不可识别的表达式");
                    }
                }
                else
                {
                    throw new Exception("不可识别的表达式");
                }
            }
            else
            {
                int left     = pos;
                int leftend  = oppos - 1;
                int right    = oppos + 1;
                int rightend = posend;
                if (tlist[oppos].text == "(")
                {
                    ICLS_Expression            v;
                    bool                       succ    = Compiler_Expression(tlist, content, oppos + 3, posend, out v);
                    CLS_Expression_TypeConvert convert = new CLS_Expression_TypeConvert(pos, posend);
                    convert.listParam.Add(v);
                    convert.targettype = content.environment.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 (tlist[oppos].text == "[")
                {
                    rightend--;
                    bool succs = Compiler_Expression(tlist, content, right, rightend, out valueright);
                    CLS_Expression_IndexFind value = new CLS_Expression_IndexFind(left, rightend);
                    value.listParam.Add(valueleft);
                    value.listParam.Add(valueright);
                    return(value);
                }
                else if (tlist[oppos].text == "as")
                {
                    CLS_Expression_TypeConvert convert = new CLS_Expression_TypeConvert(left, oppos + 1);
                    convert.listParam.Add(valueleft);
                    convert.targettype = content.environment.GetTypeByKeyword(tlist[oppos + 1].text).type;


                    return(convert);
                }
                bool succ2 = Compiler_Expression(tlist, content, right, rightend, out valueright);
                if (succ1 && succ2 && valueright != null && valueleft != null)
                {
                    if (tlist[oppos].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);
                            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);
                            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);
                            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 (tlist[oppos].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);
                            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);
                            value.functionName = vf.funcname;
                            value.listParam.Add(valueleft);
                            value.listParam.AddRange(vf.listParam.ToArray());
                            return(value);
                        }

                        else
                        {
                            throw new Exception("不可识别的表达式" + valueleft + "." + valueright);
                        }

                        //value.listParam.Add(valueright);
                    }
                    else if (tlist[oppos].text == "+=" || tlist[oppos].text == "-=" || tlist[oppos].text == "*=" || tlist[oppos].text == "/=" || tlist[oppos].text == "%=")
                    {
                        CLS_Expression_SelfOpWithValue value = new CLS_Expression_SelfOpWithValue(left, rightend);
                        value.value_name = ((CLS_Expression_GetValue)valueleft).value_name;
                        value.listParam.Add(valueright);
                        value.mathop = tlist[oppos].text[0];
                        return(value);
                    }
                    else if (tlist[oppos].text == "&&" || tlist[oppos].text == "||")
                    {
                        CLS_Expression_Math2ValueAndOr value = new CLS_Expression_Math2ValueAndOr(left, rightend);
                        value.listParam.Add(valueleft);
                        value.listParam.Add(valueright);
                        value.mathop = tlist[oppos].text[0];
                        return(value);
                    }
                    else if (tlist[oppos].text == ">" || tlist[oppos].text == ">=" || tlist[oppos].text == "<" || tlist[oppos].text == "<=" || tlist[oppos].text == "==" || tlist[oppos].text == "!=")
                    {
                        CLS_Expression_Math2ValueLogic value = new CLS_Expression_Math2ValueLogic(left, rightend);
                        value.listParam.Add(valueleft);
                        value.listParam.Add(valueright);
                        logictoken token = logictoken.not_equal;
                        if (tlist[oppos].text == ">")
                        {
                            token = logictoken.more;
                        }
                        else if (tlist[oppos].text == ">=")
                        {
                            token = logictoken.more_equal;
                        }
                        else if (tlist[oppos].text == "<")
                        {
                            token = logictoken.less;
                        }
                        else if (tlist[oppos].text == "<=")
                        {
                            token = logictoken.less_equal;
                        }
                        else if (tlist[oppos].text == "==")
                        {
                            token = logictoken.equal;
                        }
                        else if (tlist[oppos].text == "!=")
                        {
                            token = logictoken.not_equal;
                        }
                        value.mathop = token;
                        return(value);
                    }
                    else
                    {
                        char mathop = tlist[oppos].text[0];
                        if (mathop == '?')
                        {
                            CLS_Expression_Math3Value value = new CLS_Expression_Math3Value(left, rightend);
                            value.listParam.Add(valueleft);

                            CLS_Expression_Math2Value vvright = valueright as CLS_Expression_Math2Value;
                            if (vvright.mathop != ':')
                            {
                                throw new Exception("三元表达式异常");
                            }
                            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);
                            value.listParam.Add(valueleft);
                            value.listParam.Add(valueright);
                            value.mathop = mathop;
                            return(value);
                        }
                    }
                }
                else
                {
                    LogError(tlist, "编译表达式失败", right, rightend);
                }
            }

            return(null);
        }
Пример #5
0
        public ICLS_Expression Compiler_Expression_FunctionTrace(IList<Token> tlist, CLS_Content 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= FindCodeAny(tlist,ref begin,out dep);
            if(end!=posend)
            {
                return null;
            }
            CLS_Expression_Function func = new CLS_Expression_Function(pos,end);
            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;
                }
                begin = end + 2;
                end = FindCodeAny(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&&param0!=null)
            //{
            //    func.listParam.Add(param0);
            //    return func;

            //}
            return func;
            //trace ,单值直接dump,否则按逗号分隔的表达式处理

            //return null;
        }