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)); } }
public override object Eval(Context context) { var ret = Value.Eval(context); context.Define(Name, ret); return(ret); }
public override object Eval(Context context) { var ret = new ArrayList(); while ((bool)Condition.Eval(context)) { ret.Add(Body.Eval(context)); } return(ret.ToArray()); }
public override object Eval(Context context) { if ((bool)Condition.Eval(context)) { return(TrueAst.Eval(context)); } else { return(FalseAst.Eval(context)); } }
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); } }
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); })); }
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()); }
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)); }