Exemplo n.º 1
0
        public static JsObject EvalFunctionInvoke(JsExpression x, Env env)
        {
            JsFunction func = x.value == "(" ?
                              (JsFunction)x.child[0].evaluate(env) :
                              (JsFunction)env.Find(x.value);
            //add variable support,because var has child,so it can't be evaluated
            var arguments = x.child.Skip(1).Select(item => item.evaluate(env)).ToArray();

            return(func.UpdateArgs(arguments).evaluate());
        }
Exemplo n.º 2
0
 public static JsObject EvalFunction(JsExpression x, Env env)
 {
     if (x.child.Count == 3)
     {
         string[]   args = x.child[1].child.Select(i => i.value).ToArray();
         JsFunction func = new JsFunction(args, x.child[2], new Env(env));
         return(env.AddDef(x.child[0].value, func));
     }
     else
     {
         string[]   args = x.child[0].child.Select(i => i.value).ToArray();
         JsFunction func = new JsFunction(args, x.child[1], new Env(env));
         return(func);
     }
 }
Exemplo n.º 3
0
        public static JsObject EvalPointExpression(JsExpression x, Env env)
        {
            JsObject     obj = env.Find(x.child[0].value);//root obj
            JsExpression exp = x.child[1];

            if (exp.value == "=")
            {
                return(obj.AddDef(exp.child[0].value, exp.child[1].evaluate(obj.Scope)));
            }
            else
            {
                if (exp.value == "(")
                {
                    JsFunction func      = (JsFunction)obj.FindAttribute(exp.child[0].value);
                    var        arguments = exp.child.Skip(1).Select(item => item.evaluate(env)).ToArray();
                    return(func.UpdateArgs(arguments).evaluate());
                }
                else
                {
                    return(obj.FindAttribute(exp.value));
                }
            }
        }