Пример #1
0
        public static Value interp(ExprC exp)
        {
            if (exp.GetType() == typeof(numC))
            {
                var n = exp as numC;
                return(new numV(n.number));
            }
            else if (exp.GetType() == typeof(binopC))
            {
                var b = exp as binopC;

                var lVal = interp(b.left);
                var rVal = interp(b.right);
                var lNum = lVal as numV;
                var rNum = rVal as numV;

                if (b.op == op.Equals("eq?", StringComparison.Ordinal) || b.op == op.Equals("<=", StringComparison.Ordinal))
                {
                    return(booleanBinopHandle(b.op, lNum.number, rNum.number));
                }
                else if {
                    return(numBinopHandle(b.op, lNum.number, rNum.number));
                }
            }
            else if (exp.GetType() == typeof(boolC))
            {
                boolC bC = exp as boolC;
                return(boolV(bC.b));
            }
            else if (exp.GetType() == typeof(ifC))
            {
                ifC   i = exp as ifC;
                Value v = interp(i.conditional);
                if (v.GetType() == typeof(boolV))
                {
                    boolV bV = v as boolV;
                    if (bV.b == true)
                    {
                        return(interp(i.then));
                    }
                    else
                    {
                        return(interp(i.els));
                    }
                }
                else
                {
                    stringV("interp: error, not a boolV value");
                }
            }
            else
            {
                LangException ex = new LangException("Not a valid exprC");
                throw ex;
            }
        }
        public static Value interp(ExprC exp)
        {
            if (exp.GetType() == typeof(numC))
            {
                var n = exp as numC;
                return(new numV(n.number));
            }
            else if (exp.GetType() == typeof(binopC))
            {
                var b = exp as binopC;

                var lVal = interp(b.left);
                var rVal = interp(b.right);
                var lNum = lVal as numV;
                var rNum = rVal as numV;

                return(new numV(numBinopHandle(b.op, lNum.number, rNum.number)));
            }
            else if (exp.GetType() == typeof(boolC))
            {
                boolC bC = exp as boolC;
                return(new boolV(bC.b));
            }
            else if (exp.GetType() == typeof(ifC))
            {
                ifC   i = exp as ifC;
                Value v = interp(i.conditional);
                if (v.GetType() == typeof(boolV))
                {
                    boolV bV = v as boolV;
                    if (bV.b == true)
                    {
                        return(interp(i.then));
                    }
                    else
                    {
                        return(interp(i.els));
                    }
                }
                else
                {
                    LangException ex = new LangException("ifC failed");
                    throw ex;
                }
            }

            else
            {
                LangException ex = new LangException("Not a valid exprC");
                throw ex;
            }
        }
Пример #3
0
 public static Value interp(ExprC exp)
 {
     if (exp.GetType() == typeof(numC))
     {
         var n = exp as numC;
         return(new numV(n.number));
     }
     else
     {
         LangException ex = new LangException("Not a valid exprC");
         throw ex;
     }
 }