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.LEFT_BRACE, "Expect '{' before class body."); List <Stmt.Function> 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 object VisitVariableExpr(Expr.Variable expr) { if (scopes.Any() && scopes.Peek()[expr.Name.Lexeme] == false) { Lox.Error(expr.Name, "Cannot read local variable in its own initializer."); } ResolveLocal(expr, expr.Name); return(null); }
object Expr.IVisitor <object> .VisitVariableExpr(Expr.Variable expr) { if (scopes.Count > 0 && scopes.Peek().TryGetValue(expr.name.lexeme, out bool value)) { if (!value) { Lox.Error(expr.name, "Cannot read local variable in its own initializer."); } } ResolveLocal(expr, expr.name); return(null); }
public Unit VisitVariable(Expr.Variable expr) { // Because we recurse into the initializer expression (while the scope has the variable) // in 'NotReady'), we can use this to check that the initializer expression doesn't refer // to this variable. Resolution res; if (_scopes.Count != 0 && _scopes.Peek().TryGetValue(expr.Name.Lexeme, out res) && res == Resolution.NotReady) { _errors.AddResolverError(expr.Name, "Cannot read local variable in its own initializer"); } ResolveLocal(expr, expr.Name); return(Unit.Default); }
public Void Visit(Expr.Variable expr) { if (scopes.Any()) { var scope = scopes.Peek(); var name = expr.Name.Lexeme; if (scope.ContainsKey(name) && scope[name] == false) { Lox.Error(expr.Name, "Cannot read local variable in its own initializer."); } } ResolveLocal(expr, expr.Name); return(Void.Instance); }
public object VisitVariableExpr(Expr.Variable expr) { return(LookUpVariable(expr.Name, expr)); }
public string VisitVariable(Expr.Variable expr) { return(expr.Name.Lexeme); }
object Expr.IVisitor <object> .VisitVariableExpr(Expr.Variable expr) { return(LookUpVariable(expr.name, expr)); }
public Class(Token name, Expr.Variable superclass, List <Stmt.Function> methods) { this.name = name; this.superclass = superclass; this.methods = methods; }
public string VisitVariableExpr(Expr.Variable expr) { return(parenthesize("VAR", expr)); }