public ResultMemory(Bindings global) { _global = global; global.AddBinding(m1); global.AddBinding(m2); global.AddBinding(m3); }
public Macro( string symbol, ListExpression formalParams, IEnumerable<Expression> body, Environment environment) : base(new Token(Tokens.MACRO, symbol)) { _formalParams = new FormalParameters(formalParams); _body = body; _environment = environment; _scope = _environment.CurrentScope; }
public Bindings BindArguments(Bindings scope, IEnumerable<Expression> args) { var invocationScope = new Bindings { ParentScope = scope }; // TODO: enhance when optional parameter length added if (_parameters != null && _parameters.Elements.Count != args.Count()) throw new MistException(string.Format("Wrong number of arguments ({0} instead of {1})", args.Count(), _parameters.Elements.Count)); if (_parameters != null) for (int i = 0; i < Count; i++) invocationScope.AddBinding( _parameters.Elements[i], args.ElementAt(i)); return invocationScope; }
private Function GetFirstExpressionAsFunction(Bindings scope) { if (!(Elements[0] is Function)) Elements[0] = Elements[0].Evaluate(scope); // recur to try to get a function if (Functionoid.CanWrap(Elements[0])) return new Functionoid(Elements[0]); if (Elements[0] is Function) return (Function)Elements[0]; throw new MistException(Elements[0].ToString() + " is not a function"); }
private Expression CallMacro(Bindings scope) { var firstElem = Elements.First(); var macro = scope.Resolve(firstElem.Token.Text) as Macro; return macro.ExpandAndEvaluate(Elements.Skip(1), scope); }
private bool IsMacro(Expression expr, Bindings scope) { return expr is SymbolExpression && scope.Resolve(expr.Token.Text) is Macro; }
public BuiltInFunction(string symbol, Bindings scope) : base(symbol, scope) { }
public Restart(Bindings scope) : base("restart", scope) { }
public Quit(Bindings scope) : base("quit", scope) { }
/// <summary> /// Default evaluation - evaluates to self /// </summary> /// <param name="scope">Not used in base evaluator</param> public virtual Expression Evaluate(Bindings scope) { return this; }
public ScopedExpression(string symbol, Bindings scope) : base(new Token(Tokens.FUNCTION, symbol)) { Scope = new Bindings() { ParentScope = scope }; }
public Expression ExpandAndEvaluate(IEnumerable<Expression> args, Bindings scope) { return Expand(args).Evaluate(scope); }
public override Expression Evaluate(Bindings scope) { throw new MistException("You can't evaluate a macro (" + Token.Text + ")"); }