private Stmt classDeclaration() { Token name = consume(TokenType.TOKEN_IDENTIFIER, "Expect class name."); Expr.Variable superclass = null; if (match(TokenType.TOKEN_LESS)) { consume(TokenType.TOKEN_IDENTIFIER, "Expect superclass name."); superclass = new Expr.Variable(previous()); } consume(TokenType.TOKEN_LEFT_BRACE, "Expect '{' before class body."); List <Stmt.Function> methods = new List <Stmt.Function>(); while (!check(TokenType.TOKEN_RIGHT_BRACE) && !isAtEnd()) { methods.Add(function("method")); } consume(TokenType.TOKEN_RIGHT_BRACE, "Expect '}' after class body."); return(new Stmt.Class(name, superclass, methods)); }
public Class(Token name, Expr.Variable superclass, List <Stmt.Function> methods) { this.name = name; this.superclass = superclass; this.methods = methods; }