public While(Expr condition, Stmt body) { Condition = condition; Body = body; }
public StmtIf(Expr _condition, Stmt _thenBranch, Stmt _elseBranch) { condition = _condition; thenBranch = _thenBranch; elseBranch = _elseBranch; }
void execute(Stmt s) { s.accept(this); }
private void Execute(Stmt stmt) { stmt.Accept(this); }
public StmtWhile(Expr _condition, Stmt _body) { condition = _condition; body = _body; }
public If(Expr condition, Stmt thenBranch, Stmt elseBranch) { this.condition = condition; this.thenBranch = thenBranch; this.elseBranch = elseBranch; }
private Stmt ForStatement() { //forStmt → "for" "(" ( varDecl | exprStmt | ";" ) expression? ";" expression? ")" statement ; if (!TryParse(LEFT_PAREN)) { throw new ParserError(Current, "'(' expected after 'for'."); } //initializer is optional Stmt initializer = null; if (!TryParse(SEMICOLON)) //initializer skipped? { if (TryParse(VAR)) { initializer = VarDeclaration(); } else { initializer = ExpressionStatement(); } } //condition is optional Expr condition = null; if (!TryParse(SEMICOLON)) //condition skipped? { condition = Expression(); } if (!TryParse(SEMICOLON)) { throw new ParserError(Current, "';' expected after 'for' loop condition."); } //increment is also optional Expr increment = null; if (!TryParse(RIGHT_PAREN)) //increment skipped? { increment = Expression(); } if (!TryParse(RIGHT_PAREN)) { throw new ParserError(Current, "')' expected after 'for' clauses."); } //For is represented as Syntax-Tree build from primitives //{ // var i = 0; // while (i < 10) // { // print i; // i = i + 1; // } //} Stmt body = Statement(); //combine body and increment in the inner block if (increment != null) { body = new Block(new List <Stmt> { body, new ExpressionStatement(increment) }); } //wrap body in while loop with condition if (condition != null) { body = new WhileStatement(condition, body); } //if there's an initializer combine it with body to form the outer block if (initializer != null) { body = new Block(new List <Stmt> { initializer, body }); } return(body); }
void Resolve(Stmt stmt) { stmt.Accept(this); }
public While(Expr condition, Stmt body) { this.condition = condition; this.body = body; }
public If(Expr Condition, Stmt ThenBranch, Stmt ElseBranch) { this.Condition = Condition; this.ThenBranch = ThenBranch; this.ElseBranch = ElseBranch; }
public While(Expr Condition, Stmt Body) { this.Condition = Condition; this.Body = Body; }
public IfStatement(Expr condition, Stmt thenBranch, Stmt elseBranch) { Condition = condition; ThenBranch = thenBranch; ElseBranch = elseBranch; }
public WhileStatement(Expr condition, Stmt body) { Condition = condition; Body = body; }
private void Resolve(Stmt statement) { statement.Accept(this); }