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

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

            foreach (Expr argument in expr.arguments)
            {
                arguments.Add(Evaluate(argument));
            }

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

            IElizCallable function = callee as IElizCallable;

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

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

            foreach (Expr argument in expr.arguments)
            {
                Resolve(argument);
            }

            return(null);
        }