// File: matteorr[P]EarleyParser/EarleyParser.cpp
// Function: EarleyParser::scanner(State*, int)
void EarleyParser::scanner( State* stateToScan, int positionInputString )
{
	Production* productionInStateToScan = stateToScan->getProductionPointer();

	if( positionInputString >= this->inputVector.size() ){
		cout << "[DEBUG]: scanner fail, input string end reached" << endl;
		return;
	}

	if( this->inputVector.at( positionInputString ) == productionInStateToScan->getProductionContent().at( stateToScan->getProductionProgress() ) )
	{
		/*
		 * the symbol to be scanned in the production is the same of the input string
		 * a new state must be created in the next position of the chart
		 *
		 * must check for equal states in the chart and avoid insertion in case
		 */
		cout << "[DEBUG]: scan [" << this->inputVector.at( positionInputString ) << "][" << stateToScan->getProductionProgress() << "][" << stateToScan->getInputStringProgress() << "]" << endl;

		State* stateToInsert = new State( stateToScan->getNonTerminal(), stateToScan->getProductionPointer(), stateToScan, stateToScan->getInputStringProgress(), stateToScan->getProductionProgress() + 1 );
		cout << "[DEBUG]: scanner is inserting state in chart position " << positionInputString + 1 << endl;
		this->earleyParserChart[ positionInputString + 1 ].push_back( stateToInsert );
	}else{
		/*
		 * do nothing
		 * symbol to be scanned does not match with symbol in the input string
		 */

		cout << "[DEBUG]: scan mismatch - input[" << this->inputVector.at( positionInputString ) << "] production[" << productionInStateToScan->getProductionContent().at( stateToScan->getProductionProgress() ) << "]" << endl;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x116d0
movq -0xa0(%rbp), %rdi
movq %rax, -0x20(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x98(%rbp)
addq $0x98, %rdi
callq 0x6c90
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jb 0x5382
movq 0x16c76(%rip), %rdi     # 0x1bfd8
leaq 0xe087(%rip), %rsi      # 0x133f0
callq 0x21c0
movq %rax, %rdi
movq 0x16c50(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x572e
movq -0xa0(%rbp), %rdi
addq $0x98, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7090
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x114b0
movq -0x10(%rbp), %rdi
callq 0x11730
movl %eax, -0xa4(%rbp)
jmp 0x53be
movl -0xa4(%rbp), %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x7090
movq %rax, -0xb8(%rbp)
jmp 0x53d9
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rdi
callq 0x7a80
movb %al, -0xb9(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6f60
movb -0xb9(%rbp), %al
testb $0x1, %al
jne 0x540a
jmp 0x5624
movq 0x16bc7(%rip), %rdi     # 0x1bfd8
leaq 0xe008(%rip), %rsi      # 0x13420
callq 0x21c0
movq -0xa0(%rbp), %rdi
movq %rax, -0xe8(%rbp)
addq $0x98, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7090
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0xdd1c(%rip), %rsi      # 0x13170
movq %rsi, -0xd8(%rbp)
callq 0x21c0
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11730
movq -0xe0(%rbp), %rdi
movl %eax, %esi
callq 0x2330
movq -0xd8(%rbp), %rsi
movq %rax, %rdi
callq 0x21c0
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x11680
movq -0xd0(%rbp), %rdi
movl %eax, %esi
callq 0x2330
movq %rax, %rdi
leaq 0xdb74(%rip), %rsi      # 0x13029
callq 0x21c0
movq %rax, %rdi
movq 0x16b04(%rip), %rsi     # 0x1bfc8
callq 0x21f0
movl $0x58, %edi
callq 0x21d0
movq %rax, -0xc8(%rbp)
movb $0x1, -0x71(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x116a0
jmp 0x54ed
movq -0x10(%rbp), %rdi
callq 0x116d0
movq %rax, -0xf0(%rbp)
jmp 0x54ff
movq -0x10(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x11680
movl %eax, -0xf4(%rbp)
jmp 0x5517
movq -0x10(%rbp), %rdi
callq 0x11730
movl %eax, -0x104(%rbp)
jmp 0x5528
movl -0xf4(%rbp), %r8d
movq -0x100(%rbp), %rcx
movq -0xf0(%rbp), %rdx
movq -0xc8(%rbp), %rdi
movl -0x104(%rbp), %r9d
incl %r9d
leaq -0x70(%rbp), %rsi
callq 0x11520
jmp 0x5559
movb $0x0, -0x71(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2140
movq -0xc8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x16a60(%rip), %rdi     # 0x1bfd8
leaq 0xdeb1(%rip), %rsi      # 0x13430
callq 0x21c0
movq %rax, %rdi
movl -0x14(%rbp), %esi
addl $0x1, %esi
callq 0x2330
movq %rax, %rdi
movq 0x16a2c(%rip), %rsi     # 0x1bfc8
callq 0x21f0
movq -0xa0(%rbp), %rdi
addq $0x80, %rdi
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x7990
movq %rax, %rdi
leaq -0x50(%rbp), %rsi
callq 0x79b0
jmp 0x572e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6f60
jmp 0x5737
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x560b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2140
testb $0x1, -0x71(%rbp)
jne 0x5613
jmp 0x561f
movq -0xc8(%rbp), %rdi
callq 0x21b0
jmp 0x5737
movq 0x169ad(%rip), %rdi     # 0x1bfd8
leaq 0xde35(%rip), %rsi      # 0x13467
callq 0x21c0
movq -0xa0(%rbp), %rdi
movq %rax, -0x118(%rbp)
addq $0x98, %rdi
movslq -0x14(%rbp), %rsi
callq 0x7090
movq -0x118(%rbp), %rdi
movq %rax, %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0xde19(%rip), %rsi      # 0x13487
callq 0x21c0
movq %rax, -0x110(%rbp)
movq -0x20(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x114b0
movq -0x10(%rbp), %rdi
callq 0x11730
movl %eax, -0x108(%rbp)
jmp 0x569b
movl -0x108(%rbp), %eax
movslq %eax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x7090
movq %rax, -0x120(%rbp)
jmp 0x56b9
movq -0x120(%rbp), %rsi
movq -0x110(%rbp), %rdi
callq 0x21a0
movq %rax, -0x128(%rbp)
jmp 0x56d5
movq -0x128(%rbp), %rdi
leaq 0xd946(%rip), %rsi      # 0x13029
callq 0x21c0
movq %rax, -0x130(%rbp)
jmp 0x56f1
movq -0x130(%rbp), %rdi
movq 0x168c9(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x5706
leaq -0x90(%rbp), %rdi
callq 0x6f60
jmp 0x572e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x6f60
jmp 0x5737
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x2340