public Unit VisitWhileStmt(Stmt.While stmt) { Resolve(stmt.Condition); Resolve(stmt.Body); return(new Unit()); }
/// <summary> /// Parse a for loop /// </summary> /// <returns>The statement</returns> private Stmt ForStatement() { _loop_depth++; try { Consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'."); // Initializer Stmt initializer; if (Match(TokenType.SEMICOLON)) { // No initialiser initializer = null; } else if (Match(TokenType.VAR)) { // Its a variable decalration initializer = VarDeclaration(); } else { // Its an expression // This must be a _statement_ 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.SEMICOLON)) { increment = Expression(); } Consume(TokenType.RIGHT_PAREN, "Expect ')' after for clauses."); // Body Stmt body = Statement(); // Convert to a while loop if (increment != null) { body = new Stmt.Block(new[] { body, new Stmt.ExpressionStatement(increment) }); } if (condition == null) { // No condition, so set to true condition = new Expr.Literal(true); } body = new Stmt.While(condition, body); if (initializer != null) { body = new Stmt.Block(new[] { initializer, body }); } return(body); } finally { _loop_depth--; } }
public object VisitWhileStmt(Stmt.While stmt, object options) { throw new NotImplementedException(); }
public object visitWhileStmt(Stmt.While stmt) { resolve(stmt.condition); resolve(stmt.body); return(null); }
public object VisitWhileStmt(Stmt.While stmt) { Resolve(stmt.Condition); Resolve(stmt.Body); return(null); }
private Stmt ForStatment() { try { this.LoopCounter += 1; Consume(LEFT_PAREN, "Exepect '(' after 'for."); Stmt initialiser; if (Match(SEMICOLON)) { initialiser = null; } else if (Match(VAR)) { initialiser = VarDeclaration(); } else { initialiser = ExpressionStatement(); } Expr Condition = null; if (!Check(SEMICOLON)) { Condition = Expression(); } Consume(SEMICOLON, "Expect ';' after loop condition."); Expr increment = null; if (!Check(RIGHT_PAREN)) { increment = Expression(); } Consume(RIGHT_PAREN, "Expect ')' after for clausess."); Stmt body = Statement(); if (increment != null) { body = new Stmt.Block(new List <Stmt> { body, new Stmt.ExpressionStmt(increment) }); } if (Condition == null) { Condition = new Expr.Literal(true); } body = new Stmt.While(Condition, body); if (initialiser != null) { body = new Stmt.Block(new List <Stmt> { initialiser, body }); } return(body); } finally { LoopCounter--; } }
public Stmt VisitWhileStmt(Stmt.While stmt) { throw new NotImplementedException(); }
private Stmt ForStatement() { Consume(LeftParen, "Expect '(' after 'for'."); Stmt initializer; if (Match(Semicolon)) { initializer = null; } else if (Match(Var)) { initializer = VarDeclaration(); } else { initializer = ExpressionStatement(); } Expr condition = null; if (!Check(Semicolon)) { condition = Expression(); } Consume(Semicolon, "Expect ';' after loop condition."); Expr increment = null; if (!Check(RightParen)) { increment = Expression(); } Consume(RightParen, "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 object VisitWhileStmt(Stmt.While stmt, object options = null) { return(null); }
private Stmt ForStatement() { // The "for" implementation is a bit special in that it doesn't use any special AST nodes of its own. // Instead, it just desugars the for loop into already existing elements in our toolbox. // More details: http://craftinginterpreters.com/control-flow.html#desugaring Consume(LEFT_PAREN, "Expect '(' after 'for'."); Stmt initializer; if (Match(SEMICOLON)) { initializer = null; } else if (Match(VAR)) { initializer = VarDeclaration(); } else { initializer = ExpressionStatement(); } Expr condition = null; if (!Check(SEMICOLON)) { condition = Expression(); } Consume(SEMICOLON, "Expect ';' after loop condition."); Expr increment = null; if (!Check(RIGHT_PAREN)) { increment = Expression(); } Consume(RIGHT_PAREN, "Expect ')' after for clauses."); Stmt body = Statement(); if (increment != null) { body = new Stmt.Block(new List <Stmt> { body, new Stmt.ExpressionStmt(increment) }); } 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 string VisitWhileStmt(Stmt.While stmt) { return(Parenthesize2("while", stmt.Condition, stmt.Body)); }
private Stmt ForStatement() { Consume(LEFT_PAREN, "Expected \"(\" after \"for\"."); Stmt initializer; if (Match(SEMICOLON)) { initializer = null; } else if (Match(VAR)) { initializer = VarDeclaration(); } else { initializer = ExpressionStatement(); } Expr condition = null; if (!Check(SEMICOLON)) { condition = Expression(); } Consume(SEMICOLON, "Expected \";\" after loop condition"); Expr increment = null; if (!Check(RIGHT_PAREN)) { increment = Expression(); } Consume(RIGHT_PAREN, "Expected \")\" after 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); }