public object VisitVariableExpr(Expr.Variable expr) { if (scopes.Count != 0 && scopes.Peek().ContainsKey(expr.name.lexeme) && scopes.Peek()[expr.name.lexeme] == false) { Basil.Error(expr.name, "Cannot read local variable in its own initializer."); } ResolveLocal(expr, expr.name); return(null); }
private Stmt ClassDeclaration() { Token name = Consume(Token.TokenType.Identifier, "Expect class name."); Expr superclass = null; if (Match(Token.TokenType.Less)) { Consume(Token.TokenType.Identifier, "Expect superclass name."); superclass = new Expr.Variable(Previous()); } Consume(Token.TokenType.LeftBrace, "Expect '{' before class body."); List <Stmt.Function> methods = new List <Stmt.Function>(); while (!Check(Token.TokenType.RightBrace) && !IsAtEnd()) { methods.Add(Function("method")); } Consume(Token.TokenType.RightBrace, "Expect '}' after class body."); return(new Stmt.Class(name, superclass, methods)); }
public object VisitVariableExpr(Expr.Variable expr) { return(LookUpVariable(expr.name, expr)); }
public string VisitVariableExpr(Expr.Variable expr) { return(expr.name.ToString()); }