public Void Visit_WhileStmt(WhileStmt stmt) { Resolve(stmt.condition); Resolve(stmt.body); return(null); }
private Stmt ForStatement() { Expect(TokenType.LeftParen, ErrorType.ExpectedOpenParen); Stmt initializer; if (CheckCurrentToken(TokenType.Semicolon)) { initializer = null; Advance(); } else if (CheckCurrentToken(TokenType.Var)) { Advance(); initializer = VarDeclaration(); } else { initializer = ExpressionStatement(); } Expr condition = null; if (!CheckCurrentToken(TokenType.Semicolon)) { condition = Expression(); } Expect(TokenType.Semicolon, ErrorType.ExpectedSemicolon); Expr increment = null; if (!CheckCurrentToken(TokenType.RightParen)) { increment = Expression(); } Expect(TokenType.RightParen, ErrorType.ExpectedClosedParen); Stmt body = Statement(); if (increment != null) { body = new BlockStmt(new List <Stmt> { body, new ExpressionStmt(increment) }); } if (condition == null) { condition = new LiteralExpr(true); } body = new WhileStmt(condition, body); if (initializer != null) { body = new BlockStmt(new List <Stmt> { initializer, body }); } return(body); }
public string Visit_WhileStmt(WhileStmt stmt) { return(Parenthesize("While", new ExpressionStmt(stmt.condition), stmt.body)); }