// Stmt Visitors public void Visit(Stmt.Block stmt) { ExecuteBlock(stmt.statements, new Environment(environment)); }
// Stmt Visitors public void Visit(Stmt.Block block) { // do nothing }
private Stmt ForStatement() { Consume(TokenType.LeftParen, "Expect '(' after 'for'"); // initializer Stmt initializer = null; if (Match(TokenType.Semicolon)) { initializer = null; } else if (Match(TokenType.Var)) { initializer = VarDeclaration(); } else { initializer = ExpressionStatement(); } // condition Expr condition = null; if (!Check(TokenType.Semicolon)) { condition = Expression(); } Consume(TokenType.Semicolon, "Expect ';' after loop condition."); // increment Expr increment = null; if (!Check(TokenType.RightParen)) { increment = Expression(); } Consume(TokenType.RightParen, "Expect ')' after for clauses."); // body Stmt body = Statement(); // desugar if (increment != null) { List <Stmt> statements = new List <Stmt>(); statements.Add(body); statements.Add(new Stmt.Expression(increment)); body = new Stmt.Block(statements); } if (condition == null) { condition = new Expr.Literal(true); } body = new Stmt.While(condition, body); if (initializer != null) { List <Stmt> statements = new List <Stmt>(); statements.Add(initializer); statements.Add(body); body = new Stmt.Block(statements); } return(body); }
// Stmt Visitors public void Visit(Stmt.Block stmt) { BeginScope(); Resolve(stmt.statements); EndScope(); }