// File: /workspace/github_cpp_makefile_star2_O3/kram[P]kram/./src/parser/parser.cpp
// Function: Parser::lookahead(Instruction*, ON)
Instruction* Parser::lookahead(Instruction* prev, ON on) {
	this->advance();

	lexer::Token* next = this->get_token();

	// PushClass
	// IO::Println("123")
	//   ^^
	// IO.Println("123")
	//   ^
	if (on != ON::MATH_NEG) {
		if (next->type == lexer::Type::OPERATOR && (next->sub == lexer::Type::OPERATOR_DOT || next->sub == lexer::Type::OPERATOR_DOUBLE_COLON)) {
			return this->push_class(prev);
		}
	}

	// Call
	// IO::Println("123")
	//            ^
	if (next->type == lexer::Type::OPERATOR && next->sub == lexer::Type::OPERATOR_PAREN_L) {
		return this->call(prev, on);
	}

	// Assignment
	// num := 100
	//     ^^
	if (next->type == lexer::Type::OPERATOR && next->sub == lexer::Type::OPERATOR_COLON_EQ) {
		return this->assign(prev);
	}

	// Set
	// num = 100
	//     ^
	//
	// Parameter with default value
	// fn (a = 100)
	//
	if (next->type == lexer::Type::OPERATOR && next->sub == lexer::Type::OPERATOR_EQ) {
		if (on == ON::FUNCTION_PARAMETER_LIST) {
			return this->function_parameter_with_default_value(prev);
		} else {
			return this->set(prev);
		}
	}

	// Create new variable of type
	// num : Number
	//     ^
	if (next->type == lexer::Type::OPERATOR && next->sub == lexer::Type::OPERATOR_COLON) {
		return this->assign_with_type(prev);
	}

	if (on != ON::MATH_CONTINUATION && on != ON::MATH_NEG) {
		if (next->type == lexer::Type::OPERATOR) {
			if (this->startOperators.find(next->sub) != this->startOperators.end()) {
				return this->math(prev);
			}
		}
	}

	// List extraction
	// li[123]
	//   ^
	if (next->type == lexer::Type::OPERATOR && next->sub == lexer::Type::OPERATOR_SQUARE_PAREN_LEFT) {
		return this->oper_list_extraction(prev);
	}

	this->reverse();

	return prev;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
cmpb $0x1, 0x20(%rdi)
jne 0xe23d
movl 0x18(%r14), %eax
incl %eax
movl %eax, 0x18(%r14)
jmp 0xe246
movb $0x1, 0x20(%r14)
movl 0x18(%r14), %eax
cltq
movq (%r14), %rcx
movq (%rcx,%rax,8), %r15
movl (%r15), %eax
cmpl $0x2, %edx
jne 0xe266
cmpl $0x11, %eax
jne 0xe353
movl 0x4(%r15), %eax
jmp 0xe28d
cmpl $0x11, %eax
jne 0xe353
movl 0x4(%r15), %eax
cmpl $0x25, %eax
je 0xe27d
cmpl $0x14, %eax
jne 0xe28d
movq %r14, %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xe36e
cmpl $0x25, %eax
jg 0xe2b5
cmpl $0x13, %eax
je 0xe316
cmpl $0x16, %eax
jne 0xe2cf
movq %r14, %rdi
cmpl $0x4, %edx
jne 0xe360
movq %rbx, %rsi
callq 0xe86c
jmp 0xe357
cmpl $0x2a, %eax
je 0xe326
cmpl $0x26, %eax
jne 0xe2cf
movq %r14, %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xe4a4
addl $-0x3, %edx
cmpl $-0x3, %edx
ja 0xe336
leaq 0x4(%r15), %rcx
leaq 0x60(%r14), %rdi
movslq %eax, %r8
movq %r8, %rax
xorl %edx, %edx
divq 0x68(%r14)
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
callq 0x1140e
testq %rax, %rax
je 0xe336
cmpq $0x0, (%rax)
je 0xe336
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
popq %rbx
popq %r14
popq %r15
jmp 0xf7ee
movq %r14, %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xeb42
movq %r14, %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xe790
cmpl $0x11, (%r15)
jne 0xe353
cmpl $0x2e, 0x4(%r15)
jne 0xe353
movq %r14, %rdi
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xed8a
decl 0x18(%r14)
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq
movq %rbx, %rsi
popq %rbx
popq %r14
popq %r15
jmp 0xea66
nop