WhileStmtAst While() { Token keywrd = Match(TokenKind.WhileKeyword); Match(TokenKind.LeftParen); ExprAst cond = Expr(); Match(TokenKind.RightParen); StmtAst then = Stmt(); return(new WhileStmtAst(keywrd, cond, then)); }
ForStmtAst For() { Token keywrd = Match(TokenKind.ForKeyword); Match(TokenKind.LeftParen); StmtAst init = Stmt(); ExprAst cond = Expr(); Match(TokenKind.Semicol); ExprAst step = Expr(); Match(TokenKind.RightParen); StmtAst then = Stmt(); return(new ForStmtAst(keywrd, init, cond, step, then)); }
IfStmtAst If() { Token keywrd = Match(TokenKind.IfKeyword); Match(TokenKind.LeftParen); ExprAst cond = Expr(); Match(TokenKind.RightParen); StmtAst then = Stmt(); StmtAst?elze = null; if (current.kind is TokenKind.ElseKeyword) { Next(); elze = Stmt(); } return(new IfStmtAst(keywrd, cond, then, elze)); }