예제 #1
0
        public object VisitSuperExpr(Super expr)
        {
            if (currentClass == ClassType.NONE)
            {
                CsLox.Error(expr.Keyword, "Cannot use 'super' outside of a class.");
            }
            else if (currentClass != ClassType.SUBCLASS)
            {
                CsLox.Error(expr.Keyword, "Cannot use 'super' in a class with no superclass.");
            }

            ResolveLocal(expr, expr.Keyword);

            return(null);
        }
예제 #2
0
        public object VisitSuperExpr(Super expr)
        {
            int      distance   = locals[expr];
            LoxClass superclass = (LoxClass)environment.GetAt(distance, "super");

            // "this" is always one level nearer than "super"'s environment.
            LoxInstance @object = (LoxInstance)environment.GetAt(distance - 1, "this");

            LoxFunction method = superclass.FindMethod(expr.Method.Lexeme);

            if (method == null)
            {
                throw new RuntimeException(expr.Method, $"Undefined property '{expr.Method.Lexeme}'.");
            }

            return(method.Bind(@object));
        }
예제 #3
0
 public string VisitSuperExpr(Super expr)
 {
     throw new System.NotImplementedException();
 }