예제 #1
0
파일: Resolver.cs 프로젝트: mutuware/Lox
        public object VisitSuperExpr(Super expr)
        {
            if (currentClass == ClassType.NONE)
            {
                Program.Error(expr.Keyword, "Can't use 'super' outside of a class.");
            }
            else if (currentClass != ClassType.SUBCLASS)
            {
                Program.Error(expr.Keyword, "Can't use 'super' in a class with no superclass.");
            }

            ResolveLocal(expr, expr.Keyword);
            return(null);
        }
예제 #2
0
파일: Interpreter.cs 프로젝트: mutuware/Lox
        public object VisitSuperExpr(Super expr)
        {
            int      distance   = locals[expr];
            LoxClass superclass = (LoxClass)environment.GetAt(distance, "super");

            LoxInstance obj = (LoxInstance)environment.GetAt(distance - 1, "this");

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

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

            return(method.Bind(obj));
        }
예제 #3
0
 public string VisitSuperExpr(Super expr)
 {
     return("super");
 }