private Stmt ClassDeclaration() { Token name = Consume(TokenType.IDENTIFIER, "Expect class name."); Expr.Variable baseclass = null; if (Match(TokenType.LESS)) { Consume(TokenType.IDENTIFIER, "Expect baseclass name."); baseclass = 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, baseclass, methods)); }
public Void VisitVariableExpr(Expr.Variable expr) { try { if (scopes.Count > 0 && scopes.Last()[expr.name.Lexeme] == false) { ElizScriptCompiler.Error(expr.name, "Cannot read local variable in its own initializer."); } } catch { } ResolveLocal(expr, expr.name); return(null); }
public object VisitVariableExpr(Expr.Variable expr) { return(LookUpVariable(expr.name, expr)); //return environment.Get(expr.name); }
public Class(Token name, Expr.Variable baseclass, List <Function> methods) { this.name = name; this.methods = methods; this.baseclass = baseclass; }