// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1b8, %rsp            # imm = 0x1B8
movq (%rdi), %r13
movq %rdi, 0x8(%rsp)
movq 0x8(%rdi), %r15
movq 0x8(%r13), %rbx
cmpq %rbx, %r15
jae 0x142a
movq (%r13), %r12
movb (%r12,%r15), %bpl
movsbl %bpl, %r14d
movl %r14d, %edi
callq 0x1030
testl %eax, %eax
je 0x1458
incq %r15
movq 0x8(%rsp), %rax
movq %r15, 0x8(%rax)
jmp 0x13ff
leaq 0x10(%rsp), %rsi
andl $0x0, (%rsi)
andq $0x0, 0x8(%rsi)
movq 0x2bb2(%rip), %rbx      # 0x3ff0
movq %rbx, %rdi
callq 0x1302
movq %rbx, %rdi
callq 0x1080
xorl %r14d, %r14d
xorl %eax, %eax
jmp 0x1546
leal -0x30(%r14), %eax
cmpl $0x9, %eax
ja 0x1495
incq %r15
xorl %r14d, %r14d
movsbl %bpl, %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x14e1
imulq $0xa, %r14, %rax
movsbq %bpl, %rcx
leaq (%rax,%rcx), %r14
addq $-0x30, %r14
movq 0x8(%rsp), %rax
movq %r15, 0x8(%rax)
movb (%r12,%r15), %bpl
incq %r15
jmp 0x1467
movzbl %bpl, %eax
cmpl $0x2d, %eax
je 0x150c
cmpl $0x2b, %eax
jne 0x155b
leaq 0x10(%rsp), %rsi
movl $0x2, (%rsi)
movq $0x2b, 0x8(%rsi)
movq 0x2b2f(%rip), %r14      # 0x3ff0
movq %r14, %rdi
callq 0x1302
movq %r14, %rdi
callq 0x1080
movq 0x8(%rsp), %rax
incq 0x8(%rax)
pushq $0x2
popq %rax
pushq $0x2b
jmp 0x1544
leaq 0x10(%rsp), %rsi
movl $0x1, (%rsi)
movq %r14, 0x8(%rsi)
movq 0x2af9(%rip), %rbx      # 0x3ff0
movq %rbx, %rdi
callq 0x1302
movq %rbx, %rdi
callq 0x1080
pushq $0x1
popq %rax
jmp 0x1546
leaq 0x10(%rsp), %rsi
movl $0x3, (%rsi)
movq $0x2d, 0x8(%rsi)
movq 0x2aca(%rip), %r14      # 0x3ff0
movq %r14, %rdi
callq 0x1302
movq %r14, %rdi
callq 0x1080
movq 0x8(%rsp), %rax
incq 0x8(%rax)
pushq $0x3
popq %rax
pushq $0x2d
popq %r14
movq %r14, %rdx
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x1100
leaq 0xadb(%rip), %rsi       # 0x204a
movq %rbx, %rdi
callq 0x10e0
movq %rax, %rdi
movl %r14d, %esi
callq 0x10f0
pushq $0x8
popq %rdi
callq 0x1090
movq %rax, %r14
leaq 0x48(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x1120
movq 0x20(%rsp), %rax
movq %rax, (%r14)
movq 0x2a0d(%rip), %rsi      # 0x3fb8
movq %r14, %rdi
xorl %edx, %edx
callq 0x1140
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1070
jmp 0x15d4
movq %rax, %rbx
movq %r14, %rdi
callq 0x10a0
jmp 0x15d4
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x1150