public override int Eval(REnv env, FEnv fEnv)
        {
            int x = e1.Eval(env, fEnv);

            env.AllocateLocal(this.name);
            env.GetVariable(this.name).value = x;
            int y = e2.Eval(env, fEnv);

            env.PopEnv();
            return(y);
        }
示例#2
0
        public override int Eval(REnv env, FEnv fEnv)
        {
            int res1 = e1.Eval(env, fEnv);

            env.AllocateLocal(varName);
            env.GetVariable(varName).value = res1;

            int res2 = e2.Eval(env, fEnv);

            env.PopEnv();
            return(res2);
        }
示例#3
0
        public override int Eval(REnv env, FEnv fEnv)
        {
            int v1 = e1.Eval(env, fEnv);
            int v2 = e2.Eval(env, fEnv);

            switch (op)
            {
            case Operator.Add:
                return(v1 + v2);

            case Operator.Div:
                return(v1 / v2);

            case Operator.Mul:
                return(v1 * v2);

            case Operator.Sub:
                return(v1 - v2);

            case Operator.Eq:
                return(v1 == v2 ? 1 : 0);

            case Operator.Ne:
                return(v1 != v2 ? 1 : 0);

            case Operator.Lt:
                return(v1 < v2 ? 1 : 0);

            case Operator.Le:
                return(v1 <= v2 ? 1 : 0);

            case Operator.Gt:
                return(v1 > v2 ? 1 : 0);

            case Operator.Ge:
                return(v1 >= v2 ? 1 : 0);

            case Operator.And:
                return(v1 == 0 ? 0 : v2);

            case Operator.Or:
                return(v1 == 0 ? v2 : 1);

            case Operator.Mod:
                return(v1 % v2);

            default:
                throw new Exception("Unknown binary operator: " + op);
            }
        }
示例#4
0
        public override int Eval(REnv env, FEnv fenv)
        {
            int        value  = 0;
            List <int> values = new List <int>();

            foreach (var expression in expressions)
            {
                int argValue = expression.Eval(env, fenv);
                values.Add(argValue);
            }
            FuncDef fDef = fenv.getFunction(fName);

            value = fDef.Eval(env, fenv, values);
            return(value);
        }
        public override int Eval(REnv env, FEnv fEnv)
        {
            int result;
            int v1 = e1.Eval(env, fEnv);

            if (v1 == 1)
            {
                result = e2.Eval(env, fEnv);
            }
            else
            {
                result = e3.Eval(env, fEnv);
            }
            return(result);
        }
示例#6
0
        public override int Eval(REnv env, FEnv fEnv)
        {
            int v1 = e1.Eval(env, fEnv);

            switch (op)
            {
            case Operator.Not:
                return(v1 == 0 ? 1 : 0);

            case Operator.Neg:
                return(-v1);

            default:
                throw new Exception("Unknown unary operator: " + op);
            }
        }
示例#7
0
        public override int Eval(REnv env, FEnv fEnv)
        {
            int conditionRes = cond.Eval(env, fEnv);

            switch (conditionRes)
            {
            case 1:
                return(e2.Eval(env, fEnv));

            case 0:
                return(e3.Eval(env, fEnv));

            default:
                throw new Exception("Arguments after 'if' must return a bool: " + conditionRes);
            }
        }
示例#8
0
        public int Eval(REnv env, FEnv fenv, List <int> args)
        {
            int i = 0;

            foreach (var formArg in formArgs)
            {
                env.AllocateLocal(formArg.Fst);
                env.GetVariable(formArg.Fst).value = args[i];
                i++;
            }
            int v = body.Eval(env, fenv);

            foreach (var formArg in formArgs)
            {
                env.PopEnv();
            }
            return(v);
        }
        public override int Eval(REnv env, FEnv fenv)
        {
            int[] argValues;

            if (args.Count > 0)
            {
                int index = 0;
                argValues = new int[args.Count];
                foreach (Expression arg in args)
                {
                    argValues[index++] = arg.Eval(env, fenv);
                }
            }
            else
            {
                argValues = new int[0];
            }
            FuncDef fDef = fenv.getFunction(fName);

            return(fDef.Eval(env, fenv, argValues));
        }
        public int Eval(REnv env, FEnv fenv, int[] values)
        {
            int v;

            if (formArgs.Count > 0)
            {
                int index = 0;
                foreach (Pair <String, Type> argPair in this.formArgs)
                {
                    env.AllocateLocal(argPair.Fst);
                    env.GetVariable(argPair.Fst).value = values[index++];
                }
                v = body.Eval(env, fenv);
                foreach (Pair <String, Type> argPair in this.formArgs)
                {
                    env.PopEnv();
                }
            }
            else
            {
                v = body.Eval(env, fenv);
            }
            return(v);
        }
示例#11
0
        public int Eval()
        {
            REnv renv = new REnv();

            return(e.Eval(renv, fenv));
        }
示例#12
0
 public override int Eval(REnv env, FEnv fEnv)
 {
     return(env.GetVariable(name).value);
 }
示例#13
0
 public override int Eval(REnv env, FEnv fEnv)
 {
     return(value);
 }
示例#14
0
 abstract public int Eval(REnv env, FEnv fEnv);