public If(Expr condition, Stmt then, Stmt el) { this.condition = condition; this.then = then; this.el = el; }
public While(Expr condition, Stmt body) { this.condition = condition; this.body = body; }
private void Resolve(Stmt stmt) { stmt.Accept(this); }
public void Execute(Stmt statement) { statement.Accept(this); }
private Stmt ForStatement() { Consume(TokenType.LEFT_PAREN, "Expect '(' after for statement."); Stmt initializer; if (Match(TokenType.SEMICOLON)) { initializer = null; } else if (Match(TokenType.LET)) { initializer = LetDeclaration(); } else { initializer = ExpressionStatement(); } Expr cond = null; if (!Check(TokenType.SEMICOLON)) { cond = Expression(); } Consume(TokenType.SEMICOLON, "Expect ';' after condition in for statement"); Expr increment = null; if (!Check(TokenType.RIGHT_PAREN)) { increment = Expression(); } Consume(TokenType.RIGHT_PAREN, "Expect ')' after for expressions."); Stmt body = Statement(); if (increment != null) { body = new Stmt.Block(new List <Stmt>() { body, new Stmt.Expression(increment) }); } if (cond == null) { cond = new Expr.Literal(true); } body = new Stmt.While(cond, body); if (initializer != null) { body = new Stmt.Block(new List <Stmt>() { initializer, body }); } return(body); }