private void Resolve(Stmt stmt) { stmt.Accept(this); }
private Stmt ForStatement() { Consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'."); Stmt initializer; if (Match(TokenType.SEMICOLON)) { initializer = null; } else if (Match(TokenType.VAR)) { initializer = VarDeclaration(); } else { initializer = ExpressionStatement(); } Expr condition = null; if (!Check(TokenType.SEMICOLON)) { condition = Expression(); } Consume(TokenType.SEMICOLON, "Expect ';' after loop condition."); Expr increment = null; if (!Check(TokenType.RIGHT_PAREN)) { increment = Expression(); } Consume(TokenType.RIGHT_PAREN, "Expect ')' after for clauses."); Stmt body = Statement(); if (increment != null) { body = new Stmt.Block(new List <Stmt>() { body, new Stmt.Expression(increment), }); } if (condition == null) { condition = new Expr.Literal(true); } body = new Stmt.While(condition, body); if (initializer != null) { body = new Stmt.Block(new List <Stmt> { initializer, body }); } return(body); }
public If(Expr condition, Stmt thenBranch, Stmt elseBranch) { this.condition = condition; this.thenBranch = thenBranch; this.elseBranch = elseBranch; }
private void Execute(Stmt stmt) { stmt.Accept(this); }
public While(Expr condition, Stmt body) { this.condition = condition; this.body = body; }