public object visitVariableExpr(Expr.Variable expr) { bool initialized; if (scopes.Count > 0 && scopes.Peek().TryGetValue(expr.Name.Lexeme, out initialized) && initialized == false) { Lox.error(expr.Name, "Cannot read local variable in it's own initializer"); } resolveLocal(expr, expr.Name); return(null); }
private Stmt classDelaration() { Token name = consume(TokenType.IDENTIFIER, "Expect class name"); Expr.Variable superClass = null; if (match(TokenType.LESS)) { consume(TokenType.IDENTIFIER, "Expect superclass name."); superClass = new Expr.Variable(previous()); } consume(TokenType.LEFT_BRACE, "Expect '{' before class body"); var methods = new List <Stmt.Function>(); while (!check(TokenType.RIGHT_BRACE) && !isAtEnd()) { methods.Add(function("method")); } consume(TokenType.RIGHT_BRACE, "Expect '}' after class body"); return(new Stmt.Class(name, superClass, methods)); }
public string visitVariableExpr(Expr.Variable expr) { return(parenthesize("var", expr)); }
public Class(Token name, Expr.Variable superClass, List <Stmt.Function> methods) { Name = name; SuperClass = superClass; Methods = methods; }
public object visitVariableExpr(Expr.Variable expr) { return(lookUpVariable(expr.Name, expr)); }