// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ef2
movq %rbx, -0xe8(%rbp)
leaq 0x10(%rbx), %rax
movq %rax, -0x68(%rbp)
leaq -0x348(%rbp), %r14
movq 0xb782(%rip), %r13      # 0xdfd8
leaq 0x77c3(%rip), %r15      # 0xa020
movq -0x348(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x328(%rbp,%rax)
jne 0x2f60
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 0x285d
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 0x7705(%rip), %rsi      # 0xa02a
leaq 0x7700(%rip), %rdx      # 0xa02c
callq 0x676a
leaq -0xc8(%rbp), %rsi
leaq -0x40(%rbp), %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x327a
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x295f
callq 0x21a0
movq -0x40(%rbp), %rdi
cmpq %rdi, -0x38(%rbp)
je 0x30ec
leaq 0x76b9(%rip), %rsi      # 0xa02d
callq 0x20a0
testl %eax, %eax
je 0x2ee4
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %rdx
subq %rbx, %rdx
je 0x2a4a
movl $0x1, %r12d
xorl %r14d, %r14d
movl $0x9, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movl $0xd, %edx
movq %r13, %rdi
leaq 0x7675(%rip), %rsi      # 0xa02f
callq 0x2220
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0x30ca
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 0x763f(%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 0x299b
jmp 0x2a4e
sarq $0x5, %rdx
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x1, %rdx
jbe 0x30fe
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %r14
movq %r14, %rdi
leaq 0x7b1b(%rip), %rsi      # 0xa5a1
leaq 0x7b15(%rip), %rdx      # 0xa5a2
callq 0x676a
addq $0x20, %rbx
movq %rbx, %rsi
leaq -0x60(%rbp), %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x327a
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x2ac0
callq 0x21a0
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
je 0x2b81
movl $0x1, %r12d
xorl %r14d, %r14d
movl $0x9, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movl $0x13, %edx
movq %r13, %rdi
leaq 0x7549(%rip), %rsi      # 0xa03f
callq 0x2220
movq -0x60(%rbp), %rax
movq -0x58(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0x30db
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 0x7503(%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 0x2ad7
movq -0x40(%rbp), %rsi
cmpq %rsi, -0x38(%rbp)
je 0x3111
movq -0x68(%rbp), %rdi
callq 0x6804
movq %rax, %r14
testq %rax, %rax
je 0x2cd6
movl $0x10, %edx
movq %r13, %rdi
leaq 0x74a0(%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 0x748a(%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 0x3123
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 0x6172
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 0x9254
movq %r14, %rbx
addq $0x28, %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x69fc
leaq 0x7372(%rip), %r15      # 0xa020
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2040
incq 0x38(%r14)
movq %r12, %rdi
callq 0x92a4
leaq -0x118(%rbp), %rdi
callq 0x60da
jmp 0x2ed4
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 0x3136
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0x6200
movq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x6a56
testb $0x1, %dl
je 0x2e55
movq %rax, %r14
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq $0x2, %rdx
jbe 0x3148
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 0x6172
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 0x9254
leaq 0x28(%r14), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x69fc
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2040
incq 0x38(%r14)
movq %r12, %rdi
callq 0x92a4
leaq -0x100(%rbp), %rdi
callq 0x60da
movl $0x1b, %edx
movq %r13, %rdi
leaq 0x72b7(%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 0x72a6(%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 0x2e8c
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 0x2e68
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x2ea4
callq 0x21a0
movq -0xe0(%rbp), %rbx
leaq -0xe0(%rbp), %r12
cmpq %r12, %rbx
je 0x2ed4
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 0x2eb7
leaq -0x60(%rbp), %rdi
callq 0x60da
leaq -0x348(%rbp), %r14
leaq -0x40(%rbp), %rdi
callq 0x60da
jmp 0x285d
movq 0xb0df(%rip), %rdi      # 0xdfd8
leaq 0x7235(%rip), %rsi      # 0xa135
movl $0x24, %edx
callq 0x2220
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0xb0c0(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %rbx
leaq 0x7116(%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 0x3094
leaq -0x348(%rbp), %rdi
callq 0x2060
movq -0xe8(%rbp), %r15
cmpb $0x1, 0x8(%r15)
jne 0x3094
addq $0x20, %r15
movq 0xb04f(%rip), %r14      # 0xdfd8
leaq 0x70ad(%rip), %r12      # 0xa03d
movq (%r15), %r13
testq %r13, %r13
je 0x3094
movl $0x22, %edx
movq %r14, %rdi
leaq 0x7121(%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 0x303f
xorps %xmm0, %xmm0
movss %xmm0, -0x68(%rbp)
leaq 0x10(%r13), %rdi
callq 0x930c
movss -0x68(%rbp), %xmm1
addss %xmm0, %xmm1
movaps %xmm1, %xmm0
movq (%r13), %r13
cmpq %rbx, %r13
jne 0x300d
ucomiss 0x6fcd(%rip), %xmm0     # 0xa004
jne 0x303f
jnp 0x2f90
movq 0xaf92(%rip), %rdi      # 0xdfd8
leaq 0x70a2(%rip), %rsi      # 0xa0ef
movl $0x19, %edx
callq 0x2220
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdx
movq 0xaf72(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %rbx
leaq 0x7094(%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 0x30b8
callq 0x21a0
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7544(%rip), %rdi      # 0xa615
movq %r14, %rsi
xorl %eax, %eax
callq 0x2280
leaq 0x7533(%rip), %rdi      # 0xa615
movq %r14, %rsi
xorl %eax, %eax
callq 0x2280
leaq 0x7522(%rip), %rdi      # 0xa615
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2280
leaq 0x7510(%rip), %rdi      # 0xa615
movl $0x1, %esi
xorl %eax, %eax
callq 0x2280
leaq 0x74fd(%rip), %rdi      # 0xa615
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2280
leaq 0x74eb(%rip), %rdi      # 0xa615
movl $0x2, %esi
xorl %eax, %eax
callq 0x2280
leaq 0x74d8(%rip), %rdi      # 0xa615
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2280
leaq 0x74c6(%rip), %rdi      # 0xa615
movl $0x2, %esi
xorl %eax, %eax
callq 0x2280
movq %rax, %rbx
jmp 0x325a
jmp 0x3204
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x92a4
jmp 0x317c
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x60da
jmp 0x3207
jmp 0x3204
jmp 0x3190
jmp 0x3204
movq %rax, %rbx
jmp 0x3213
jmp 0x3234
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x92a4
jmp 0x31ae
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x60da
jmp 0x3237
jmp 0x3234
jmp 0x322f
jmp 0x3234
jmp 0x3234
jmp 0x3234
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x3237
callq 0x21a0
jmp 0x3237
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x3245
callq 0x21a0
jmp 0x3245
jmp 0x3242
jmp 0x3242
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x6258
leaq -0xe0(%rbp), %rdi
callq 0x6692
jmp 0x3237
jmp 0x322f
jmp 0x322f
jmp 0x3234
jmp 0x322f
jmp 0x322f
jmp 0x3234
jmp 0x3242
movq %rax, %rbx
jmp 0x324e
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x60da
jmp 0x3245
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x60da
leaq -0x348(%rbp), %rdi
callq 0x2080
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x3272
callq 0x21a0
movq %rbx, %rdi
callq 0x22f0