// File: /workspace/github_cpp_makefile_star2_O3/SeanLee97[P]LL1-Parser/scan.cpp
// Function: scan()
token scan() {
    image_index = 0;

    while (isspace(cur_char)) {
        cur_char = cin.get();
        cur_col++;
        if (cur_char == '\n') {
            cur_line++;
            cur_col = 0;
        }
    }
    tok_line = cur_line;  tok_col = cur_col;

    if (cur_char == EOF) {                     // end of file
        return make_token(tok_eof);
    }

    if (isalpha(cur_char)) {                   // identifier
        do {
            nextchar();
        } while (isdigit(cur_char) || isalpha(cur_char) || cur_char == '_');

        token_image[image_index] = 0;

        for (int w = first_rw; w <= last_rw; w++) {
            if (!strcmp(token_image, &token_names[w][3])) {
                return make_token(tok_num(w));
            }
        }
        return make_token(ident);
    }

    else if (isdigit(cur_char)) {              // literal
        tok_num tok = lit_int;
        do {
            nextchar();
        } while (isdigit(cur_char));
        if (cur_char == '.') {
            nextchar();
            if (!isdigit(cur_char)) {
                return make_token(tok_error);
            }
            tok = lit_real;
            do {
                nextchar();
            } while (isdigit(cur_char));
        }
        return make_token(tok);

    } else switch (cur_char) {                 // misc. other cases
        case ':':
            nextchar();
            if (cur_char != '=') {
                return make_token(colon);
            } else {
                nextchar();
                return make_token(becomes);
            }
            break;
        case '<':
            nextchar();
            if (cur_char != '=') {
                return make_token(op_lt);
            } else {
                nextchar();
                return make_token(op_le);
            }
            break;
        case '>':
            nextchar();
            if (cur_char != '=') {
                return make_token(op_gt);
            } else {
                nextchar();
                return make_token(op_ge);
            }
            break;
        case '=':
            nextchar();
            if (cur_char != '=') {
                return make_token(tok_error);
            } else {
                nextchar();
                return make_token(op_eq);
            }
            break;
        case '!':
            nextchar();
            if (cur_char != '=') {
                return make_token(tok_error);
            } else {
                nextchar();
                return make_token(op_ne);
            }
            break;
        case '+': nextchar(); return make_token(op_add);
        case '-': nextchar(); return make_token(op_sub);
        case '*': nextchar(); return make_token(op_mul);
        case '/': nextchar(); return make_token(op_div);
        case '(': nextchar(); return make_token(lparen);
        case ')': nextchar(); return make_token(rparen);
        case '[': nextchar(); return make_token(lbrac);
        case ']': nextchar(); return make_token(rbrac);
        case ',': nextchar(); return make_token(comma);
        case ';': nextchar(); return make_token(semic);
        default:  nextchar(); return make_token(tok_error);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl $0x0, 0x8b6c(%rip)      # 0xb2e4
movl 0x8b39(%rip), %r14d     # 0xb2b8
movl %r14d, %edi
callq 0x2050
testl %eax, %eax
je 0x27da
movq 0x884e(%rip), %r15      # 0xafe0
movq %r15, %rdi
callq 0x2220
movl %eax, %r14d
movl %eax, 0x8b15(%rip)      # 0xb2b8
movl 0x8b3e(%rip), %r12d     # 0xb2e8
incl %r12d
movl %r12d, 0x8b34(%rip)     # 0xb2e8
cmpl $0xa, %eax
jne 0x27cc
incl 0x8afd(%rip)            # 0xb2bc
movl $0x0, 0x8b1f(%rip)      # 0xb2e8
xorl %r12d, %r12d
movl %r14d, %edi
callq 0x2050
testl %eax, %eax
jne 0x2792
jmp 0x27e1
movl 0x8b07(%rip), %r12d     # 0xb2e8
movl 0x8ad5(%rip), %eax      # 0xb2bc
movl %eax, 0x8aff(%rip)      # 0xb2ec
movl %r12d, 0x8afc(%rip)     # 0xb2f0
cmpl $-0x1, %r14d
je 0x28ff
movl %r14d, %edi
callq 0x22a0
testl %eax, %eax
je 0x291c
movl 0x8ad0(%rip), %eax      # 0xb2e4
cmpl $0x63, %eax
jg 0x28a2
leaq 0x8adc(%rip), %r12      # 0xb300
movq 0x87b5(%rip), %r15      # 0xafe0
leal 0x1(%rax), %ecx
movl %ecx, 0x8ab0(%rip)      # 0xb2e4
cltq
movb %r14b, (%rax,%r12)
movq %r15, %rdi
callq 0x2220
movl %eax, %r14d
movl %eax, 0x8a6d(%rip)      # 0xb2b8
incl 0x8a97(%rip)            # 0xb2e8
cmpl $0xa, %eax
jne 0x2876
incl 0x8a60(%rip)            # 0xb2bc
movl $0x0, 0x8a82(%rip)      # 0xb2e8
movl $0xa, %edi
callq 0x22a0
testl %eax, %eax
jne 0x2897
jmp 0x28c1
leal -0x30(%r14), %eax
cmpl $0xa, %eax
jb 0x2897
movl %r14d, %edi
callq 0x22a0
testl %eax, %eax
setne %al
cmpl $0x5f, %r14d
sete %cl
orb %al, %cl
je 0x28c1
movl 0x8a47(%rip), %eax      # 0xb2e4
cmpl $0x64, %eax
jl 0x282b
leaq 0x58bf(%rip), %rdi      # 0x8168
leaq 0x58d0(%rip), %rsi      # 0x8180
leaq 0x5916(%rip), %rcx      # 0x81cd
movl $0x48, %edx
callq 0x2130
movslq 0x8a1c(%rip), %rax      # 0xb2e4
movb $0x0, (%rax,%r12)
movl $0x3, %r15d
leaq 0x88d6(%rip), %r14      # 0xb1b0
movq (%r14,%r15,8), %rsi
addq $0x3, %rsi
movq %r12, %rdi
callq 0x2250
testl %eax, %eax
je 0x2905
incq %r15
cmpq $0xc, %r15
jne 0x28da
movl $0x2, %r15d
jmp 0x2905
movl $0x1, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x2bd5
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leal -0x30(%r14), %eax
cmpl $0x9, %eax
ja 0x29e0
leaq 0x89d0(%rip), %r12      # 0xb300
movq 0x86a9(%rip), %r15      # 0xafe0
movslq 0x89a6(%rip), %rax      # 0xb2e4
cmpq $0x64, %rax
jge 0x28a2
leal 0x1(%rax), %ecx
movl %ecx, 0x8993(%rip)      # 0xb2e4
movb %r14b, (%rax,%r12)
movq %r15, %rdi
callq 0x2220
movl %eax, 0x8955(%rip)      # 0xb2b8
incl 0x897f(%rip)            # 0xb2e8
cmpl $0xa, %eax
je 0x2a21
movl %eax, %r14d
leal -0x30(%r14), %eax
cmpl $0xa, %eax
jb 0x2937
movl $0xc, %r15d
cmpl $0x2e, %r14d
jne 0x2905
movslq 0x894f(%rip), %rax      # 0xb2e4
cmpq $0x64, %rax
jge 0x28a2
leal 0x1(%rax), %ecx
movl %ecx, 0x893c(%rip)      # 0xb2e4
movb $0x2e, (%rax,%r12)
movq 0x862c(%rip), %rdi      # 0xafe0
callq 0x2220
movl %eax, 0x88f9(%rip)      # 0xb2b8
incl 0x8923(%rip)            # 0xb2e8
cmpl $0xa, %eax
jne 0x2a62
incl 0x88e8(%rip)            # 0xb2bc
movl $0x0, 0x890a(%rip)      # 0xb2e8
jmp 0x2a57
callq 0x2cd3
leal -0x21(%r14), %eax
cmpl $0x1d, %eax
ja 0x2a3c
leaq 0x560f(%rip), %rcx      # 0x8004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x20, %r15d
cmpl $0x3d, 0x88ad(%rip)     # 0xb2b8
jne 0x2905
callq 0x2cd3
movl $0x1e, %r15d
jmp 0x2905
incl 0x8895(%rip)            # 0xb2bc
movl $0x0, 0x88b7(%rip)      # 0xb2e8
movl $0xc, %r15d
jmp 0x2905
cmpl $0x5b, %r14d
je 0x2baf
cmpl $0x5d, %r14d
jne 0x2a57
movl $0x15, %r15d
jmp 0x2905
movl $0x20, %r15d
jmp 0x2905
leal -0x30(%rax), %ecx
movl $0x20, %r15d
cmpl $0x9, %ecx
ja 0x2905
movq 0x8565(%rip), %r14      # 0xafe0
movslq 0x8862(%rip), %rcx      # 0xb2e4
cmpq $0x64, %rcx
jge 0x28a2
leal 0x1(%rcx), %edx
movl %edx, 0x884f(%rip)      # 0xb2e4
movb %al, (%rcx,%r12)
movq %r14, %rdi
callq 0x2220
movl %eax, 0x8811(%rip)      # 0xb2b8
incl 0x883b(%rip)            # 0xb2e8
cmpl $0xa, %eax
je 0x2bba
movl %eax, %ecx
addl $-0x30, %ecx
movl $0xd, %r15d
cmpl $0xa, %ecx
jb 0x2a7b
jmp 0x2905
movl $0x1a, %r15d
cmpl $0x3d, 0x87e0(%rip)     # 0xb2b8
jne 0x2905
callq 0x2cd3
movl $0x1c, %r15d
jmp 0x2905
movl $0x11, %r15d
jmp 0x2905
movl $0xe, %r15d
jmp 0x2905
movl $0x12, %r15d
jmp 0x2905
movl $0x20, %r15d
cmpl $0x3d, 0x879c(%rip)     # 0xb2b8
jne 0x2905
callq 0x2cd3
movl $0x1d, %r15d
jmp 0x2905
movl $0x16, %r15d
jmp 0x2905
movl $0x13, %r15d
jmp 0x2905
movl $0x10, %r15d
jmp 0x2905
movl $0xf, %r15d
jmp 0x2905
movl $0x18, %r15d
cmpl $0x3d, 0x874d(%rip)     # 0xb2b8
jne 0x2905
callq 0x2cd3
movl $0x1f, %r15d
jmp 0x2905
movl $0x19, %r15d
cmpl $0x3d, 0x872a(%rip)     # 0xb2b8
jne 0x2905
callq 0x2cd3
movl $0x1b, %r15d
jmp 0x2905
movl $0x17, %r15d
jmp 0x2905
movl $0x14, %r15d
jmp 0x2905
incl 0x86fc(%rip)            # 0xb2bc
movl $0x0, 0x871e(%rip)      # 0xb2e8
movl $0xd, %r15d
jmp 0x2905