Пример #1
0
        public ICQ_Expression Compiler_Expression_DefineAndSet(IList <Token> tlist, ICQ_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;
            }
            ICQ_Expression v;
            bool           succ = Compiler_Expression(tlist, content, expbegin, expend, out v);

            if (succ && v != null)
            {
                CQ_Expression_Define define = new CQ_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);
                if (tlist[pos].text == "bool")
                {
                    define.value_type = typeof(bool);
                }
                else
                {
                    ICQ_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 static ICQ_Expression Compiler_Expression_DefineAndSetArray(IList <Token> tlist, int pos, int posend)
        {
            int expbegin = pos + 5;
            int bdep;
            int expend = FindCodeAny(tlist, ref expbegin, out bdep);

            if (expend != posend)
            {
                expend = posend;
            }
            ICQ_Expression v;
            bool           succ = Compiler_Expression(tlist, expbegin, expend, out v);

            if (succ && v != null)
            {
                CQ_Expression_Define define = new CQ_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);
                {
                    IType type = AppDomain.GetTypeByKeyword(tlist[pos].text + "[]");
                    define.value_type = type.typeBridge;
                }
                define.value_name = tlist[pos + 3].text;
                define._expressions.Add(v);
                return(define);
            }
            LogError(tlist, "不正确的定义表达式:", pos, posend);
            return(null);
        }
Пример #3
0
        public ICQ_Expression Compiler_Expression_DefineArray(IList <Token> tlist, ICQ_Environment content, int pos, int posend)
        {
            CQ_Expression_Define define = new CQ_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);

            {
                ICQ_Type type = content.GetTypeByKeyword(tlist[pos].text + "[]");
                define.value_type = type.type;
            }
            define.value_name = tlist[pos + 3].text;
            return(define);
        }
        public static ICQ_Expression Compiler_Expression_DefineArray(IList <Token> tlist, int pos, int posend)
        {
            CQ_Expression_Define define = new CQ_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);

            {
                IType type = CQuark.AppDomain.GetTypeByKeyword(tlist[pos].text + "[]");
                define.value_type = type.typeBridge;
            }
            define.value_name = tlist[pos + 3].text;
            return(define);
        }
Пример #5
0
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            List <string> depth__;

            content.Record(out depth__);
            try
            {
                ICQ_Expression expr = listParam[0];
                if (expr is CQ_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)
                {
                    CQ_Expression_Define def = listParam[i] as CQ_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);
        }
Пример #6
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            int oldDepthCount = content.Record();
            try {
                ICQ_Expression expr = _expressions[0];
                if (expr is CQ_Expression_Block)
                {
                    expr.ComputeValue(content);
                }
                else
                {
                    content.DepthAdd();
                    expr.ComputeValue(content);
                    content.DepthRemove();
                }
            }
            catch (Exception err) {
                bool bParse = false;
                int  i      = 1;
                while (i < _expressions.Count)
                {
                    CQ_Expression_Define def = _expressions[i] as CQ_Expression_Define;
                    if (err.GetType() == (Type)def.value_type || err.GetType().IsSubclassOf((Type)def.value_type))
                    {
                        content.DepthAdd();
                        CQ_Value errVal = new CQ_Value();
                        errVal.SetObject(def.value_type, err);
                        content.DefineAndSet(def.value_name, def.value_type, errVal);

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

#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(CQ_Value.Null);
        }
Пример #7
0
        public ICQ_Expression Compiler_Expression_Define(IList <Token> tlist, ICQ_Environment content, int pos, int posend)
        {
            CQ_Expression_Define define = new CQ_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);

            if (tlist[pos].text == "bool")
            {
                define.value_type = typeof(bool);
            }
            else
            {
                ICQ_Type type = content.GetTypeByKeyword(tlist[pos].text);
                define.value_type = type.type;
            }
            define.value_name = tlist[pos + 1].text;
            return(define);
        }
        public static ICQ_Expression Compiler_Expression_Define(IList <Token> tlist, int pos, int posend)
        {
            CQ_Expression_Define define = new CQ_Expression_Define(pos, posend, tlist[pos].line, tlist[posend].line);

            if (tlist[pos].text == "bool")
            {
                define.value_type = typeof(bool);
            }
            else
            {
                IType type = CQuark.AppDomain.GetTypeByKeyword(tlist[pos].text);
                define.value_type = type.typeBridge;
            }
            define.value_name = tlist[pos + 1].text;
            return(define);
        }
Пример #9
0
 public DeleLambda(CQ_Content content, IList <ICQ_Expression> param, ICQ_Expression func)
 {
     this.content   = content.Clone();
     this.expr_func = func;
     foreach (var p in param)
     {
         CQ_Expression_GetValue v1 = p as CQ_Expression_GetValue;
         CQ_Expression_Define   v2 = p as CQ_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 参数不正确");
         }
     }
 }
Пример #10
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            CQ_Expression_Define define = _expressions[0] as CQ_Expression_Define;
            define.ComputeValue(content);

            System.Collections.IEnumerable emu = _expressions[1].ComputeValue(content).GetObject() as System.Collections.IEnumerable;

            ICQ_Expression expr_block = _expressions[2] as ICQ_Expression;

            var      it  = emu.GetEnumerator();
            CQ_Value vrt = CQ_Value.Null;
            while (it.MoveNext())
            {
                //content.Set(define.value_name, it.Current);
                CQ_Value val = new CQ_Value();
                val.SetObject(define.value_type, it.Current);
                content.Set(define.value_name, val);


                if (expr_block != null)
                {
                    if (expr_block is CQ_Expression_Block)
                    {
                        CQ_Value v = expr_block.ComputeValue(content);

                        if (v.m_breakBlock == BreakType.Return)
                        {
                            vrt = v;
                        }
                        if (v.m_breakBlock == BreakType.Return || v.m_breakBlock == BreakType.Break)
                        {
                            break;
                        }
                    }
                    else
                    {
                        content.DepthAdd();
                        bool     bbreak = false;
                        CQ_Value v      = expr_block.ComputeValue(content);

                        if (v.m_breakBlock == BreakType.Return)
                        {
                            vrt = v;
                        }
                        if (v.m_breakBlock == BreakType.Break || v.m_breakBlock == BreakType.Return)
                        {
                            bbreak = true;
                        }

                        content.DepthRemove();
                        if (bbreak)
                        {
                            break;
                        }
                    }
                }
            }

            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(vrt);
        }
Пример #11
0
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            CQ_Expression_Define define = listParam[0] as CQ_Expression_Define;

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

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

            ICQ_Expression expr_block = listParam[2] as ICQ_Expression;

            var it = emu.GetEnumerator();

            CQ_Content.Value vrt = null;
            while (it.MoveNext())
            {
                content.Set(define.value_name, it.Current);
                if (expr_block != null)
                {
                    if (expr_block is CQ_Expression_Block)
                    {
                        var v = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        content.DepthAdd();
                        bool bbreak = false;
                        var  v      = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                bbreak = true;
                            }
                        }
                        content.DepthRemove();
                        if (bbreak)
                        {
                            break;
                        }
                    }
                }
            }
            //ICQ_Expression expr_continue = listParam[1] as ICQ_Expression;
            //ICQ_Expression expr_step = listParam[2] as ICQ_Expression;

            //ICQ_Expression expr_block = listParam[3] as ICQ_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(vrt);
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            CQ_Expression_Define define = _expressions[0] as CQ_Expression_Define;
            if (define == null)
            {
            }
            define.ComputeValue(content);

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

            ICQ_Expression expr_block = _expressions[2] as ICQ_Expression;

            var      it  = emu.GetEnumerator();
            CQ_Value vrt = null;
            while (it.MoveNext())
            {
                content.Set(define.value_name, it.Current);
                if (expr_block != null)
                {
                    if (expr_block is CQ_Expression_Block)
                    {
                        var v = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        content.DepthAdd();
                        bool bbreak = false;
                        var  v      = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                bbreak = true;
                            }
                        }
                        content.DepthRemove();
                        if (bbreak)
                        {
                            break;
                        }
                    }
                }
            }

            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(vrt);
        }