// File: /workspace/github_cpp_makefile_star2_O1/jaldhar[P]Lets-Build-a-Simple-Interpreter/calc1.cc
// Function: Interpreter::get_next_token()
Token Interpreter::get_next_token() {
    // Skip leading white space.
    while (_pos < _text.length() && isspace(_text[_pos])) {
        _pos++;
    }

    // is _pos index past the end of _text ?
    // if so, then return ENDOFFILE token because there is no more
    // input left to convert into tokens
    if (_pos >= _text.length()) {
        Token token(TOKENTYPE::ENDOFFILE, 0);
        cerr << token << endl;
        return token;
    }

    // get a character at the position _pos and decide what token to create
    // based on the single character
    char current_char = _text[_pos];

    // if the next characters are digits then convert them to an integer, create
    // an INTEGER token, increment _pos index to point to the next character
    // after the digits, and return the INTEGER token
    if (isdigit(current_char)) {
        long total = 0;
        while (isdigit(_text[_pos])) {
            total *= 10;
            total += (_text[_pos] - '0');
            _pos++;
        }
        Token token(TOKENTYPE::INTEGER, total);
        cerr << token << endl;
        return token;
    }

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

    if (current_char == '-') {
        Token token(TOKENTYPE::MINUS, '-');
        cerr << token << endl;
        _pos++;
        return token;
    }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq (%rdi), %r14
movq 0x8(%rdi), %r15
movq 0x8(%r14), %r12
cmpq %r12, %r15
setb %bpl
jae 0x2535
movq %rdi, %rbx
movq (%r14), %r13
movsbl (%r13,%r15), %edi
callq 0x2040
testl %eax, %eax
je 0x24d8
incq %r15
movq %r15, 0x8(%rbx)
cmpq %r15, %r12
je 0x2535
movsbl (%r13,%r15), %edi
callq 0x2040
incq %r15
testl %eax, %eax
jne 0x24b3
decq %r15
cmpq %r12, %r15
setb %bpl
testb %bpl, %bpl
je 0x2535
movq (%r14), %rax
movsbl (%rax,%r15), %r14d
leal -0x30(%r14), %ecx
cmpl $0x9, %ecx
ja 0x2596
movq 0x8(%rbx), %rcx
movsbl (%rax,%rcx), %esi
leal -0x30(%rsi), %edx
cmpl $0x9, %edx
ja 0x25b7
incq %rcx
xorl %edx, %edx
leaq (%rdx,%rdx,4), %rdx
movsbq %sil, %rsi
leaq (%rsi,%rdx,2), %rdx
addq $-0x30, %rdx
movq %rcx, 0x8(%rbx)
movsbl (%rax,%rcx), %esi
movl %esi, %edi
addl $-0x30, %edi
incq %rcx
cmpl $0xa, %edi
jb 0x250b
jmp 0x25b9
movq %rsp, %rsi
movl $0x0, (%rsi)
movq $0x0, 0x8(%rsi)
movq 0x2aa3(%rip), %rbx      # 0x4ff0
movq %rbx, %rdi
callq 0x2370
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movl (%rsp), %eax
movq 0x8(%rsp), %rdx
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %r14b, %eax
cmpl $0x2d, %eax
je 0x25cb
cmpl $0x2b, %eax
jne 0x261b
movq %rsp, %rsi
movl $0x2, (%rsi)
movq $0x2b, 0x8(%rsi)
jmp 0x25dc
xorl %edx, %edx
movq %rsp, %rsi
movl $0x1, (%rsi)
movq %rdx, 0x8(%rsi)
jmp 0x2546
movq %rsp, %rsi
movl $0x3, (%rsi)
movq $0x2d, 0x8(%rsi)
movq 0x2a0d(%rip), %r14      # 0x4ff0
movq %r14, %rdi
callq 0x2370
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x20e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
incq 0x8(%rbx)
jmp 0x257c
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x2120
leaq 0xa1b(%rip), %rsi       # 0x304a
movl $0x1a, %edx
movq %rbx, %rdi
callq 0x2110
leaq 0x10(%rsp), %rsi
movb %r14b, (%rsi)
leaq 0x30(%rsp), %rdi
movl $0x1, %edx
callq 0x2110
movl $0x8, %edi
callq 0x2080
movq %rax, %rbx
leaq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2150
movq 0x10(%rsp), %rax
movq %rax, (%rbx)
movq 0x2932(%rip), %rsi      # 0x4fb0
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2170
movq %rax, %r14
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x26a6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2100
xorl %eax, %eax
jmp 0x26af
movq %rax, %r14
movb $0x1, %al
testb %al, %al
je 0x26c0
movq %rbx, %rdi
callq 0x20b0
jmp 0x26c0
movq %rax, %r14
movq 0x28f9(%rip), %rsi      # 0x4fc0
leaq 0x30(%rsp), %rdi
callq 0x2090
leaq 0xa0(%rsp), %rdi
callq 0x2050
movq %r14, %rdi
callq 0x2180