Inheritance: ICLS_Expression
Ejemplo n.º 1
0
        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 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;
 }
Ejemplo n.º 3
0
        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);
            List <string> depth__;

            content.Record(out depth__);
            try
            {
                ICLS_Expression expr = listParam[0];
                if (expr is CLS_Expression_Block)
                {
                    expr.ComputeValue(content);
                }
                else
                {
                    content.DepthAdd();
                    expr.ComputeValue(content);
                    content.DepthRemove();
                }
            }
            catch (Exception err)
            {
                bool bParse = false;
                int  i      = 1;
                while (i < listParam.Count)
                {
                    CLS_Expression_Define def = listParam[i] as CLS_Expression_Define;
                    if (err.GetType() == (Type)def.value_type || err.GetType().IsSubclassOf((Type)def.value_type))
                    {
                        content.DepthAdd();
                        content.DefineAndSet(def.value_name, def.value_type, err);

                        listParam[i + 1].ComputeValue(content);
                        content.DepthRemove();
                        bParse = true;
                        break;
                    }
                    i += 2;
                }
                if (!bParse)
                {
                    throw err;
                }
            }
            content.Restore(depth__, this);
            //while((bool)expr_continue.value);

            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return(null);
        }
Ejemplo n.º 5
0
        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_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;
 }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);
            content.DepthAdd();

            CLS_Content.Value vrt = null;

            CLS_Expression_Define define = listParam[0] as CLS_Expression_Define;

            define.ComputeValue(content);

            IEnumerator it = (listParam[1].ComputeValue(content).value as IEnumerable).GetEnumerator();

            ICLS_Expression expr_block = listParam[2];

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

                if (expr_block != null)
                {
                    CLS_Content.Value v = expr_block.ComputeValue(content);
                    if (v != null)
                    {
                        if (v.breakBlock > 2)
                        {
                            vrt = v;
                        }
                        if (v.breakBlock > 1)
                        {
                            break;
                        }
                    }
                }
            }
            content.DepthRemove();
            content.OutStack(this);
            return(vrt);
        }
Ejemplo n.º 9
0
 public DeleLambda(CLS_Content content, IList <ICLS_Expression> param, ICLS_Expression func)
 {
     this.content   = content.Clone();
     this.expr_func = func;
     for (int i = 0, count = param.Count; i < count; i++)
     {
         CLS_Expression_GetValue v1 = param[i] as CLS_Expression_GetValue;
         if (v1 != null)
         {
             paramTypes.Add(null);
             paramNames.Add(v1.value_name);
             continue;
         }
         CLS_Expression_Define v2 = param[i] as CLS_Expression_Define;
         if (v2 != null)
         {
             paramTypes.Add(v2.value_type);
             paramNames.Add(v2.value_name);
             continue;
         }
         throw new Exception("DeleLambda 参数不正确");
     }
 }
Ejemplo n.º 10
0
 public DeleLambda(CLS_Content content, IList <ICLS_Expression> param, ICLS_Expression func)
 {
     this.content   = content.Clone();
     this.expr_func = func;
     foreach (var p in param)
     {
         CLS_Expression_GetValue v1 = p as CLS_Expression_GetValue;
         CLS_Expression_Define   v2 = p as CLS_Expression_Define;
         if (v1 != null)
         {
             paramTypes.Add(null);
             paramNames.Add(v1.value_name);
         }
         else if (v2 != null)
         {
             paramTypes.Add(v2.value_type);
             paramNames.Add(v2.value_name);
         }
         else
         {
             throw new Exception("DeleLambda 参数不正确");
         }
     }
 }
 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;
 }