Esempio n. 1
0
        public ResultMemory(Bindings global)
        {
            _global = global;

            global.AddBinding(m1);
            global.AddBinding(m2);
            global.AddBinding(m3);
        }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        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");
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
 private bool IsMacro(Expression expr, Bindings scope)
 {
     return expr is SymbolExpression
         && scope.Resolve(expr.Token.Text) is Macro;
 }
Esempio n. 7
0
 public BuiltInFunction(string symbol, Bindings scope)
     : base(symbol, scope)
 {
 }
Esempio n. 8
0
 public Restart(Bindings scope)
     : base("restart", scope)
 {
 }
Esempio n. 9
0
 public Quit(Bindings scope)
     : base("quit", scope)
 {
 }
Esempio n. 10
0
 /// <summary>
 /// Default evaluation - evaluates to self
 /// </summary>
 /// <param name="scope">Not used in base evaluator</param>
 public virtual Expression Evaluate(Bindings scope)
 {
     return this;
 }
Esempio n. 11
0
 public ScopedExpression(string symbol, Bindings scope)
     : base(new Token(Tokens.FUNCTION, symbol))
 {
     Scope = new Bindings() { ParentScope = scope };
 }
Esempio n. 12
0
 public Expression ExpandAndEvaluate(IEnumerable<Expression> args, Bindings scope)
 {
     return Expand(args).Evaluate(scope);
 }
Esempio n. 13
0
 public override Expression Evaluate(Bindings scope)
 {
     throw new MistException("You can't evaluate a macro (" + Token.Text + ")");
 }