public WhileStmt(Expr Condition, Stmt BodyStatement) { this.Condition = Condition; this.BodyStatement = BodyStatement; }
public void Execute(Stmt stmt) { stmt.Accept(this); }
public IfStmt(Expr Condition, Stmt ThenStatement, Stmt ElseStatement) { this.Condition = Condition; this.ThenStatement = ThenStatement; this.ElseStatement = ElseStatement; }
Stmt ForStatement() { Consume(TokenType.LeftParen, "Expected opening '('."); Stmt initializer = null; if (MatchNext(TokenType.Var)) { initializer = VarDeclaration(); } else if (MatchNext(TokenType.SemiColon)) { initializer = null; } else { initializer = ExpressionStatement(); } Expr conditional = null; if (!MatchNext(TokenType.SemiColon)) { conditional = Expression(); Consume(TokenType.SemiColon, "Expecting ';' in for loop"); } Expr incrementer = null; if (!MatchNext(TokenType.RightParen)) { incrementer = Expression(); Consume(TokenType.RightParen, "Expected closing ')' in for loop"); } var body = Statement(); if (incrementer != null) { body = new BlockStmt(new List <Stmt> { body, new ExpressionStmt(incrementer) }); } if (conditional == null) { conditional = new LiteralExpr(true); } body = new WhileStmt(conditional, body); if (initializer != null) { body = new BlockStmt(new List <Stmt> { initializer, body }); } return(body); }