public object visitVariableExpr(Expr.Variable expr) { if (scopes.Count > 0 && scopes[scopes.Count - 1].ContainsKey(expr.name.lexeme)) { if (scopes[scopes.Count - 1][expr.name.lexeme] == false) { Jingle.Error(expr.name, "Cannot read local variable in its own initializer."); } } resolveLocal(expr, expr.name); return(null); }
private Stmt classDeclaration() { 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.COLON, "Expect '{' before class body."); List <Stmt.Function> methods = new List <Stmt.Function>(); while (!check(TokenType.END) && !isAtEnd()) { methods.Add(function("method")); } consume(TokenType.END, "Expect '}' after class body."); return(new Stmt.Class(name, superclass, methods)); }
public string visitVariableExpr(Expr.Variable expr) { return(""); }
public Class(Token name, Expr.Variable superclass, List <Stmt.Function> methods) { this.name = name; this.superclass = superclass; this.methods = methods; }
public object visitVariableExpr(Expr.Variable expr) { return(lookUpVariable(expr.name, expr)); }