// File: /workspace/github_cpp_makefile_star2_O1/matteorr[P]EarleyParser/EarleyParser.cpp
// Function: EarleyParser::createDictionary(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void EarleyParser::createDictionary( string filePath )
{
	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 a word
			 * second token is the associated non terminal
			 */
			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;
			}

			/*
			 * looks in the hash table of dictionary
			 * if the word was allready inserted
			 */
			EarleyParser::dictionaryHashTable::iterator got = this->earleyDictionary.find( tokenVector.at(0) );
			if( got != this->earleyDictionary.end() )
			{
				/*
				 * element found in hash table (key tokenVector->at(0) contained)
				 * error!
				 */

				cout << "[DEBUG]: BAD INPUT DICTIONARY!" << endl << endl;
				exit(1);
			}else{
				/*
				 * element not found in hash table (key tokenVector->at(0) not contained)
				 * save string in the hash map
				 */

				pair< string, string > element( tokenVector.at(0), tokenVector.at(1) );

				std::pair<EarleyParser::dictionaryHashTable::iterator, bool> insertionResult;
				insertionResult = this->earleyDictionary.insert( element );
				if( insertionResult.second == true ){
					/*
					 * element inserted with success
					 */
					cout << "[DEBUG]: [" << element.first << "][" << element.second << "] inserted with success" << endl << endl;
				}
			}

		}
		inputFile.close();

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

			cout << "[DEBUG]: element [" << i->first << "][" << i->second << "] in dictionary" << endl;
		}

	}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 $0x298, %rsp            # imm = 0x298
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x2b8(%rbp), %rdi
callq 0x2210
movq (%r14), %rsi
leaq -0x2b8(%rbp), %rdi
movl $0x8, %edx
callq 0x2130
leaq -0x240(%rbp), %rdi
callq 0x2070
testb %al, %al
je 0x375c
leaq -0xa0(%rbp), %r15
leaq 0x48(%rbx), %rax
movq %rax, -0x50(%rbp)
movq 0xabcd(%rip), %r14      # 0xdfd8
leaq 0x6c0e(%rip), %r12      # 0xa020
movq $0x0, -0x48(%rbp)
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x298(%rbp,%rax)
jne 0x37f5
leaq (%rax,%rbp), %rdi
addq $-0x2b8, %rdi           # imm = 0xFD48
movl $0xa, %esi
callq 0x21c0
movsbl %al, %edx
leaq -0x2b8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x2310
cmpq $0x0, -0x68(%rbp)
je 0x341a
movl $0x9, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2220
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
movq %r14, %rdi
callq 0x2220
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movq %r15, -0xb0(%rbp)
leaq -0xb0(%rbp), %r13
movq %r13, %rdi
leaq 0x6b57(%rip), %rsi      # 0xa02a
leaq 0x6b52(%rip), %rdx      # 0xa02c
callq 0x676a
leaq -0x70(%rbp), %rsi
leaq -0x40(%rbp), %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x327a
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3503
callq 0x21a0
movq -0x40(%rbp), %rdi
cmpq %rdi, -0x38(%rbp)
je 0x38b9
leaq 0x6b15(%rip), %rsi      # 0xa02d
callq 0x20a0
testl %eax, %eax
je 0x374e
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
movq %rax, %rdx
subq %rsi, %rdx
je 0x35f5
movl $0x1, %r15d
xorl %r13d, %r13d
movl $0x9, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2220
movl $0xd, %edx
movq %r14, %rdi
leaq 0x6ace(%rip), %rsi      # 0xa02f
callq 0x2220
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
subq %rax, %rdx
sarq $0x5, %rdx
cmpq %r13, %rdx
jbe 0x38a8
shlq $0x5, %r13
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
movq %r14, %rdi
callq 0x2220
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x6a98(%rip), %rsi      # 0xa03d
callq 0x2220
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movl %r15d, %r13d
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
movq %rax, %rdx
subq %rsi, %rdx
sarq $0x5, %rdx
incl %r15d
cmpq %r13, %rdx
ja 0x3542
jmp 0x35f9
sarq $0x5, %rdx
cmpq %rsi, %rax
je 0x391c
movq -0x50(%rbp), %rdi
callq 0x6dec
leaq -0xa0(%rbp), %r15
testq %rax, %rax
jne 0x38e6
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
movq %rax, %rdx
subq %rsi, %rdx
sarq $0x5, %rdx
cmpq %rsi, %rax
je 0x38d4
cmpq $0x2, %rdx
jb 0x38cb
leaq 0x20(%rsi), %rdx
leaq -0xb0(%rbp), %r13
movq %r13, %rdi
callq 0x6284
movq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0x6ef8
testb $0x1, %dl
je 0x3728
movl $0xa, %edx
movq %r14, %rdi
leaq 0x6b02(%rip), %rsi      # 0xa179
callq 0x2220
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %r14, %rdi
callq 0x2220
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
leaq 0x6ae0(%rip), %rsi      # 0xa184
callq 0x2220
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq %r13, %rdi
callq 0x2220
movq %rax, %r13
movl $0x17, %edx
movq %rax, %rdi
leaq 0x6ab6(%rip), %rsi      # 0xa187
callq 0x2220
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x373d
callq 0x21a0
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x374e
callq 0x21a0
leaq -0x40(%rbp), %rdi
callq 0x60da
jmp 0x341a
movq 0xa875(%rip), %rdi      # 0xdfd8
leaq 0x69cb(%rip), %rsi      # 0xa135
movl $0x24, %edx
callq 0x2220
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0xa856(%rip), %rdi      # 0xdfd8
callq 0x2220
movq %rax, %rbx
leaq 0x68ac(%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
leaq -0x2b8(%rbp), %rdi
callq 0x2080
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x37e3
callq 0x21a0
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x2b8(%rbp), %rdi
callq 0x2060
addq $0x58, %rbx
movq 0xa7cc(%rip), %r14      # 0xdfd8
leaq 0x6971(%rip), %r12      # 0xa184
leaq 0x6998(%rip), %r13      # 0xa1b2
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x37c5
movl $0x12, %edx
movq %r14, %rdi
leaq 0x696e(%rip), %rsi      # 0xa19f
callq 0x2220
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq %r14, %rdi
callq 0x2220
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2220
movq 0x28(%rbx), %rsi
movq 0x30(%rbx), %rdx
movq %r15, %rdi
callq 0x2220
movq %rax, %r15
movl $0xf, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2220
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2150
jmp 0x381a
leaq 0x6d66(%rip), %rdi      # 0xa615
movq %r13, %rsi
xorl %eax, %eax
callq 0x2280
leaq 0x6d55(%rip), %rdi      # 0xa615
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2280
movl $0x1, %eax
movq %rax, -0x48(%rbp)
leaq 0x6d3a(%rip), %rdi      # 0xa615
movq -0x48(%rbp), %rsi
xorl %eax, %eax
callq 0x2280
movq 0xa6eb(%rip), %rdi      # 0xdfd8
leaq 0x6866(%rip), %rsi      # 0xa15a
movl $0x1e, %edx
callq 0x2220
movq 0xa6d3(%rip), %rdi      # 0xdfd8
callq 0x20f0
movq %rax, %rdi
callq 0x20f0
movl $0x1, %edi
callq 0x2230
leaq 0x6cf2(%rip), %rdi      # 0xa615
xorl %esi, %esi
xorl %eax, %eax
callq 0x2280
movq %rax, %rbx
jmp 0x398b
jmp 0x396e
jmp 0x3973
jmp 0x3959
jmp 0x3973
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3976
callq 0x21a0
jmp 0x3976
jmp 0x3973
jmp 0x3973
jmp 0x3973
jmp 0x3973
jmp 0x396e
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x62ec
jmp 0x3976
jmp 0x396e
jmp 0x3973
movq %rax, %rbx
jmp 0x397f
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x60da
leaq -0x2b8(%rbp), %rdi
callq 0x2080
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x399d
callq 0x21a0
movq %rbx, %rdi
callq 0x22f0
nop