// File: jaldhar[P]Lets-Build-a-Simple-Interpreter/calc6.cc
// Function: Lexer::get_next_token()
Token Lexer::get_next_token() {

    while (_current_char != '\0') {

        if (isspace(_current_char)) {
            skip_whitespace();
            continue;
        }

        if (isdigit(_current_char)) {
            Token token(TOKENTYPE::INTEGER, integer());
            cerr << token << endl;
            return token;
        }

        if (_current_char == '*') {
            advance();
            Token token(TOKENTYPE::MUL, '*');
            cerr << token << endl;
            return token;
        }

        if (_current_char == '/') {
            advance();
            Token token(TOKENTYPE::DIV, '/');
            cerr << token << endl;
            return token;
        }

        if (_current_char == '+') {
            advance();
            Token token(TOKENTYPE::PLUS, '+');
            cerr << token << endl;
            return token;
        }

        if (_current_char == '-') {
            advance();
            Token token(TOKENTYPE::MINUS, '-');
            cerr << token << endl;
            return token;
        }

        if (_current_char == '(') {
            advance();
            Token token(TOKENTYPE::LPAREN, '(');
            cerr << token << endl;
            return token;
        }

        if (_current_char == ')') {
            advance();
            Token token(TOKENTYPE::RPAREN, ')');
            cerr << token << endl;
            return token;
        }

        ostringstream out;
        out << "Error parsing input. Got: " << _current_char;
        throw(out.str().c_str());
    }

    Token token(TOKENTYPE::ENDOFFILE, '\0');
    cerr << token << endl;
    return token;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x0, %eax
je 0x29fd
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %edi
callq 0x2040
cmpl $0x0, %eax
je 0x26a1
movq -0x1d0(%rbp), %rdi
callq 0x2a50
jmp 0x266a
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %edi
callq 0x2170
cmpl $0x0, %eax
je 0x26f7
movq -0x1d0(%rbp), %rdi
callq 0x2ab0
movq %rax, %rdx
leaq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x32d0
movq 0x3916(%rip), %rdi      # 0x5ff0
leaq -0x10(%rbp), %rsi
callq 0x2590
movq %rax, %rdi
movq 0x38bb(%rip), %rsi      # 0x5fa8
callq 0x21a0
jmp 0x2a2b
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x2a, %eax
jne 0x274a
movq -0x1d0(%rbp), %rdi
callq 0x2bb0
leaq -0x10(%rbp), %rdi
movl $0x4, %esi
movl $0x2a, %edx
callq 0x32d0
movq 0x38c3(%rip), %rdi      # 0x5ff0
leaq -0x10(%rbp), %rsi
callq 0x2590
movq %rax, %rdi
movq 0x3868(%rip), %rsi      # 0x5fa8
callq 0x21a0
jmp 0x2a2b
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x2f, %eax
jne 0x279d
movq -0x1d0(%rbp), %rdi
callq 0x2bb0
leaq -0x10(%rbp), %rdi
movl $0x5, %esi
movl $0x2f, %edx
callq 0x32d0
movq 0x3870(%rip), %rdi      # 0x5ff0
leaq -0x10(%rbp), %rsi
callq 0x2590
movq %rax, %rdi
movq 0x3815(%rip), %rsi      # 0x5fa8
callq 0x21a0
jmp 0x2a2b
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x2b, %eax
jne 0x27f0
movq -0x1d0(%rbp), %rdi
callq 0x2bb0
leaq -0x10(%rbp), %rdi
movl $0x2, %esi
movl $0x2b, %edx
callq 0x32d0
movq 0x381d(%rip), %rdi      # 0x5ff0
leaq -0x10(%rbp), %rsi
callq 0x2590
movq %rax, %rdi
movq 0x37c2(%rip), %rsi      # 0x5fa8
callq 0x21a0
jmp 0x2a2b
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x2d, %eax
jne 0x2843
movq -0x1d0(%rbp), %rdi
callq 0x2bb0
leaq -0x10(%rbp), %rdi
movl $0x3, %esi
movl $0x2d, %edx
callq 0x32d0
movq 0x37ca(%rip), %rdi      # 0x5ff0
leaq -0x10(%rbp), %rsi
callq 0x2590
movq %rax, %rdi
movq 0x376f(%rip), %rsi      # 0x5fa8
callq 0x21a0
jmp 0x2a2b
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x28, %eax
jne 0x2896
movq -0x1d0(%rbp), %rdi
callq 0x2bb0
leaq -0x10(%rbp), %rdi
movl $0x6, %esi
movl $0x28, %edx
callq 0x32d0
movq 0x3777(%rip), %rdi      # 0x5ff0
leaq -0x10(%rbp), %rsi
callq 0x2590
movq %rax, %rdi
movq 0x371c(%rip), %rsi      # 0x5fa8
callq 0x21a0
jmp 0x2a2b
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x29, %eax
jne 0x28e9
movq -0x1d0(%rbp), %rdi
callq 0x2bb0
leaq -0x10(%rbp), %rdi
movl $0x7, %esi
movl $0x29, %edx
callq 0x32d0
movq 0x3724(%rip), %rdi      # 0x5ff0
leaq -0x10(%rbp), %rsi
callq 0x2590
movq %rax, %rdi
movq 0x36c9(%rip), %rsi      # 0x5fa8
callq 0x21a0
jmp 0x2a2b
leaq -0x190(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x2220
movq -0x1e0(%rbp), %rdi
leaq 0x1758(%rip), %rsi      # 0x4062
callq 0x2180
movq %rax, -0x1d8(%rbp)
jmp 0x2918
movq -0x1d8(%rbp), %rdi
movq -0x1d0(%rbp), %rax
movsbl 0x10(%rax), %esi
callq 0x21f0
jmp 0x2931
movb $0x1, -0x1c1(%rbp)
movl $0x8, %edi
callq 0x20c0
movq %rax, -0x1e8(%rbp)
leaq -0x1c0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x2190
jmp 0x295e
leaq -0x1c0(%rbp), %rdi
callq 0x20a0
movq -0x1e8(%rbp), %rdi
movq %rax, (%rdi)
movb $0x0, -0x1c1(%rbp)
movq 0x362e(%rip), %rsi      # 0x5fb0
xorl %eax, %eax
movl %eax, %edx
callq 0x22a0
jmp 0x2a47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x198(%rbp)
movl %eax, -0x19c(%rbp)
jmp 0x29ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x198(%rbp)
movl %eax, -0x19c(%rbp)
jmp 0x29d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x198(%rbp)
movl %eax, -0x19c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x20e0
testb $0x1, -0x1c1(%rbp)
jne 0x29e1
jmp 0x29ed
movq -0x1e8(%rbp), %rdi
callq 0x2120
jmp 0x29ef
leaq -0x190(%rbp), %rdi
callq 0x2070
jmp 0x2a3b
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x32d0
movq 0x35dd(%rip), %rdi      # 0x5ff0
leaq -0x10(%rbp), %rsi
callq 0x2590
movq %rax, %rdi
movq 0x3582(%rip), %rsi      # 0x5fa8
callq 0x21a0
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rdx
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq -0x198(%rbp), %rdi
callq 0x22b0
nopw (%rax,%rax)