def parse_while_stat(lexer):
     lexer.get_next_token_of_kind(TokenKind.KW_WHILE)
     exp = ExpParser.parse_exp(lexer)
     lexer.get_next_token_of_kind(TokenKind.KW_DO)
     block = Parser.parse_block(lexer)
     lexer.get_next_token_of_kind(TokenKind.KW_END)
     return lua_stat.WhileStat(exp, block)
    def finish_for_num_stat(lexer, line_of_for, var_name):
        lexer.get_next_token_of_kind(TokenKind.OP_ASSIGN)
        init_exp = ExpParser.parse_exp(lexer)
        lexer.get_next_token_of_kind(TokenKind.SEP_COMMA)
        limit_exp = ExpParser.parse_exp(lexer)

        if lexer.look_ahead() == TokenKind.SEP_COMMA:
            lexer.get_next_token()
            step_exp = ExpParser.parse_exp(lexer)
        else:
            step_exp = lua_exp.IntegerExp(lexer.get_line(), 1)

        line_of_do, _ = lexer.get_next_token_of_kind(TokenKind.KW_DO)
        block = Parser.parse_block(lexer)
        lexer.get_next_token_of_kind(TokenKind.KW_END)

        return lua_stat.ForNumStat(line_of_for, line_of_do, var_name, init_exp, limit_exp, step_exp, block)
    def parse_if_stat(lexer):
        exps = []
        blocks = []

        lexer.get_next_token_of_kind(TokenKind.KW_IF)
        exps.append(ExpParser.parse_exp(lexer))
        lexer.get_next_token_of_kind(TokenKind.KW_THEN)
        blocks.append(Parser.parse_block(lexer))

        while lexer.look_ahead() == TokenKind.KW_ELSEIF:
            lexer.get_next_token()
            exps.append(ExpParser.parse_exp(lexer))
            lexer.get_next_token_of_kind(TokenKind.KW_THEN)
            blocks.append(Parser.parse_block(lexer))

        if lexer.look_ahead() == TokenKind.KW_ELSE:
            lexer.get_next_token()
            exps.append(lua_exp.TrueExp(lexer.get_line()))
            blocks.append(Parser.parse_block(lexer))

        lexer.get_next_token_of_kind(TokenKind.KW_END)
        return lua_stat.IfStat(exps, blocks)
 def parse_repeat_stat(lexer):
     lexer.get_next_token_of_kind(TokenKind.KW_REPEAT)
     block = Parser.parse_block(lexer)
     lexer.get_next_token_of_kind(TokenKind.KW_UNTIL)
     exp = ExpParser.parse_exp(lexer)
     return lua_stat.RepeatStat(block, exp)