// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
andl $0x0, 0x8bcf(%rip)      # 0xb2d4
movq %rdi, %rbx
movl 0x8b99(%rip), %r14d     # 0xb2a8
movq 0x88ca(%rip), %r15      # 0xafe0
movl %r14d, %edi
callq 0x2040
testl %eax, %eax
je 0x274d
movq %r15, %rdi
callq 0x21f0
movl %eax, %r14d
movl %eax, 0x8b75(%rip)      # 0xb2a8
incl 0x8b9f(%rip)            # 0xb2d8
cmpl $0xa, %eax
jne 0x2716
incl 0x8b68(%rip)            # 0xb2ac
andl $0x0, 0x8b8d(%rip)      # 0xb2d8
jmp 0x2716
movl 0x8b59(%rip), %eax      # 0xb2ac
movl %eax, 0x8b83(%rip)      # 0xb2dc
movl 0x8b79(%rip), %eax      # 0xb2d8
movl %eax, 0x8b7b(%rip)      # 0xb2e0
cmpl $-0x1, %r14d
je 0x27e6
movl %r14d, %edi
callq 0x2280
testl %eax, %eax
je 0x27ec
callq 0x2a2c
movl 0x8b25(%rip), %r14d     # 0xb2a8
leal -0x30(%r14), %eax
cmpl $0xa, %eax
jb 0x2777
movl %r14d, %edi
callq 0x2280
testl %eax, %eax
setne %al
cmpl $0x5f, %r14d
sete %cl
orb %al, %cl
jne 0x2777
movslq 0x8b29(%rip), %rax      # 0xb2d4
leaq 0x8b3e(%rip), %r15      # 0xb2f0
movb $0x0, (%rax,%r15)
pushq $0x3
popq %r12
pushq $0x2
popq %r14
leaq 0x89da(%rip), %r13      # 0xb1a0
cmpq $0xc, %r12
je 0x2844
movq (%r13,%r12,8), %rsi
addq $0x3, %rsi
movq %r15, %rdi
callq 0x2230
testl %eax, %eax
je 0x2841
incq %r12
jmp 0x27c6
pushq $0x1
popq %r14
jmp 0x2844
leal -0x30(%r14), %eax
cmpl $0x9, %eax
ja 0x2861
callq 0x2a2c
movl 0x8aa8(%rip), %eax      # 0xb2a8
leal -0x30(%rax), %ecx
cmpl $0xa, %ecx
jb 0x27f5
cmpl $0x2e, %eax
jne 0x2894
callq 0x2a2c
movl 0x8a8c(%rip), %eax      # 0xb2a8
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x28f5
pushq $0xd
popq %r14
callq 0x2a2c
movl 0x8a71(%rip), %eax      # 0xb2a8
addl $-0x30, %eax
cmpl $0xa, %eax
jb 0x282c
jmp 0x2844
movl %r12d, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2965
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2a2c
leal -0x21(%r14), %eax
cmpl $0x1d, %eax
ja 0x289b
leaq 0x478e(%rip), %rcx      # 0x7004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x3d, 0x8a22(%rip)     # 0xb2a8
jne 0x28f5
callq 0x2a2c
pushq $0x1e
jmp 0x27e8
pushq $0xc
jmp 0x27e8
cmpl $0x5b, %r14d
je 0x2949
cmpl $0x5d, %r14d
jne 0x28f5
pushq $0x15
jmp 0x27e8
cmpl $0x3d, 0x89ef(%rip)     # 0xb2a8
jne 0x2950
callq 0x2a2c
pushq $0x1c
jmp 0x27e8
pushq $0x11
jmp 0x27e8
pushq $0xe
jmp 0x27e8
pushq $0x12
jmp 0x27e8
cmpl $0x3d, 0x89c1(%rip)     # 0xb2a8
jne 0x28f5
callq 0x2a2c
pushq $0x1d
jmp 0x27e8
pushq $0x20
jmp 0x27e8
pushq $0x16
jmp 0x27e8
pushq $0x13
jmp 0x27e8
pushq $0x10
jmp 0x27e8
pushq $0xf
jmp 0x27e8
cmpl $0x3d, 0x8989(%rip)     # 0xb2a8
jne 0x2957
callq 0x2a2c
pushq $0x1f
jmp 0x27e8
cmpl $0x3d, 0x8974(%rip)     # 0xb2a8
jne 0x295e
callq 0x2a2c
pushq $0x1b
jmp 0x27e8
pushq $0x17
jmp 0x27e8
pushq $0x14
jmp 0x27e8
pushq $0x1a
jmp 0x27e8
pushq $0x18
jmp 0x27e8
pushq $0x19
jmp 0x27e8