// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x7828
movslq %r15d, %r13
movq 0xa0(%rbx), %rcx
subq 0x98(%rbx), %rcx
sarq $0x5, %rcx
cmpq %r13, %rcx
jbe 0x3e6d
movl %r15d, -0x2c(%rbp)
movq %rbx, -0x50(%rbp)
leaq 0x98(%rbx), %r15
movq %r15, %rdi
movq %rax, %rbx
movq %r13, %rsi
callq 0x4c0a
movq %rax, %r12
leaq -0x48(%rbp), %rdi
movq %rbx, -0x58(%rbp)
movq %rbx, %rsi
callq 0x76d8
movq %r14, %rdi
callq 0x785a
movslq %eax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x4c0a
movq %r12, %rdi
movq %rax, %rsi
callq 0x4e25
movl %eax, %r12d
leaq -0x48(%rbp), %rdi
callq 0x4ba2
movq 0x92a2(%rip), %rdi      # 0xcfd8
testb %r12b, %r12b
je 0x3e96
leaq 0x46ee(%rip), %rsi      # 0x8434
callq 0x21c0
movq %rax, %r12
movq %r15, %rdi
movq %r13, %rsi
callq 0x4c0a
movq %r12, %rdi
movq %rax, %rsi
callq 0x2190
leaq 0x4419(%rip), %r15      # 0x8184
movq %rax, %rdi
movq %r15, %rsi
callq 0x21c0
movq %rax, %r12
movq %r14, %rdi
callq 0x785a
movq %r12, %rdi
movl %eax, %esi
callq 0x22b0
movq %rax, %rdi
movq %r15, %rsi
callq 0x21c0
movq %rax, %r15
movq %r14, %rdi
callq 0x7802
movq %r15, %rdi
movl %eax, %esi
callq 0x22b0
leaq 0x428b(%rip), %rsi      # 0x803d
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x2100
pushq $0x58
popq %rdi
callq 0x21d0
movq %rax, %r12
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x780c
movq %r14, %rdi
callq 0x7828
movq %rax, %r15
movq %r14, %rdi
callq 0x7802
movl %eax, %r13d
movq %r14, %rdi
callq 0x785a
incl %eax
leaq -0x78(%rbp), %rsi
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
movl %r13d, %r8d
movl %eax, %r9d
callq 0x770c
leaq -0x78(%rbp), %rdi
callq 0x20f0
leaq -0x48(%rbp), %r14
movq %r12, (%r14)
movq 0x91b0(%rip), %rdi      # 0xcfd8
leaq 0x4615(%rip), %rsi      # 0x8444
callq 0x21c0
movl -0x2c(%rbp), %r15d
incl %r15d
movq %rax, %rdi
movl %r15d, %esi
callq 0x22b0
movq %rax, %rdi
callq 0x2100
movslq %r15d, %rax
imulq $0x18, %rax, %rdi
movq -0x50(%rbp), %rax
addq 0x80(%rax), %rdi
movq %r14, %rsi
callq 0x4de0
jmp 0x3f19
movq 0x9164(%rip), %rdi      # 0xcfd8
leaq 0x4589(%rip), %rsi      # 0x8404
callq 0x21c0
movq %rax, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2100
leaq 0x45de(%rip), %rsi      # 0x847b
callq 0x21c0
movq %rax, %rbx
movq %r15, %rdi
movq %r13, %rsi
callq 0x4c0a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2190
leaq 0x45d9(%rip), %rsi      # 0x849b
movq %rax, %rdi
callq 0x21c0
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x76d8
movq %r14, %rdi
callq 0x785a
movslq %eax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x4c0a
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2190
leaq 0x413d(%rip), %rsi      # 0x803d
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x2100
leaq -0x48(%rbp), %rdi
callq 0x4ba2
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x3f39
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x21a0
jmp 0x3f51
jmp 0x3f45
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x4ba2
movq %rbx, %rdi
callq 0x22c0
nop