Example #1
0
        public object visitCallExpr(Expr.Call expr)
        {
            object callee = Evaluate(expr.callee);

            List <object> args = expr.args.ConvertAll(Evaluate);

            if (callee is LoxCallable function)
            {
                if (args.Count != function.Arity())
                {
                    throw new RuntimeError(expr.paren, "Expected " + function.Arity() + " arguments but got " + args.Count + ".");
                }
                return(function.Call(this, args));
            }
            else
            {
                throw new RuntimeError(expr.paren, "Can only call functions and classes.");
            }
        }
Example #2
0
 public object visitCallExpr(Expr.Call expr)
 {
     Resolve(expr.callee);
     expr.args.ForEach(Resolve);
     return(null);
 }
Example #3
0
 public string visitCallExpr(Expr.Call expr)
 {
     return(parenthesize("CALL " + expr.callee.ToString(), expr.args.ToArray()));
 }