public Void Visit_BlockStmt(BlockStmt stmt) { BeginScope(); Resolve(stmt.statements); EndScope(); return(null); }
public object VisitBlockStmt(BlockStmt stmt) { BeginScope(); Resolve(stmt.Statements); EndScope(); return(null); }
// ForStatement -> "for" "(" ( varDecl | ExpressionStmt | ";" ) Expression? ";" Expression? ";" ")" Statement private AstNode ForStatement() { Consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'."); AstNode initializer = default(AstNode); if (!Match(TokenType.SEMICOLON)) { initializer = Match(TokenType.VAR) ? VarDeclaration() : ExpressionStatement(); } AstNode condition = Check(TokenType.SEMICOLON) ? new LiteralExpr(true) : Expression(); Consume(TokenType.SEMICOLON, "Expect ';' after 'for' loop condition."); AstNode increment = Check(TokenType.RIGHT_PAREN) ? null : Expression(); Consume(TokenType.RIGHT_PAREN, "Expect ')' after for clauses."); AstNode body = Statement(); // Desugarize for loop // From: for (var i = 0; i < 10; ++i) doStuff(); // To: var i = 0; while (i < 10) { doStuff(); i = i+1; } if (increment != null) { body = new BlockStmt(new List <AstNode> { body, new ExpressionStmt(increment) }); } body = new WhileStmt(condition, body); if (initializer != null) { body = new BlockStmt(new List <AstNode> { initializer, body }); } return(body); }
public object VisitBlockStmt(BlockStmt stmt) { ExecuteBlock(stmt.Statements, new Scope(_scope)); 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 Void Visit_BlockStmt(BlockStmt stmt) { ExecuteBlock(stmt.statements, new Environment(_environment)); return(null); }
public string Visit_BlockStmt(BlockStmt stmt) { return(Parenthesize("Block", stmt.statements.ToArray())); }