// File: matteorr[P]EarleyParser/EarleyParser.cpp
// Function: EarleyParser::completer(State*, int)
void EarleyParser::completer( State* stateCompleted, int positionInputString )
{
	cout << "[DEBUG]: complete [" << stateCompleted->getNonTerminal() << "][" << stateCompleted->getProductionProgress() << "][" << stateCompleted->getInputStringProgress() << "]" << endl;
	//string nonTerminal = stateCompleted->getNonTerminal();
	//int inputStringProgress = stateCompleted->getInputStringProgress();
	//cout << "test input string progress: " << inputStringProgress << endl << endl;
	//vector<State>::iterator itTest = this->earleyParserChart[ stateCompleted->getInputStringProgress() ].begin();
	//cout << "test iterator: " << itTest->getNonTerminal() << endl << endl;

	if( stateCompleted->getInputStringProgress() >= this->earleyParserChart.size() ){
		cout << "[ERROR]: COMPLETER OVERFLOW" << endl;
		exit(1);
	}
	for( vector<State*>::iterator it = this->earleyParserChart[ stateCompleted->getInputStringProgress() ].begin();
			it != this->earleyParserChart[ stateCompleted->getInputStringProgress() ].end(); it++ )
	{
		if( (*it)->getProductionPointer()->getProductionContent().size() <= (*it)->getProductionProgress() ) continue;
		if( stateCompleted->getNonTerminal() == (*it)->getProductionPointer()->getProductionContent().at( (*it)->getProductionProgress() ) )
		{
			//cout << "before constructor in complete" << endl;
			State* stateToInsert = new State( (*it)->getNonTerminal(), (*it)->getProductionPointer(), stateCompleted, (*it)->getInputStringProgress(), (*it)->getProductionProgress() + 1 );
			this->earleyParserChart[ positionInputString ].push_back( stateToInsert );
			//cout << "after push back in complete" << endl;
		}
		//cout << "destructor called in complete" << endl;
	}

	//cout << "[DEBUG]: completed [" << stateCompleted.getNonTerminal() << "]" << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq 0x16870(%rip), %rdi     # 0x1bfd8
leaq 0xdd26(%rip), %rsi      # 0x13495
callq 0x21c0
movq %rax, -0xf8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x38(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x116a0
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x21a0
movq %rax, -0xe8(%rbp)
jmp 0x57ab
movq -0xe8(%rbp), %rdi
leaq 0xd9b7(%rip), %rsi      # 0x13170
callq 0x21c0
movq %rax, -0x108(%rbp)
jmp 0x57c7
movq -0x10(%rbp), %rdi
callq 0x11730
movl %eax, -0x10c(%rbp)
jmp 0x57d8
movl -0x10c(%rbp), %esi
movq -0x108(%rbp), %rdi
callq 0x2330
movq %rax, -0x118(%rbp)
jmp 0x57f3
movq -0x118(%rbp), %rdi
leaq 0xd96f(%rip), %rsi      # 0x13170
callq 0x21c0
movq %rax, -0x120(%rbp)
jmp 0x580f
movq -0x10(%rbp), %rdi
callq 0x11680
movl %eax, -0x124(%rbp)
jmp 0x5820
movl -0x124(%rbp), %esi
movq -0x120(%rbp), %rdi
callq 0x2330
movq %rax, -0x130(%rbp)
jmp 0x583b
movq -0x130(%rbp), %rdi
leaq 0xd7e0(%rip), %rsi      # 0x13029
callq 0x21c0
movq %rax, -0x138(%rbp)
jmp 0x5857
movq -0x138(%rbp), %rdi
movq 0x16763(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x586c
leaq -0x38(%rbp), %rdi
callq 0x2140
movq -0x10(%rbp), %rdi
callq 0x11680
movq -0x100(%rbp), %rdi
cltq
movq %rax, -0x140(%rbp)
addq $0x80, %rdi
callq 0x7b50
movq %rax, %rcx
movq -0x140(%rbp), %rax
cmpq %rcx, %rax
jb 0x58ef
movq 0x16728(%rip), %rdi     # 0x1bfd8
leaq 0xdbf2(%rip), %rsi      # 0x134a9
callq 0x21c0
movq %rax, %rdi
movq 0x16702(%rip), %rsi     # 0x1bfc8
callq 0x21f0
movl $0x1, %edi
callq 0x2220
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2140
jmp 0x5c6a
movq -0x100(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11680
movq -0x148(%rbp), %rdi
movslq %eax, %rsi
callq 0x7990
movq %rax, %rdi
callq 0x6d00
movq %rax, -0x50(%rbp)
movq -0x100(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11680
movq -0x150(%rbp), %rdi
movslq %eax, %rsi
callq 0x7990
movq %rax, %rdi
callq 0x6d70
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x6d30
testb $0x1, %al
jne 0x5975
jmp 0x5c61
leaq -0x50(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x6da0
movq (%rax), %rdi
callq 0x116d0
movq %rax, %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x114b0
movq -0x170(%rbp), %rdi
callq 0x6c90
movq -0x168(%rbp), %rdi
movq %rax, -0x160(%rbp)
callq 0x6da0
movq (%rax), %rdi
callq 0x11730
movl %eax, -0x154(%rbp)
jmp 0x59cf
movl -0x154(%rbp), %eax
cltq
movq %rax, -0x178(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x6f60
movq -0x178(%rbp), %rcx
movq -0x160(%rbp), %rax
cmpq %rcx, %rax
ja 0x5a19
jmp 0x5c4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x6f60
jmp 0x5c6a
movq -0x10(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x116a0
leaq -0x50(%rbp), %rdi
callq 0x6da0
movq (%rax), %rdi
callq 0x116d0
movq %rax, -0x180(%rbp)
jmp 0x5a43
movq -0x180(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x114b0
jmp 0x5a58
leaq -0x50(%rbp), %rdi
callq 0x6da0
movq (%rax), %rdi
callq 0x11730
movl %eax, -0x184(%rbp)
jmp 0x5a71
movl -0x184(%rbp), %eax
movslq %eax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x7090
movq %rax, -0x190(%rbp)
jmp 0x5a8f
movq -0x190(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x7a80
movb %al, -0x191(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x6f60
leaq -0x90(%rbp), %rdi
callq 0x2140
movb -0x191(%rbp), %al
testb $0x1, %al
jne 0x5acf
jmp 0x5c48
movl $0x58, %edi
callq 0x21d0
movq %rax, -0x1a0(%rbp)
movb $0x1, -0xd1(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x6da0
movq (%rax), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x116a0
jmp 0x5b01
leaq -0x50(%rbp), %rdi
callq 0x6da0
movq (%rax), %rdi
callq 0x116d0
movq %rax, -0x1a8(%rbp)
jmp 0x5b1b
movq -0x10(%rbp), %rax
movq %rax, -0x1b8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x6da0
movq (%rax), %rdi
callq 0x11680
movl %eax, -0x1ac(%rbp)
jmp 0x5b3f
leaq -0x50(%rbp), %rdi
callq 0x6da0
movq (%rax), %rdi
callq 0x11730
movl %eax, -0x1bc(%rbp)
jmp 0x5b58
movl -0x1ac(%rbp), %r8d
movq -0x1b8(%rbp), %rcx
movq -0x1a8(%rbp), %rdx
movq -0x1a0(%rbp), %rdi
movl -0x1bc(%rbp), %r9d
incl %r9d
leaq -0xd0(%rbp), %rsi
callq 0x11520
jmp 0x5b8c
movb $0x0, -0xd1(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x2140
movq -0x1a0(%rbp), %rax
movq -0x100(%rbp), %rdi
movq %rax, -0xb0(%rbp)
addq $0x80, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7990
movq %rax, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x79b0
jmp 0x5c48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5bfb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x6f60
leaq -0x90(%rbp), %rdi
callq 0x2140
jmp 0x5c6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5c2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x2140
testb $0x1, -0xd1(%rbp)
jne 0x5c3a
jmp 0x5c46
movq -0x1a0(%rbp), %rdi
callq 0x21b0
jmp 0x5c6a
jmp 0x5c4a
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x6dc0
movq %rax, -0xe0(%rbp)
jmp 0x5927
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x2340
nopw %cs:(%rax,%rax)