// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, %rbx
movl $0x0, 0x8bb1(%rip)      # 0xb2e4
movl 0x8b7e(%rip), %r14d     # 0xb2b8
movl %r14d, %edi
callq 0x2050
testl %eax, %eax
je 0x2789
movq 0x8893(%rip), %r15      # 0xafe0
movq %r15, %rdi
callq 0x2220
movl %eax, 0x8b5d(%rip)      # 0xb2b8
incl 0x8b87(%rip)            # 0xb2e8
cmpl $0xa, %eax
jne 0x2776
incl 0x8b50(%rip)            # 0xb2bc
movl $0x0, 0x8b72(%rip)      # 0xb2e8
movl 0x8b3b(%rip), %r14d     # 0xb2b8
movl %r14d, %edi
callq 0x2050
testl %eax, %eax
jne 0x274d
movl 0x8b2d(%rip), %eax      # 0xb2bc
movl %eax, 0x8b57(%rip)      # 0xb2ec
movl 0x8b4d(%rip), %eax      # 0xb2e8
movl %eax, 0x8b4f(%rip)      # 0xb2f0
cmpl $-0x1, %r14d
je 0x28e3
movl %r14d, %edi
callq 0x22a0
testl %eax, %eax
je 0x28ee
movl 0x8b23(%rip), %eax      # 0xb2e4
cmpl $0x63, %eax
jg 0x2842
leaq 0x8b33(%rip), %r14      # 0xb300
movq 0x880c(%rip), %r15      # 0xafe0
movb 0x8ade(%rip), %cl       # 0xb2b8
leal 0x1(%rax), %edx
movl %edx, 0x8b01(%rip)      # 0xb2e4
cltq
movb %cl, (%rax,%r14)
movq %r15, %rdi
callq 0x2220
movl %eax, %r12d
movl %eax, 0x8abe(%rip)      # 0xb2b8
incl 0x8ae8(%rip)            # 0xb2e8
cmpl $0xa, %eax
jne 0x2815
incl 0x8ab1(%rip)            # 0xb2bc
movl $0x0, 0x8ad3(%rip)      # 0xb2e8
leal -0x30(%r12), %eax
cmpl $0xa, %eax
jb 0x2837
movl %r12d, %edi
callq 0x22a0
testl %eax, %eax
sete %al
cmpl $0x5f, %r12d
setne %cl
testb %cl, %al
jne 0x2861
movl 0x8aa7(%rip), %eax      # 0xb2e4
cmpl $0x64, %eax
jl 0x27d4
leaq 0x591f(%rip), %rdi      # 0x8168
leaq 0x5930(%rip), %rsi      # 0x8180
leaq 0x5976(%rip), %rcx      # 0x81cd
movl $0x48, %edx
callq 0x2130
movslq 0x8a7c(%rip), %rax      # 0xb2e4
movb $0x0, (%rax,%r14)
movq 0x8954(%rip), %rsi      # 0xb1c8
addq $0x3, %rsi
movq %r14, %rdi
callq 0x2250
testl %eax, %eax
je 0x2a2b
xorl %r15d, %r15d
leaq 0x891e(%rip), %r13      # 0xb1b0
leaq 0x8a67(%rip), %r12      # 0xb300
movl $0x2, %r14d
cmpq $0x8, %r15
je 0x2a31
movq 0x20(%r13,%r15,8), %rsi
addq $0x3, %rsi
movq %r12, %rdi
callq 0x2250
incq %r15
testl %eax, %eax
jne 0x289f
leaq 0x2(%r15), %r12
addl $0x3, %r15d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x2b97
cmpq $0xa, %r12
ja 0x2a31
jmp 0x2a3c
movl $0x1, %r14d
jmp 0x2a31
leal -0x30(%r14), %eax
cmpl $0x9, %eax
ja 0x2a4e
leaq 0x89fe(%rip), %r12      # 0xb300
movq 0x86d7(%rip), %r14      # 0xafe0
movslq 0x89d4(%rip), %rax      # 0xb2e4
cmpq $0x64, %rax
jge 0x2842
movb 0x8998(%rip), %cl       # 0xb2b8
leal 0x1(%rax), %edx
movl %edx, 0x89bb(%rip)      # 0xb2e4
movb %cl, (%rax,%r12)
movq %r14, %rdi
callq 0x2220
movl %eax, 0x897d(%rip)      # 0xb2b8
incl 0x89a7(%rip)            # 0xb2e8
cmpl $0xa, %eax
jne 0x2956
incl 0x8970(%rip)            # 0xb2bc
movl $0x0, 0x8992(%rip)      # 0xb2e8
leal -0x30(%rax), %ecx
cmpl $0xa, %ecx
jb 0x2909
movl $0xc, %r14d
cmpl $0x2e, %eax
jne 0x2a31
movslq 0x8970(%rip), %rax      # 0xb2e4
cmpq $0x64, %rax
jge 0x2842
leal 0x1(%rax), %ecx
movl %ecx, 0x895d(%rip)      # 0xb2e4
movb $0x2e, (%rax,%r12)
movq 0x864d(%rip), %rdi      # 0xafe0
callq 0x2220
movl %eax, 0x891a(%rip)      # 0xb2b8
incl 0x8944(%rip)            # 0xb2e8
cmpl $0xa, %eax
jne 0x29b9
incl 0x890d(%rip)            # 0xb2bc
movl $0x0, 0x892f(%rip)      # 0xb2e8
addl $-0x30, %eax
movl $0x20, %r14d
cmpl $0x9, %eax
ja 0x2a31
movq 0x8612(%rip), %r15      # 0xafe0
movl $0xd, %r14d
movslq 0x8909(%rip), %rax      # 0xb2e4
cmpq $0x64, %rax
jge 0x2842
movb 0x88cd(%rip), %cl       # 0xb2b8
leal 0x1(%rax), %edx
movl %edx, 0x88f0(%rip)      # 0xb2e4
movb %cl, (%rax,%r12)
movq %r15, %rdi
callq 0x2220
movl %eax, 0x88b2(%rip)      # 0xb2b8
incl 0x88dc(%rip)            # 0xb2e8
cmpl $0xa, %eax
jne 0x2a21
incl 0x88a5(%rip)            # 0xb2bc
movl $0x0, 0x88c7(%rip)      # 0xb2e8
addl $-0x30, %eax
cmpl $0xa, %eax
jb 0x29d4
jmp 0x2a31
movl $0x3, %r14d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2b97
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2c98
leal -0x21(%r14), %eax
cmpl $0x1d, %eax
ja 0x2a88
leaq 0x55a1(%rip), %rcx      # 0x8004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x20, %r14d
cmpl $0x3d, 0x883f(%rip)     # 0xb2b8
jne 0x2a31
callq 0x2c98
movl $0x1e, %r14d
jmp 0x2a31
cmpl $0x5b, %r14d
je 0x2b8c
cmpl $0x5d, %r14d
jne 0x2aa0
movl $0x15, %r14d
jmp 0x2a31
movl $0x20, %r14d
jmp 0x2a31
movl $0x1a, %r14d
cmpl $0x3d, 0x8803(%rip)     # 0xb2b8
jne 0x2a31
callq 0x2c98
movl $0x1c, %r14d
jmp 0x2a31
movl $0x11, %r14d
jmp 0x2a31
movl $0xe, %r14d
jmp 0x2a31
movl $0x12, %r14d
jmp 0x2a31
movl $0x20, %r14d
cmpl $0x3d, 0x87bf(%rip)     # 0xb2b8
jne 0x2a31
callq 0x2c98
movl $0x1d, %r14d
jmp 0x2a31
movl $0x16, %r14d
jmp 0x2a31
movl $0x13, %r14d
jmp 0x2a31
movl $0x10, %r14d
jmp 0x2a31
movl $0xf, %r14d
jmp 0x2a31
movl $0x18, %r14d
cmpl $0x3d, 0x8770(%rip)     # 0xb2b8
jne 0x2a31
callq 0x2c98
movl $0x1f, %r14d
jmp 0x2a31
movl $0x19, %r14d
cmpl $0x3d, 0x874d(%rip)     # 0xb2b8
jne 0x2a31
callq 0x2c98
movl $0x1b, %r14d
jmp 0x2a31
movl $0x17, %r14d
jmp 0x2a31
movl $0x14, %r14d
jmp 0x2a31