public object VisitVariableExpr(Expr.VariableExpr expr) { if (Scopes.Any()) { var scope = Scopes.Peek(); if (scope.ContainsKey(expr.Name.Lexeme) && !scope[expr.Name.Lexeme]) { Lox.Error(expr.Name, "Cannot read local variable in its own initializer."); } } ResolveLocal(expr, expr.Name); return(null); }
private Stmt ClassDeclaration() { var name = Consume(IDENTIFIER, "Expect class name."); Expr.VariableExpr superclass = null; if (Match(LESS)) { Consume(IDENTIFIER, "Expect superclass name."); superclass = new Expr.VariableExpr(Previous()); } Consume(LEFT_BRACE, "Expect '{' before class body."); var methods = new List <Stmt.FunctionStmt>(); while (!Check(RIGHT_BRACE) && !IsAtEnd()) { methods.Add(Function("method")); } Consume(RIGHT_BRACE, "Expect '}' after class body."); return(new Stmt.ClassStmt(name, superclass, methods)); }
public ClassStmt(Token name, Expr.VariableExpr superclass, List <FunctionStmt> methods) { Name = name; Superclass = superclass; Methods = methods; }
public string VisitVariableExpr(Expr.VariableExpr expr) { return(expr.Name.Lexeme); }