Ejemplo 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 LoxCallable))
            {
                throw new RuntimeError(expr.paren, "Can only call functions and classes.");
            }

            LoxCallable function = (LoxCallable)callee;

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

            return(function.Call(this, arguments));
        }
        public MyVoid VisitCallExpr(Expr.Call expr)
        {
            resolve(expr.callee);

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

            return(null);
        }
Ejemplo n.º 3
0
 public string VisitCallExpr(Expr.Call expr)
 {
     return("Printing call expression not implemeneted");
 }