Esempio n. 1
0
        public override object Eval(Environment env)
        {
            object            ret      = null;
            NestedEnvironment newScope = new NestedEnvironment(env);

            IterControl().Define().Eval(newScope);
            while ((int)IterControl().Condition().Eval(newScope) == Environment.True)
            {
                ret = ForBody().Eval(newScope);
                IterControl().Next().Eval(newScope);
            }
            return(ret);
        }
Esempio n. 2
0
        public override object Eval(Environment env)
        {
            object            ret      = null;
            NestedEnvironment newScope = new NestedEnvironment(env);

            foreach (var stmnt in this)
            {
                if (stmnt.GetType() == typeof(NullStmnt))
                {
                    continue;
                }
                ret = stmnt.Eval(newScope);
            }
            return(ret);
        }
Esempio n. 3
0
 public object Eval(Environment env, object value)
 {
     if (value.GetType() == typeof(SheFunction))
     {
         SheFunction   func    = (SheFunction)value;
         ParameterList @params = func.Parameters;
         if (Size() != @params.Size())
         {
             throw new SheException("bad number of arguments", this);
         }
         Environment newEnv = new NestedEnvironment(env);
         int         num    = 0;
         foreach (ASTree ast in this)
         {
             @params.Eval(newEnv, num++, ast.Eval(env));
         }
         return(func.Body.Eval(newEnv));
     }
     else if (value.GetType() == typeof(NativeFunction))
     {
         NativeFunction func = (NativeFunction)value;
         if (func.NumParams != NativeFunction.VariadicArg && func.NumParams != NumChildren())
         {
             throw new SheException("bad number of arguments", this);
         }
         object[] @params = new object[NumChildren()];
         for (int i = 0; i < NumChildren(); i++)
         {
             @params[i] = GetChild(i).Eval(env);
         }
         return(func.Invoke(@params, this));
     }
     else
     {
         throw new SheException("bad function", this);
     }
 }