Esempio n. 1
0
    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));
    }
Esempio n. 2
0
    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));
    }
Esempio n. 3
0
    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));
    }