示例#1
0
文件: Call.cs 项目: 40ambar/Lips
    public override object Eval(Context context)
    {
        //evaluated parameters
        var evaluatedParameters = new object[ParametersValues.Length];

        for (var i = 0; i < ParametersValues.Length; i++)
        {
            evaluatedParameters[i] = ParametersValues[i].Eval(context);
        }

        //get function
        var func = (Delegate)Function.Eval(context);

        //internal
        if (Function is Lambda)
        {
            return(func.DynamicInvoke(new[] { evaluatedParameters }));
        }

        //external
        else
        {
            return(func.DynamicInvoke(evaluatedParameters));
        }
    }
示例#2
0
    public override object Eval(Context context)
    {
        var ret = Value.Eval(context);

        context.Define(Name, ret);
        return(ret);
    }
示例#3
0
    public override object Eval(Context context)
    {
        var ret = new ArrayList();

        while ((bool)Condition.Eval(context))
        {
            ret.Add(Body.Eval(context));
        }
        return(ret.ToArray());
    }
示例#4
0
 public override object Eval(Context context)
 {
     if ((bool)Condition.Eval(context))
     {
         return(TrueAst.Eval(context));
     }
     else
     {
         return(FalseAst.Eval(context));
     }
 }
示例#5
0
    public override object Eval(Context context)
    {
        switch (Op)
        {
        case "++": {
            var variable = (Get)Left;
            var value    = (double)variable.Eval(context);
            context.Set(variable.Name, value + 1);
            return(value);
        }

        case "--": {
            var variable = (Get)Left;
            var value    = (double)variable.Eval(context);
            context.Set(variable.Name, value + 1);
            return(value);
        }

        case "+": return((double)Left.Eval(context) + (double)Right.Eval(context));

        case "-": return((double)Left.Eval(context) - (double)Right.Eval(context));

        case "*": return((double)Left.Eval(context) * (double)Right.Eval(context));

        case "/": return((double)Left.Eval(context) / (double)Right.Eval(context));

        case "<": return((double)Left.Eval(context) < (double)Right.Eval(context));

        case ">": return((double)Left.Eval(context) > (double)Right.Eval(context));

        default: return(0);
        }
    }
示例#6
0
 public override object Eval(Context context)
 {
     return(new Func <object[], object>(arguments => {
         var funcContext = context.Extend();
         for (var i = 0; i < arguments.Length; i++)
         {
             funcContext.Define(
                 ParameterNames[i],
                 arguments[i]
                 );
         }
         return Body.Eval(funcContext);
     }));
 }
示例#7
0
    public override object Eval(Context context)
    {
        var ret  = new ArrayList();
        var from = (double)From.Eval(context);
        var to   = (double)To.Eval(context);
        var step = (double)Step.Eval(context);

        context.Define(Variable, from);
        for (var i = from; i <= to; i += step)
        {
            context.Set(Variable, i);
            ret.Add(Body.Eval(context));
        }
        return(ret.ToArray());
    }
示例#8
0
        private object Eval(Ast ast)
        {
            var context = new Context();

            context.Define("sin",
                           new Func <double, double>(Math.Sin)
                           );

            context.Define("format",
                           new Func <string, object[], string>((s, values) => {
                //var parameters = new string[values.Length];
                //for (int i = 0; i < values.Length; i++) {
                //    parameters[i] = values.ToString();
                //}
                return(string.Format(s, values.Select(i => i.ToString()).ToArray()));
            })
                           );

            context.Define("log",
                           new Action <string>(value => Debug.WriteLine(value))
                           );

            return(ast.Eval(context));
        }