public Void visitBlockStmt(Stmt.Block stmt) { BeginScope(); Resolve(stmt.statements); EndScope(); return(null); }
public Void visitBlockStmt(Stmt.Block stmt) { bool previous = REPL; REPL = false; ExecuteBlock(stmt.statements, new Env(environment)); REPL = previous; return(null); }
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); }