Exemplo n.º 1
0
        public object visitCallExpr(Expr.Call expr)
        {
            object callee = Evaluate(expr.callee);

            if (!(callee is ICallable))
            {
                throw new RuntimeError(expr.paren, "Can only call on functions and classes.");
            }

            List <object> args = new List <object>();

            foreach (Expr arg in expr.args)
            {
                args.Add(Evaluate(arg));
            }

            ICallable function = (ICallable)callee;

            if (args.Count != function.Arity())
            {
                throw new RuntimeError(expr.paren, "Expected " + function.Arity() + " arguments but got " + args.Count + ".");
            }

            return(function.Call(this, args));
        }
Exemplo n.º 2
0
        public Void visitCallExpr(Expr.Call expr)
        {
            Resolve(expr.callee);

            foreach (Expr arg in expr.args)
            {
                Resolve(arg);
            }

            return(null);
        }