예제 #1
0
        public ICLS_Expression Compiler_Expression_FunctionNew(IList<Token> tlist, CLS_Content content, int pos, int posend)
        {
            CLS_Expression_FunctionNew func = new CLS_Expression_FunctionNew(pos,posend);
            func.type =content.environment.GetTypeByKeyword( tlist[pos+1].text);
            int begin = pos + 3;
            int dep;
            int end = FindCodeAny(tlist, ref begin, out dep);

            if (tlist[pos + 2].type == TokenType.PUNCTUATION && tlist[pos + 2].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 = FindCodeAny(tlist, ref begin, out dep);

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

                return func;
            }
            //一般函数
            return null;
        }
예제 #2
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            ICLS_Expression expr_if = listParam[0];
            bool bif = (bool)expr_if.ComputeValue(content).value;
            //if (expr_init != null) expr_init.ComputeValue(content);
            ICLS_Expression expr_go1 = listParam[1];
            ICLS_Expression expr_go2 = null;
            if(listParam.Count>2)expr_go2= listParam[2];
            CLS_Content.Value value = null;
            if (bif && expr_go1 != null)
            {

                value= expr_go1.ComputeValue(content);

            }
            else if (!bif && expr_go2 != null)
            {

                value= expr_go2.ComputeValue(content);

            }

            //while((bool)expr_continue.value);

            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return value;
        }
예제 #3
0
        public ICLS_Expression Compiler(IList <Token> tlist, CLS_Content 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);
            }
        }
예제 #4
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            if (_listParam != null && _listParam.Count > 0)
            {
                CLS_Content.Value v = _listParam[0].ComputeValue(content);
                object val = v.value;
                if (value_type==typeof(CLS_Type_Var.var))
                {
                    if(v.type!=null)
                        value_type = v.type;

                }
                else if (v.type != value_type)
                {
                    val = content.environment.GetType(v.type).ConvertTo(content.environment, v.value, value_type);

                }

                content.DefineAndSet(value_name, value_type, val);
            }
            else
            {
                content.Define(value_name, value_type);
            }
            //设置环境变量为
            content.OutStack(this);

            return null;
        }
예제 #5
0
 public ICLS_Expression Compiler_Expression_DefineAndSet(IList<Token> tlist, CLS_Content 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);
         if (tlist[pos].text == "bool")
         {
             define.value_type = typeof(bool);
         }
         else
         {
             ICLS_Type type = content.environment.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;
 }
예제 #6
0
 public ICLS_Expression Compiler_Expression_NegativeValue(IList<Token> tlist, CLS_Content 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);
             v.listParam.Add(subvalue);
             return v;
         }
         else
         {
             LogError(tlist, "无法识别的负号表达式:", expbegin, posend);
             return null;
         }
     }
 }
예제 #7
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            CLS_Content.Value rv = new CLS_Content.Value();
            rv.breakBlock = 10;
            if (listParam.Count > 0 && listParam[0] != null)
            {
                var v = listParam[0].ComputeValue(content);
                {
                    rv.type  = v.type;
                    rv.value = v.value;
                }
            }
            else
            {
                rv.type = typeof(void);
            }
            content.OutStack(this);
            return(rv);

            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
 public CLS_Content.Value ComputeValue(CLS_Content content)
 {
     content.InStack(this);
     var value=type.function.StaticValueGet(content.environment, staticmembername);
     content.OutStack(this);
     return value;
 }
예제 #9
0
        public ICLS_Expression Compiler(IList<Token> tlist, CLS_Content 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;
            }
        }
예제 #10
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;
        }
예제 #11
0
        public object Math2Value(CLS_Environment env, char code, object left, CLS_Content.Value right, out Type returntype)
        {
            returntype = typeof(double);
            if (right.type == typeof(int))
            {
                if (code == '+')
                    return (double)left + (double)(int)right.value;
                else if (code == '-')
                    return (double)left - (double)(int)right.value;
                else if (code == '*')
                    return (double)left * (double)(int)right.value;
                else if (code == '/')
                    return (double)left / (double)(int)right.value;
                else if (code == '%')
                    return (double)left % (double)(int)right.value;
            }
            else if (right.type == typeof(uint))
            {
                if (code == '+')
                    return (double)left + (double)(uint)right.value;
                else if (code == '-')
                    return (double)left - (double)(uint)right.value;
                else if (code == '*')
                    return (double)left * (double)(uint)right.value;
                else if (code == '/')
                    return (double)left / (double)(uint)right.value;
                else if (code == '%')
                    return (double)left % (double)(uint)right.value;
            }
            else if (right.type == typeof(double))
            {
                returntype = typeof(double);

                if (code == '+')
                    return (double)left + (double)right.value;
                else if (code == '-')
                    return (double)left - (double)right.value;
                else if (code == '*')
                    return (double)left * (double)right.value;
                else if (code == '/')
                    return (double)left / (double)right.value;
                else if (code == '%')
                    return (double)left % (double)right.value;
            }
            else if (right.type == typeof(float))
            {
                returntype = typeof(double);
                if (code == '+')
                    return (double)left + (double)(float)right.value;
                else if (code == '-')
                    return (double)left - (double)(float)right.value;
                else if (code == '*')
                    return (double)left * (double)(float)right.value;
                else if (code == '/')
                    return (double)left / (double)(float)right.value;
                else if (code == '%')
                    return (double)left % (double)(float)right.value;
            }
            throw new NotImplementedException();
        }
예제 #12
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            ICLS_Expression expr_init = listParam[0] as ICLS_Expression;
            if (expr_init != null) expr_init.ComputeValue(content);

            ICLS_Expression expr_continue = listParam[1] as ICLS_Expression;
            ICLS_Expression expr_step = listParam[2] as ICLS_Expression;

            ICLS_Expression expr_block = listParam[3] as ICLS_Expression;

            for (; (bool)expr_continue.ComputeValue(content).value; expr_step.ComputeValue(content))
            {
                if (expr_block != null)
                {
                    var v = expr_block.ComputeValue(content);
                    if (v != null && v.breakBlock > 1) break; ;
                    //if (v.breakBlock == 1) continue;
                    //if (v.breakBlock == 2) break;
                    //if (v.breakBlock == 10) return v;
                }
            }
            content.DepthRemove();
            content.OutStack(this);
            return null;
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
예제 #13
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            var value = type.function.StaticValueGet(content.environment, staticmembername);

            content.OutStack(this);
            return(value);
        }
예제 #14
0
        public object Math2Value(CLS_Environment env, char code, object left, CLS_Content.Value right, out Type returntype)
        {
            returntype = typeof(string);
            if (code == '+')
                return (string)left + right.value.ToString();

            throw new NotImplementedException();
        }
예제 #15
0
 public CLS_Content.Value Execute(ICLS_Expression expr, CLS_Content content = null)
 {
     if (content == null)
     {
         content = CreateContent();
     }
     return(expr.ComputeValue(content));
 }
예제 #16
0
 public CLS_Content.Value ComputeValue(CLS_Content content)
 {
     content.InStack(this);
     CLS_Content.Value rv = new CLS_Content.Value();
     rv.breakBlock = 2;
     //跳出逻辑
     content.OutStack(this);
     return(rv);
 }
예제 #17
0
 public CLS_Content.Value ComputeValue(CLS_Content content)
 {
     content.InStack(this);
     CLS_Content.Value rv = new CLS_Content.Value();
     rv.breakBlock = 2;
     //跳出逻辑
     content.OutStack(this);
     return rv;
 }
예제 #18
0
 public CLS_Content.Value ComputeValue(CLS_Content content)
 {
     content.InStack(this);
     CLS_Content.Value v = new CLS_Content.Value();
     v.type  = this.type;
     v.value = null;
     content.OutStack(this);
     return(v);
 }
예제 #19
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            var value=content.Get(value_name);
            content.OutStack(this);

            //从上下文取值

            return value;
        }
예제 #20
0
        public ICLS_Expression Compiler_Expression_Loop_For(IList <Token> tlist, CLS_Content 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, fe1);

            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.listParam.Add(subvalueblock);
                return(value);
            }
            return(null);
        }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            CLS_Expression_Define define = listParam[0] as CLS_Expression_Define;

            if (define == null)
            {
            }
            define.ComputeValue(content);

            System.Collections.IEnumerable emu = listParam[1].ComputeValue(content).value as System.Collections.IEnumerable;

            ICLS_Expression expr_block = listParam[2] as ICLS_Expression;

            var it = emu.GetEnumerator();

            while (it.MoveNext())
            {
                content.Set(define.value_name, it.Current);

                if (expr_block != null)
                {
                    var v = expr_block.ComputeValue(content);
                    if (v != null && v.breakBlock > 1)
                    {
                        break;
                    }
                    ;
                }
            }
            //ICLS_Expression expr_continue = listParam[1] as ICLS_Expression;
            //ICLS_Expression expr_step = listParam[2] as ICLS_Expression;

            //ICLS_Expression expr_block = listParam[3] as ICLS_Expression;

            //for (;(bool)expr_continue.ComputeValue(content).value; expr_step.ComputeValue(content))
            //{
            //    if(expr_block!=null)
            //    {
            //        var v = expr_block.ComputeValue(content);
            //        if (v != null && v.breakBlock > 1) break; ;
            //        //if (v.breakBlock == 1) continue;
            //        //if (v.breakBlock == 2) break;
            //        //if (v.breakBlock == 10) return v;
            //    }
            //}
            content.DepthRemove();
            content.OutStack(this);
            return(null);
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
예제 #22
0
        public ICLS_Expression Compiler_Expression_Loop_ForEach(IList<Token> tlist, CLS_Content 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);
            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.listParam.Add(subvalueblock);
                return value;
            }
            return null;
        }
예제 #23
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            var value = content.Get(value_name);

            content.OutStack(this);

            //从上下文取值

            return(value);
        }
예제 #24
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            CLS_Content.Value r    = listParam[0].ComputeValue(content);
            ICLS_Type         type = content.environment.GetType(r.type);

            r.value = type.Math2Value(content.environment, '*', r.value, CLS_Content.Value.OneMinus, out r.type);
            content.OutStack(this);

            return(r);
        }
예제 #25
0
 public bool MathLogic(CLS_Environment env, logictoken code, object left, CLS_Content.Value right)
 {
     if (code == logictoken.equal)
     {
         return null == right.value;
     }
     else if(code== logictoken.not_equal)
     {
         return null != right.value;
     }
     throw new NotImplementedException();
 }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            CLS_Content.Value r = listParam[0].ComputeValue(content);
            ICLS_Type type =content.environment.GetType(r.type);

            r.value= type.Math2Value(content.environment, '*', r.value, CLS_Content.Value.OneMinus, out r.type);
            content.OutStack(this);

            return r;
        }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            //var parent = listParam[0].ComputeValue(content);
            var value = listParam[0].ComputeValue(content);

            type.function.StaticValueSet(content.environment, staticmembername, value.value);
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return(null);
        }
예제 #28
0
 public CLS_Content.Value ComputeValue(CLS_Content content)
 {
     content.InStack(this);
     var parent = listParam[0].ComputeValue(content);
     var type = content.environment.GetType(parent.type);
     var value=type.function.MemberValueGet(content.environment, parent.value, membername);
     content.OutStack(this);
     return value;
     //做数学计算
     //从上下文取值
     //_value = null;
     //return null;
 }
예제 #29
0
        public ICLS_Expression Optimize(ICLS_Expression value, CLS_Content content)
        {
            ICLS_Expression expr = value as ICLS_Expression;

            if (expr == null)
            {
                return(value);
            }
            else
            {
                return(OptimizeDepth(expr, content));
            }
        }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            //var parent = listParam[0].ComputeValue(content);
            var value = listParam[0].ComputeValue(content);

            type.function.StaticValueSet(content.environment, staticmembername, value.value);
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return null;
        }
예제 #31
0
        public ICLS_Expression Compiler_Expression_Loop_For(IList<Token> tlist, CLS_Content 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, fe1);

            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.listParam.Add(subvalueblock);
                return value;
            }
            return null;
        }
예제 #32
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            var parent = listParam[0].ComputeValue(content);
            var type   = content.environment.GetType(parent.type);
            var value  = type.function.MemberValueGet(content.environment, parent.value, membername);

            content.OutStack(this);
            return(value);
            //做数学计算
            //从上下文取值
            //_value = null;
            //return null;
        }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            CLS_Expression_Define define = listParam[0] as CLS_Expression_Define;
            if (define == null)
            {

            }
            define.ComputeValue(content);

            System.Collections.IEnumerable emu = listParam[1].ComputeValue(content).value as System.Collections.IEnumerable;

            ICLS_Expression expr_block = listParam[2] as ICLS_Expression;

            var it = emu.GetEnumerator();
            while (it.MoveNext())
            {
                content.Set(define.value_name, it.Current);

                if (expr_block != null)
                {
                    var v = expr_block.ComputeValue(content);
                    if (v != null && v.breakBlock > 1) break; ;
                }
            }
            //ICLS_Expression expr_continue = listParam[1] as ICLS_Expression;
            //ICLS_Expression expr_step = listParam[2] as ICLS_Expression;

            //ICLS_Expression expr_block = listParam[3] as ICLS_Expression;

            //for (;(bool)expr_continue.ComputeValue(content).value; expr_step.ComputeValue(content))
            //{
            //    if(expr_block!=null)
            //    {
            //        var v = expr_block.ComputeValue(content);
            //        if (v != null && v.breakBlock > 1) break; ;
            //        //if (v.breakBlock == 1) continue;
            //        //if (v.breakBlock == 2) break;
            //        //if (v.breakBlock == 10) return v;
            //    }
            //}
            content.DepthRemove();
            content.OutStack(this);
            return null;
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            CLS_Content.Value r = listParam[0].ComputeValue(content);

            CLS_Content.Value r2 = new CLS_Content.Value();
            r2.type = r.type;
            r2.breakBlock = r.breakBlock;
            r2.value = !(bool)r.value;
            content.OutStack(this);

            return r2;
        }
예제 #35
0
        public ICLS_Expression Compiler_Expression_Loop_Return(IList <Token> tlist, CLS_Content content, int pos, int posend)
        {
            CLS_Expression_LoopReturn value = new CLS_Expression_LoopReturn(pos, posend);

            ICLS_Expression subvalue;
            bool            succ = Compiler_Expression(tlist, content, pos + 1, posend, out subvalue);

            if (succ)
            {
                value.listParam.Add(subvalue);
            }

            return(value);
        }
예제 #36
0
 public ICLS_Expression Compiler_Expression_Define(IList<Token> tlist,CLS_Content content, int pos,int posend)
 {
     CLS_Expression_Define define = new CLS_Expression_Define(pos, posend);
     if (tlist[pos].text == "bool")
     {
         define.value_type = typeof(bool);
     }
     else
     {
         ICLS_Type type =    content.environment.GetTypeByKeyword(tlist[pos].text);
         define.value_type = type.type;
     }
     define.value_name = tlist[pos+1].text;
     return define;
 }
예제 #37
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            CLS_Content.Value result = null;

            {
                result = new CLS_Content.Value();
                var left = listParam[0].ComputeValue(content);
                var right = listParam[1].ComputeValue(content);
                result.value = content.environment.GetType(left.type).Math2Value(content.environment, mathop, left.value, right, out result.type);

            }
            content.OutStack(this);
            return result;
        }
예제 #38
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            CLS_Content.Value r = listParam[0].ComputeValue(content);


            CLS_Content.Value r2 = new CLS_Content.Value();
            r2.type       = r.type;
            r2.breakBlock = r.breakBlock;
            r2.value      = !(bool)r.value;
            content.OutStack(this);

            return(r2);
        }
 public CLS_Content.Value ComputeValue(CLS_Content content)
 {
     content.InStack(this);
     List<CLS_Content.Value> list = new List<CLS_Content.Value>();
     foreach(ICLS_Expression p in listParam)
     {
         if(p!=null)
         {
             list.Add(p.ComputeValue(content));
         }
     }
     var value= type.function.New(content.environment,list);
     content.OutStack(this);
     return value;
 }
예제 #40
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            CLS_Content.Value result = null;


            {
                result = new CLS_Content.Value();
                var left  = listParam[0].ComputeValue(content);
                var right = listParam[1].ComputeValue(content);
                result.value = content.environment.GetType(left.type).Math2Value(content.environment, mathop, left.value, right, out result.type);
            }
            content.OutStack(this);
            return(result);
        }
예제 #41
0
        public CLS_Environment(ICLS_Logger logger)
        {
            this.logger = logger;
            tokenParser = new CLS_TokenParser();
            compiler = new CLS_Expression_Compiler(logger);
            RegType(new CLS_Type_Int());
            RegType(new CLS_Type_UInt());
            RegType(new CLS_Type_Float());
            RegType(new CLS_Type_Double());
            RegType(new CLS_Type_String());
            RegType(new CLS_Type_Var());
            typess["null"] = new CLS_Type_NULL();
            contentGloabl = CreateContent();

            RegFunction(new FunctionTrace());
        }
예제 #42
0
        public ICLS_Expression Compiler_Expression_Define(IList <Token> tlist, CLS_Content content, int pos, int posend)
        {
            CLS_Expression_Define define = new CLS_Expression_Define(pos, posend);

            if (tlist[pos].text == "bool")
            {
                define.value_type = typeof(bool);
            }
            else
            {
                ICLS_Type type = content.environment.GetTypeByKeyword(tlist[pos].text);
                define.value_type = type.type;
            }
            define.value_name = tlist[pos + 1].text;
            return(define);
        }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            List <CLS_Content.Value> list = new List <CLS_Content.Value>();

            foreach (ICLS_Expression p in listParam)
            {
                if (p != null)
                {
                    list.Add(p.ComputeValue(content));
                }
            }
            var value = type.function.New(content.environment, list);

            content.OutStack(this);
            return(value);
        }
예제 #44
0
        ICLS_Expression OptimizeDepth(ICLS_Expression expr, CLS_Content content)
        {
            //先进行深入优化
            if (expr.listParam != null)
            {
                for (int i = 0; i < expr.listParam.Count; i++)
                {
                    ICLS_Expression subexpr = expr.listParam[i] as ICLS_Expression;
                    if (subexpr != null)
                    {
                        expr.listParam[i] = OptimizeDepth(subexpr, content);
                    }
                }
            }

            return OptimizeSingle(expr, content);
        }
예제 #45
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            {
                CLS_Content.Value v = listParam[0].ComputeValue(content);
                Type value_type     = content.values[value_name].type;

                object val = v.value;
                if (value_type != typeof(CLS_Type_Var.var) && value_type != v.type)
                {
                    val = content.environment.GetType(v.type).ConvertTo(content.environment, v.value, value_type);
                }
                content.Set(value_name, val);
            }
            content.OutStack(this);
            return(null);
        }
예제 #46
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            {
                CLS_Content.Value v = listParam[0].ComputeValue(content);
                Type value_type = content.values[value_name].type;

                object val = v.value;
                if (value_type != typeof(CLS_Type_Var.var) && value_type!=v.type)
                {
                    val = content.environment.GetType(v.type).ConvertTo(content.environment, v.value, value_type);
                }
                content.Set(value_name, val);
            }
            content.OutStack(this);
            return null;
        }
예제 #47
0
        ICLS_Expression OptimizeSingle(ICLS_Expression expr, CLS_Content content)
        {
            if (expr is CLS_Expression_Math2Value || expr is CLS_Expression_Math2ValueAndOr || expr is CLS_Expression_Math2ValueLogic)
            {
                if (expr.listParam[0] is ICLS_Value &&
                    expr.listParam[1] is ICLS_Value)
                {
                    CLS_Content.Value result = expr.ComputeValue(content);
                    if (result.type == typeof(bool))
                    {
                        CLS_Value_Value <bool> value = new CLS_Value_Value <bool>();
                        value.value_value = (bool)result.value;
                        value.tokenBegin  = expr.listParam[0].tokenBegin;
                        value.tokenEnd    = expr.listParam[1].tokenEnd;
                        return(value);
                    }
                    else
                    {
                        ICLS_Type  v     = content.environment.GetType(result.type);
                        ICLS_Value value = v.MakeValue(result.value);
                        value.tokenBegin = expr.listParam[0].tokenBegin;
                        value.tokenEnd   = expr.listParam[1].tokenEnd;

                        return(value);
                    }
                }
            }
            if (expr is CLS_Expression_Math3Value)
            {
                CLS_Content.Value result = expr.listParam[0].ComputeValue(content);
                if (result.type == typeof(bool))
                {
                    bool bv = (bool)result.value;
                    if (bv)
                    {
                        return(expr.listParam[1]);
                    }
                    else
                    {
                        return(expr.listParam[2]);
                    }
                }
            }

            return(expr);
        }
예제 #48
0
        ICLS_Expression OptimizeDepth(ICLS_Expression expr, CLS_Content content)
        {
            //先进行深入优化
            if (expr.listParam != null)
            {
                for (int i = 0; i < expr.listParam.Count; i++)
                {
                    ICLS_Expression subexpr = expr.listParam[i] as ICLS_Expression;
                    if (subexpr != null)
                    {
                        expr.listParam[i] = OptimizeDepth(subexpr, content);
                    }
                }
            }


            return(OptimizeSingle(expr, content));
        }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            var right = listParam[0].ComputeValue(content);
            ICLS_Type type = content.environment.GetType(right.type);
            CLS_Content.Value value = new CLS_Content.Value();
            value.type = targettype;
            value.value = type.ConvertTo(content.environment, right.value, targettype);

            //操作变量之
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);

            return value;
        }
 public CLS_Content.Value ComputeValue(CLS_Content content)
 {
     content.InStack(this);
     //var parent = listParam[0].ComputeValue(content);
     //var type = content.environment.GetType(parent.type);
     List<CLS_Content.Value> _params = new List<CLS_Content.Value>();
     for (int i = 0; i < listParam.Count; i++)
     {
         _params.Add(listParam[i].ComputeValue(content));
     }
     var value = type.function.StaticCall(content.environment, functionName, _params);
     content.OutStack(this);
     return value;
     //做数学计算
     //从上下文取值
     //_value = null;
     //return null;
 }
예제 #51
0
 public virtual object Math2Value(CLS_Environment env, char code, object left, CLS_Content.Value right, out Type returntype)
 {
     returntype = type;
     System.Reflection.MethodInfo call = null;
     //var m = type.GetMethods();
     if (code == '+')
         call = type.GetMethod("op_Addition", new Type[] { this.type, right.type });
     else if (code == '-')//base = {CLScriptExt.Vector3 op_Subtraction(CLScriptExt.Vector3, CLScriptExt.Vector3)}
         call = type.GetMethod("op_Subtraction",new Type[]{this.type,right.type});
     else if (code == '*')//[2] = {CLScriptExt.Vector3 op_Multiply(CLScriptExt.Vector3, CLScriptExt.Vector3)}
         call = type.GetMethod("op_Multiply", new Type[] { this.type, right.type });
     else if (code == '/')//[3] = {CLScriptExt.Vector3 op_Division(CLScriptExt.Vector3, CLScriptExt.Vector3)}
         call = type.GetMethod("op_Division", new Type[] { this.type, right.type });
     else if (code == '%')//[4] = {CLScriptExt.Vector3 op_Modulus(CLScriptExt.Vector3, CLScriptExt.Vector3)}
         call = type.GetMethod("op_Modulus", new Type[] { this.type, right.type });
     var obj = call.Invoke(null, new object[] { left, right.value });
     //function.StaticCall(env,"op_Addtion",new List<ICL>{})
     return obj;
 }
예제 #52
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            var       right = listParam[0].ComputeValue(content);
            ICLS_Type type  = content.environment.GetType(right.type);

            CLS_Content.Value value = new CLS_Content.Value();
            value.type  = targettype;
            value.value = type.ConvertTo(content.environment, right.value, targettype);

            //操作变量之
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);

            return(value);
        }
예제 #53
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            var    parent = listParam[0].ComputeValue(content);
            var    value  = listParam[1].ComputeValue(content);
            object setv   = value.value;
            //if(value.type!=parent.type)
            //{
            //    var vtype = content.environment.GetType(value.type);
            //    setv = vtype.ConvertTo(content.environment, setv, parent.type);
            //}
            var type = content.environment.GetType(parent.type);

            type.function.MemberValueSet(content.environment, parent.value, membername, setv);
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return(null);
        }
예제 #54
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            var       v    = content.Get(value_name);
            ICLS_Type type = content.environment.GetType(v.type);
            Type      returntype;
            object    value = type.Math2Value(content.environment, mathop, v.value, CLS_Content.Value.One, out returntype);

            value = type.ConvertTo(content.environment, value, v.type);
            content.Set(value_name, value);

            //操作变量之
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);

            return(null);
        }
예제 #55
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            //var parent = listParam[0].ComputeValue(content);
            //var type = content.environment.GetType(parent.type);
            List <CLS_Content.Value> _params = new List <CLS_Content.Value>();

            for (int i = 0; i < listParam.Count; i++)
            {
                _params.Add(listParam[i].ComputeValue(content));
            }
            var value = type.function.StaticCall(content.environment, functionName, _params);

            content.OutStack(this);
            return(value);
            //做数学计算
            //从上下文取值
            //_value = null;
            //return null;
        }
예제 #56
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            CLS_Content.Value result = new CLS_Content.Value();

            //if (mathop == "&&" || mathop == "||")
            {
                bool bleft  = false;
                bool bright = false;
                if (listParam[0] is ICLS_Value)
                {
                    bleft = (bool)((listParam[0] as ICLS_Value).value);
                }
                else
                {
                    bleft = (bool)listParam[0].ComputeValue(content).value;
                }

                if (listParam[1] is ICLS_Value)
                {
                    bright = (bool)((listParam[1] as ICLS_Value).value);
                }
                else
                {
                    bright = (bool)listParam[1].ComputeValue(content).value;
                }
                result.type = typeof(bool);


                if (mathop == '&')
                {
                    result.value = (bool)(bleft && bright);
                }
                else if (mathop == '|')
                {
                    result.value = (bool)(bleft || bright);
                }
            }
            content.OutStack(this);
            return(result);
        }
예제 #57
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            List <CLS_Content.Value> list = new List <CLS_Content.Value>();

            foreach (ICLS_Expression p in listParam)
            {
                if (p != null)
                {
                    list.Add(p.ComputeValue(content));
                }
            }
            var v = content.environment.GetFunction(funcname).Call(content.environment, list);

            //操作变量之
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return(v);
        }
예제 #58
0
        public ICLS_Expression Compiler_NoBlock(IList <Token> tlist, CLS_Content content)
        {
            ICLS_Expression value;
            int             expbegin = 0;
            int             expend   = tlist.Count - 1;
            bool            succ     = Compiler_Expression(tlist, content, expbegin, expend, out value);

            if (succ)
            {
                if (value == null)
                {
                    logger.Log_Warn("编译为null:");
                }
                return(value);
            }
            else
            {
                LogError(tlist, "编译失败:", expbegin, expend);
                return(null);
            }
        }
예제 #59
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            ICLS_Expression expr_init = listParam[0] as ICLS_Expression;

            if (expr_init != null)
            {
                expr_init.ComputeValue(content);
            }

            ICLS_Expression expr_continue = listParam[1] as ICLS_Expression;
            ICLS_Expression expr_step     = listParam[2] as ICLS_Expression;

            ICLS_Expression expr_block = listParam[3] as ICLS_Expression;

            for (; (bool)expr_continue.ComputeValue(content).value; expr_step.ComputeValue(content))
            {
                if (expr_block != null)
                {
                    var v = expr_block.ComputeValue(content);
                    if (v != null && v.breakBlock > 1)
                    {
                        break;
                    }
                    ;
                    //if (v.breakBlock == 1) continue;
                    //if (v.breakBlock == 2) break;
                    //if (v.breakBlock == 10) return v;
                }
            }
            content.DepthRemove();
            content.OutStack(this);
            return(null);
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
예제 #60
0
        public ICLS_Expression Compiler_Expression_Set(IList <Token> tlist, CLS_Content content, int pos, int posend)
        {
            int expbegin = pos + 2;
            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_SetValue define = new CLS_Expression_SetValue(pos, expend);
                define.value_name = tlist[pos].text;
                define.listParam.Add(v);
                return(define);
            }
            LogError(tlist, "不正确的定义表达式:", pos, posend);
            return(null);
        }