Ejemplo n.º 1
0
 public object visitSuperExpr(Expr.Super expr)
 {
     if (currentClass == ClassType.NONE)
     {
         Lox.error(expr.Keyword,
                   "Cannot use 'super' outisde of class");
     }
     else if (currentClass != ClassType.SUBCLASS)
     {
         Lox.error(expr.Keyword,
                   "Cannot use 'super' in a class with no superclass");
     }
     resolveLocal(expr, expr.Keyword);
     return(null);
 }
Ejemplo n.º 2
0
        public object visitSuperExpr(Expr.Super expr)
        {
            int      distance   = locals[expr];
            LoxClass superClass = (LoxClass)env.getAt(
                distance, "super");
            LoxInstance instance = (LoxInstance)env.getAt(
                distance - 1, "this");

            LoxFunction method = superClass.findMethod(expr.Method.Lexeme);

            if (method == null)
            {
                throw new RuntimeError(expr.Method,
                                       $"Undefined propert '{expr.Method.Lexeme}'");
            }
            return(method.bind(instance));
        }
Ejemplo n.º 3
0
 public string visitSuperExpr(Expr.Super expr)
 {
     throw new NotImplementedException();
 }