Esempio n. 1
0
        public static JsObject EvalIf(JsExpression x, Env env)
        {
            JsBool cond = (JsBool)(x.child[0].evaluate(env));

            if (x.child.Count == 3)
            {
                return(cond ? x.child[1].evaluate(env) : x.child[2].evaluate(env));
            }
            else
            {
                return(cond ? x.child[1].evaluate(env) : new JsBool(false));
            }
        }
Esempio n. 2
0
        public static JsObject EvalWhile(JsExpression x, Env env)
        {
            JsBool   cond = (JsBool)(x.child[0].evaluate(env));
            JsObject res  = null;

            if (cond)
            {
                while ((JsBool)x.child[0].evaluate(env))//build-in
                {
                    res = x.child[1].evaluate(env);
                }
            }
            return(res);
        }
Esempio n. 3
0
        public static JsBool BoolEval(this JsExpression[] args, Env env, Func <JsBool, JsBool, bool> rel)
        {
            (args.Length > 1).OrThrows("arguments are too less in relation expressions");
            JsBool curr = (JsBool)args[0].evaluate(env);

            foreach (var item in args.Skip(1))
            {
                JsBool next = (JsBool)item.evaluate(env);
                if (rel(curr, next))
                {
                    curr = next;
                }
                else
                {
                    return(JsBool.False);
                }
            }
            return(JsBool.True);
        }