Exemplo n.º 1
0
 public object visitCallExpr(Expr.Call expr)
 {
     resolve(expr.Callee);
     foreach (Expr arg in expr.Arguments)
     {
         resolve(arg);
     }
     return(null);
 }
Exemplo n.º 2
0
        public object visitCallExpr(Expr.Call expr)
        {
            object        callee = evaluate(expr.Callee);
            List <object> args   = expr.Arguments.ConvertAll(
                new Converter <Expr, object>(x => evaluate(x))
                );

            if (!(callee is LoxCallable))
            {
                throw new RuntimeError(expr.Paren,
                                       "Can only call functions and classes");
            }
            LoxCallable function = (LoxCallable)callee;

            if (args.Count != function.arity())
            {
                throw new RuntimeError(expr.Paren,
                                       $"Expected {function.arity()} but got {args.Count}");
            }
            return(function.call(this, args));
        }
Exemplo n.º 3
0
 public string visitCallExpr(Expr.Call expr)
 {
     return(parenthesize("call", expr.Callee));
 }