// File: kram[P]kram/./src/lexer/lexer.cpp
// Function: lexer::Lexer::next()
Token* Lexer::next() {
	this->current = this->char_at_pos(this->index);

	// End of row
	if (this->current == '\0') {
		return new Token(Type::T_EOL);
	}

	// Ignore Whitespace
	if (iswspace(this->current)) {
		return new Token(Type::IGNORE);
	}

	// Comments
	if (this->current == '/' && this->char_at_pos(this->index+1) == '/') {
		return this->comment();
	}

	// Names
	// Begins with a char a-Z
	if ((this->current >= 'a' && this->current <= 'z') || (this->current >= 'A' && this->current <= 'Z')) {
		return this->name();
	}

	// Numbers
	if (this->current >= '0' && this->current <= '9') {
		return this->number();
	}

	// Strings
	if (this->current == '\"') {
		return this->string();
	}

	// Operators
	std::string str(1, this->current);
	if (Token::Trans(str) != Type::IGNORE) {
		return this->oper();
	}

	std::cout << "Ignoring: " << this->current << "(" << str << ")\n";

	return new Token(Type::IGNORE);
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
movq %rdi, 0x50(%rsp)
movq 0x58(%rdi), %rsi
callq 0x81e0
movb %al, %cl
movq 0x50(%rsp), %rax
movb %cl, 0x60(%rax)
movsbl 0x60(%rax), %eax
cmpl $0x0, %eax
jne 0x7e6e
movl $0x28, %edi
callq 0x32e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x48(%rsp)
movl $0x1, %esi
callq 0xaf20
jmp 0x7e39
movq 0x48(%rsp), %rax
movq %rax, 0xc0(%rsp)
jmp 0x81b9
movq 0x48(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
callq 0x32b0
jmp 0x81c9
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %edi
callq 0x3260
cmpl $0x0, %eax
je 0x7ed7
movl $0x28, %edi
callq 0x32e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x40(%rsp)
movl $0x2, %esi
callq 0xaf20
jmp 0x7ea2
movq 0x40(%rsp), %rax
movq %rax, 0xc0(%rsp)
jmp 0x81b9
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
callq 0x32b0
jmp 0x81c9
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x2f, %eax
jne 0x7f16
movq 0x50(%rsp), %rdi
movq 0x58(%rdi), %rsi
addq $0x1, %rsi
callq 0x81e0
movsbl %al, %eax
cmpl $0x2f, %eax
jne 0x7f16
movq 0x50(%rsp), %rdi
callq 0x8240
movq %rax, 0xc0(%rsp)
jmp 0x81b9
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x61, %eax
jl 0x7f32
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x7a, %eax
jle 0x7f4e
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x41, %eax
jl 0x7f65
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x5a, %eax
jg 0x7f65
movq 0x50(%rsp), %rdi
callq 0x82f0
movq %rax, 0xc0(%rsp)
jmp 0x81b9
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x30, %eax
jl 0x7f98
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x39, %eax
jg 0x7f98
movq 0x50(%rsp), %rdi
callq 0x8750
movq %rax, 0xc0(%rsp)
jmp 0x81b9
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
cmpl $0x22, %eax
jne 0x7fbd
movq 0x50(%rsp), %rdi
callq 0x8940
movq %rax, 0xc0(%rsp)
jmp 0x81b9
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %eax
movl %eax, 0x34(%rsp)
leaq 0x87(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x34a0
movl 0x34(%rsp), %edx
movq 0x38(%rsp), %rcx
leaq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0x3210
jmp 0x7ff9
leaq 0x87(%rsp), %rdi
callq 0x3310
leaq 0x60(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x3140
jmp 0x801a
leaq 0x60(%rsp), %rdi
callq 0xb030
movl %eax, 0x30(%rsp)
jmp 0x802a
leaq 0x60(%rsp), %rdi
callq 0x31f0
movl 0x30(%rsp), %eax
cmpl $0x2, %eax
je 0x80ce
movq 0x50(%rsp), %rdi
callq 0x8bd0
movq %rax, 0x28(%rsp)
jmp 0x8052
movq 0x28(%rsp), %rax
movq %rax, 0xc0(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0x819b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x87(%rsp), %rdi
callq 0x3310
jmp 0x81c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x81aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x31f0
jmp 0x81aa
movq 0x31f03(%rip), %rdi     # 0x39fd8
leaq 0x23162(%rip), %rsi     # 0x2b23e
callq 0x32d0
movq %rax, 0x20(%rsp)
jmp 0x80e8
movq 0x20(%rsp), %rdi
movq 0x50(%rsp), %rax
movsbl 0x60(%rax), %esi
callq 0x3320
movq %rax, 0x18(%rsp)
jmp 0x8102
movq 0x18(%rsp), %rdi
leaq 0x2313b(%rip), %rsi     # 0x2b249
callq 0x32d0
movq %rax, 0x10(%rsp)
jmp 0x811a
movq 0x10(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x32a0
movq %rax, 0x8(%rsp)
jmp 0x8133
movq 0x8(%rsp), %rdi
leaq 0x234ef(%rip), %rsi     # 0x2b62e
callq 0x32d0
jmp 0x8146
movl $0x28, %edi
callq 0x32e0
movq %rax, (%rsp)
jmp 0x8156
movq (%rsp), %rdi
movl $0x2, %esi
callq 0xaf20
jmp 0x8166
movq (%rsp), %rax
movq %rax, 0xc0(%rsp)
movl $0x1, 0x5c(%rsp)
jmp 0x819b
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
callq 0x32b0
jmp 0x81aa
leaq 0x88(%rsp), %rdi
callq 0x31f0
jmp 0x81b9
leaq 0x88(%rsp), %rdi
callq 0x31f0
jmp 0x81c9
movq 0xc0(%rsp), %rax
addq $0xc8, %rsp
retq
movq 0xb0(%rsp), %rdi
callq 0x3490
nopw %cs:(%rax,%rax)