// File: /workspace/github_cpp_makefile_star2_O3/matteorr[P]EarleyParser/EarleyParser.cpp
// Function: EarleyParser::initialize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
void EarleyParser::initialize( string filePath, bool probablityParser )
{
	this->probabilityParser = probablityParser;

	string line;
	ifstream inputFile;

	inputFile.open( filePath.c_str(), fstream::in );

	if( inputFile.is_open() )
	{
		while( inputFile.good() )
		{
			/*
			 * reads a line (production) from the context free input grammar
			 */
			getline( inputFile, line );

			//skips empty line
			if( line.size() == 0 ) continue;

			cout << "[DEBUG]: " << line << endl;

			/*
			 * extracts tokens of the production
			 * separated by "->"
			 * first token is terminal symbol
			 * second token is production rule
			 * third tolken is production probability
			 */
			vector< string > tokenVector;
			this->splitToVector( line, &tokenVector, "->", false );

			//skips comment line
			if( tokenVector.at(0) == "#" ) continue;

			for( unsigned int i = 0; i < tokenVector.size(); i++ ){
				cout << "[DEBUG]: " << "line token: [" << tokenVector.at(i) << "]" << endl;
			}

			/*
			 * extracts all symbols in the production
			 * separated by " "
			 */
			vector< string > productionTokenVector;
			this->splitToVector( tokenVector.at(1), &productionTokenVector, " ", false );
			for( unsigned int i = 0; i < productionTokenVector.size(); i++ ){
				cout << "[DEBUG]: " << "production token: [" << productionTokenVector.at(i) << "]" << endl;
			}

			/*
			 * looks in the hash table of productions
			 * if the non terminal symbol was allready inserted
			 */
			EarleyParser::productionHashTable::iterator got = this->earleyProductions.find( tokenVector.at(0) );
			if( got != this->earleyProductions.end() )
			{
				/*
				 * element found in hash table (key tokenVector->at(0) contained)
				 * add a new Production at the end of the list
				 */

				cout << "[DEBUG]: found [" << got->first << "] adding Production to existing list" << endl << endl;

				got->second.push_back( Production( atof( tokenVector.at(2).c_str() ), productionTokenVector.size(), productionTokenVector ) );

			}else{
				/*
				 * element not found in hash table (key tokenVector->at(0) not contained)
				 * create a new list and save it in hash map
				 * adds new Production to the list
				 */

				list<Production> productionList;

				pair< string, list<Production> > productions( tokenVector.at(0), productionList );

				std::pair<EarleyParser::productionHashTable::iterator, bool> insertionResult;
				insertionResult = this->earleyProductions.insert( productions );
				if( insertionResult.second == true ){
					/*
					 * element inserted with success
					 */
					insertionResult.first->second.push_back( Production( atof( tokenVector.at(2).c_str() ), productionTokenVector.size(), productionTokenVector ) );

					cout << "[DEBUG]: created new list [" << productions.first << "] and inserted Production with success" << endl << endl;
				}
			}

		}
		inputFile.close();

		/*
		 * check probabilities coherence if specified by the input boolean
		 */
		if( this->probabilityParser == true ){

			for( productionHashTable::iterator i = this->earleyProductions.begin(); i != this->earleyProductions.end(); i++ ){

				float productionProbability = 0;

				cout << "[DEBUG]: checking probability of [" << i->first << "]" << endl;

				for( list<Production>::iterator j = i->second.begin(); j != i->second.end(); j++ ){

					productionProbability += j->getProductionProbability();
				}
				if( productionProbability != 1 ){
					cout << "[DEBUG]: probability of [" << i->first << "] does not sum up to 1! - BAD INPUT GRAMMAR" << endl;
					exit(1);
				}
			}
		}

	}else{
		cout << "Error: not able to open input file [" << filePath << "]" << endl;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x328, %rsp            # imm = 0x328
movq %rsi, %r14
movq %rdi, %rbx
movb %dl, 0x8(%rdi)
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x348(%rbp), %rdi
callq 0x2210
movq (%r14), %rsi
leaq -0x348(%rbp), %rdi
movl $0x8, %edx
callq 0x2130
leaq -0x2d0(%rbp), %rdi
callq 0x2070
testb %al, %al
je 0x2f06
movq %rbx, -0xe8(%rbp)
leaq 0x10(%rbx), %rax
movq %rax, -0x68(%rbp)
leaq -0x348(%rbp), %r14
movq 0xb76e(%rip), %r13      # 0xdfd8
leaq 0x77af(%rip), %r15      # 0xa020
movq -0x348(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x328(%rbp,%rax)
jne 0x2f74
leaq (%rax,%rbp), %rdi
addq $-0x348, %rdi           # imm = 0xFCB8
movl $0xa, %esi
callq 0x21c0
movsbl %al, %edx
movq %r14, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2310
cmpq $0x0, -0xc0(%rbp)
je 0x2871
movl $0x9, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movq %r13, %rdi
callq 0x2220
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
leaq 0x76f1(%rip), %rsi      # 0xa02a
leaq 0x76ec(%rip), %rdx      # 0xa02c
callq 0x675a
leaq -0xc8(%rbp), %rsi
leaq -0x40(%rbp), %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x328e
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x2973
callq 0x21a0
movq -0x40(%rbp), %rdi
cmpq %rdi, -0x38(%rbp)
je 0x3100
leaq 0x76a5(%rip), %rsi      # 0xa02d
callq 0x20a0
testl %eax, %eax
je 0x2ef8
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %rdx
subq %rbx, %rdx
je 0x2a5e
movl $0x1, %r12d
xorl %r14d, %r14d
movl $0x9, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movl $0xd, %edx
movq %r13, %rdi
leaq 0x7661(%rip), %rsi      # 0xa02f
callq 0x2220
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0x30de
shlq $0x5, %r14
movq (%rax,%r14), %rsi
movq 0x8(%rax,%r14), %rdx
movq %r13, %rdi
callq 0x2220
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x762b(%rip), %rsi      # 0xa03d
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movl %r12d, %r14d
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %rdx
subq %rbx, %rdx
sarq $0x5, %rdx
incl %r12d
cmpq %r14, %rdx
ja 0x29af
jmp 0x2a62
sarq $0x5, %rdx
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x1, %rdx
jbe 0x3112
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
leaq 0x7b07(%rip), %rsi      # 0xa5a1
leaq 0x7b01(%rip), %rdx      # 0xa5a2
callq 0x675a
addq $0x20, %rbx
movq %rbx, %rsi
leaq -0x60(%rbp), %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x328e
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x2ad4
callq 0x21a0
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
je 0x2b95
movl $0x1, %r12d
xorl %r14d, %r14d
movl $0x9, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movl $0x13, %edx
movq %r13, %rdi
leaq 0x7535(%rip), %rsi      # 0xa03f
callq 0x2220
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0x30ef
shlq $0x5, %r14
movq (%rax,%r14), %rsi
movq 0x8(%rax,%r14), %rdx
movq %r13, %rdi
callq 0x2220
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x74ef(%rip), %rsi      # 0xa03d
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq -0x58(%rbp), %rax
subq -0x60(%rbp), %rax
movl %r12d, %r14d
sarq $0x5, %rax
incl %r12d
cmpq %r14, %rax
ja 0x2aeb
movq -0x40(%rbp), %rsi
cmpq %rsi, -0x38(%rbp)
je 0x3125
movq -0x68(%rbp), %rdi
callq 0x67f8
movq %rax, %r14
testq %rax, %rax
je 0x2cea
movl $0x10, %edx
movq %r13, %rdi
leaq 0x748c(%rip), %rsi      # 0xa053
callq 0x2220
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %r13, %rdi
callq 0x2220
movq %rax, %rbx
movl $0x24, %edx
movq %rax, %rdi
leaq 0x7476(%rip), %rsi      # 0xa064
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq $0x2, %rdx
jbe 0x3137
movq 0x40(%rax), %rdi
callq 0x2250
movsd %xmm0, -0x70(%rbp)
movq -0x60(%rbp), %r12
movq -0x58(%rbp), %rbx
leaq -0x118(%rbp), %r15
movq %r15, %rdi
leaq -0x60(%rbp), %rsi
callq 0x615e
subq %r12, %rbx
shrq $0x5, %rbx
xorps %xmm0, %xmm0
cvtsd2ss -0x70(%rbp), %xmm0
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
movl %ebx, %esi
movq %r15, %rdx
callq 0x9244
movq %r14, %rbx
addq $0x28, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x69f0
leaq 0x735e(%rip), %r15      # 0xa020
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2040
incq 0x38(%r14)
movq %r12, %rdi
callq 0x9294
leaq -0x118(%rbp), %rdi
callq 0x60b2
jmp 0x2ee8
leaq -0xe0(%rbp), %rdx
movq %rdx, -0xd8(%rbp)
movq %rdx, -0xe0(%rbp)
movq $0x0, -0xd0(%rbp)
movq -0x40(%rbp), %rsi
cmpq %rsi, -0x38(%rbp)
je 0x314a
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x61ec
movq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x6a4a
testb $0x1, %dl
je 0x2e69
movq %rax, %r14
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq $0x2, %rdx
jbe 0x315c
movq 0x40(%rax), %rdi
callq 0x2250
movsd %xmm0, -0x70(%rbp)
movq -0x60(%rbp), %r12
movq -0x58(%rbp), %rbx
leaq -0x100(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x615e
subq %r12, %rbx
shrq $0x5, %rbx
xorps %xmm0, %xmm0
cvtsd2ss -0x70(%rbp), %xmm0
leaq -0x140(%rbp), %r12
movq %r12, %rdi
movl %ebx, %esi
leaq -0x100(%rbp), %rdx
callq 0x9244
leaq 0x28(%r14), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x69f0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2040
incq 0x38(%r14)
movq %r12, %rdi
callq 0x9294
leaq -0x100(%rbp), %rdi
callq 0x60b2
movl $0x1b, %edx
movq %r13, %rdi
leaq 0x72a3(%rip), %rsi      # 0xa089
callq 0x2220
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq %r13, %rdi
callq 0x2220
movq %rax, %rbx
movl $0x26, %edx
movq %rax, %rdi
leaq 0x7292(%rip), %rsi      # 0xa0a5
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq -0x88(%rbp), %rbx
leaq -0x88(%rbp), %rax
cmpq %rax, %rbx
je 0x2ea0
movq (%rbx), %r14
movq 0x10(%rbx), %rax
leaq 0x10(%rbx), %rdi
callq *(%rax)
movq %rbx, %rdi
callq 0x21a0
movq %r14, %rbx
leaq -0x88(%rbp), %rax
cmpq %rax, %r14
jne 0x2e7c
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x2eb8
callq 0x21a0
movq -0xe0(%rbp), %rbx
leaq -0xe0(%rbp), %r12
cmpq %r12, %rbx
je 0x2ee8
movq (%rbx), %r14
movq 0x10(%rbx), %rax
leaq 0x10(%rbx), %rdi
callq *(%rax)
movq %rbx, %rdi
callq 0x21a0
movq %r14, %rbx
cmpq %r12, %r14
jne 0x2ecb
leaq -0x60(%rbp), %rdi
callq 0x60b2
leaq -0x348(%rbp), %r14
leaq -0x40(%rbp), %rdi
callq 0x60b2
jmp 0x2871
movq 0xb0cb(%rip), %rdi      # 0xdfd8
leaq 0x7221(%rip), %rsi      # 0xa135
movl $0x24, %edx
callq 0x2220
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0xb0ac(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %rbx
leaq 0x7102(%rip), %rsi      # 0xa03d
movl $0x1, %edx
movq %rax, %rdi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
jmp 0x30a8
leaq -0x348(%rbp), %rdi
callq 0x2060
movq -0xe8(%rbp), %r15
cmpb $0x1, 0x8(%r15)
jne 0x30a8
addq $0x20, %r15
movq 0xb03b(%rip), %r14      # 0xdfd8
leaq 0x7099(%rip), %r12      # 0xa03d
movq (%r15), %r13
testq %r13, %r13
je 0x30a8
movl $0x22, %edx
movq %r14, %rdi
leaq 0x710d(%rip), %rsi      # 0xa0cc
callq 0x2220
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rdx
movq %r14, %rdi
callq 0x2220
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2220
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
leaq 0x28(%r13), %rbx
movq %r13, %r15
movq 0x28(%r13), %r13
cmpq %rbx, %r13
je 0x3053
xorps %xmm0, %xmm0
movss %xmm0, -0x68(%rbp)
leaq 0x10(%r13), %rdi
callq 0x92fc
movss -0x68(%rbp), %xmm1
addss %xmm0, %xmm1
movaps %xmm1, %xmm0
movq (%r13), %r13
cmpq %rbx, %r13
jne 0x3021
ucomiss 0x6fb9(%rip), %xmm0     # 0xa004
jne 0x3053
jnp 0x2fa4
movq 0xaf7e(%rip), %rdi      # 0xdfd8
leaq 0x708e(%rip), %rsi      # 0xa0ef
movl $0x19, %edx
callq 0x2220
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdx
movq 0xaf5e(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %rbx
leaq 0x7080(%rip), %rsi      # 0xa109
movl $0x2b, %edx
movq %rax, %rdi
callq 0x2220
movq %rbx, %rdi
callq 0x20f0
movl $0x1, %edi
callq 0x2230
leaq -0x348(%rbp), %rdi
callq 0x2080
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x30cc
callq 0x21a0
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7530(%rip), %rdi      # 0xa615
movq %r14, %rsi
xorl %eax, %eax
callq 0x2280
leaq 0x751f(%rip), %rdi      # 0xa615
movq %r14, %rsi
xorl %eax, %eax
callq 0x2280
leaq 0x750e(%rip), %rdi      # 0xa615
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2280
leaq 0x74fc(%rip), %rdi      # 0xa615
movl $0x1, %esi
xorl %eax, %eax
callq 0x2280
leaq 0x74e9(%rip), %rdi      # 0xa615
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2280
leaq 0x74d7(%rip), %rdi      # 0xa615
movl $0x2, %esi
xorl %eax, %eax
callq 0x2280
leaq 0x74c4(%rip), %rdi      # 0xa615
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2280
leaq 0x74b2(%rip), %rdi      # 0xa615
movl $0x2, %esi
xorl %eax, %eax
callq 0x2280
movq %rax, %rbx
jmp 0x326e
jmp 0x3218
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x9294
jmp 0x3190
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x60b2
jmp 0x321b
jmp 0x3218
jmp 0x31a4
jmp 0x3218
movq %rax, %rbx
jmp 0x3227
jmp 0x3248
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x9294
jmp 0x31c2
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x60b2
jmp 0x324b
jmp 0x3248
jmp 0x3243
jmp 0x3248
jmp 0x3248
jmp 0x3248
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x324b
callq 0x21a0
jmp 0x324b
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x3259
callq 0x21a0
jmp 0x3259
jmp 0x3256
jmp 0x3256
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x6244
leaq -0xe0(%rbp), %rdi
callq 0x667e
jmp 0x324b
jmp 0x3243
jmp 0x3243
jmp 0x3248
jmp 0x3243
jmp 0x3243
jmp 0x3248
jmp 0x3256
movq %rax, %rbx
jmp 0x3262
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60b2
jmp 0x3259
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x60b2
leaq -0x348(%rbp), %rdi
callq 0x2080
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x3286
callq 0x21a0
movq %rbx, %rdi
callq 0x22f0