public object VisitVariableExpr(Expr.Variable expr) { _scopes.TryPeek(out IDictionary <string, bool> peekedDictionary); bool getValue = false; peekedDictionary?.TryGetValue(expr.Name.Lexeme, out getValue); if (_scopes.Count != 0 && getValue == false) { Lox.Error(expr.Name, "Cannot read local variable in its own initializer."); } ResolveLocal(expr, expr.Name); return(null); }
private Stmt ClassDeclaration() { Token name = Consume(IDENTIFIER, "Expect class name."); Expr.Variable superclass = null; if (Match(LESS)) { Consume(IDENTIFIER, "Expect superclass name"); superclass = new Expr.Variable(Previous()); } Consume(LEFT_BRACE, "Expect '{' before class body."); List <Stmt.Function> methods = new List <Stmt.Function>(); while (!Check(RIGHT_BRACE) && !IsAtEnd()) { methods.Add(Function("method")); } Consume(RIGHT_BRACE, "Expect '}' after class body"); return(new Stmt.Class(name, superclass, methods)); }
public object VisitVariableExpr(Expr.Variable expr) { return(LookUpVariable(expr.Name, expr)); }
public Class(Token name, Expr.Variable superclass, IEnumerable <Stmt.Function> methods) { this.Name = name; this.Superclass = superclass; this.Methods = methods; }
public string Visit(Expr.Variable expr) { throw new NotImplementedException(); }