// File: /workspace/github_cpp_makefile_star2_O2/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)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x2b8(%rbp), %rdi
callq 0x21f0
movq (%r14), %rsi
leaq -0x2b8(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2140
leaq -0x240(%rbp), %rdi
callq 0x2070
testb %al, %al
je 0x3084
leaq 0x48(%rbx), %rax
movq %rax, -0x38(%rbp)
movq 0xa143(%rip), %r15      # 0xcfd8
leaq -0xb0(%rbp), %r14
leaq -0x50(%rbp), %r13
movq -0x2b8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x298(%rbp,%rax)
jne 0x30e0
leaq -0x2b8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x2040
cmpq $0x0, -0x68(%rbp)
je 0x2ea0
movq %r15, %rdi
leaq 0x5146(%rip), %rsi      # 0x8020
callq 0x21c0
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
callq 0x2190
movq %rax, %rdi
callq 0x2100
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
movq %r14, %rdi
leaq 0x5121(%rip), %rsi      # 0x802a
leaq -0x29(%rbp), %rdx
callq 0x20c0
leaq -0x70(%rbp), %rsi
movq %r13, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x2d42
movq %r14, %rdi
callq 0x20f0
movq %r13, %rdi
xorl %esi, %esi
callq 0x4c0a
movq %rax, %rdi
leaq 0x50ed(%rip), %rsi      # 0x802d
callq 0x4bf9
testb %al, %al
jne 0x3077
xorl %r14d, %r14d
movl %r14d, %r14d
movq -0x48(%rbp), %rax
subq -0x50(%rbp), %rax
sarq $0x5, %rax
cmpq %r14, %rax
jbe 0x2fb7
movq %r15, %rdi
leaq 0x50b2(%rip), %rsi      # 0x8020
callq 0x21c0
movq %rax, %rdi
leaq 0x50b2(%rip), %rsi      # 0x802f
callq 0x21c0
movq %rax, %r12
movq %r13, %rdi
movq %r14, %rsi
callq 0x4c0a
movq %r12, %rdi
movq %rax, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x5098(%rip), %rsi      # 0x803d
callq 0x21c0
movq %rax, %rdi
callq 0x2100
incl %r14d
jmp 0x2f50
movq %r13, %rdi
xorl %esi, %esi
callq 0x4c0a
movq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x5978
testq %rax, %rax
jne 0x3157
movq %r13, %rdi
xorl %esi, %esi
callq 0x4c0a
movq %rax, %r14
movq %r13, %rdi
pushq $0x1
popq %rsi
callq 0x4c0a
leaq -0xb0(%rbp), %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x4ce6
movq -0x38(%rbp), %rdi
leaq -0xb0(%rbp), %r14
movq %r14, %rsi
callq 0x5a56
testb $0x1, %dl
je 0x306f
movq %r15, %rdi
leaq 0x5157(%rip), %rsi      # 0x8179
callq 0x21c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x5148(%rip), %rsi      # 0x8184
callq 0x21c0
movq %rax, %rdi
leaq -0x90(%rbp), %rsi
callq 0x2190
movq %rax, %rdi
leaq 0x512d(%rip), %rsi      # 0x8187
callq 0x21c0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
movq %r14, %rdi
callq 0x4d1c
movq %r13, %rdi
callq 0x4ba2
jmp 0x2ea0
movq 0x9f4d(%rip), %rdi      # 0xcfd8
leaq 0x50a3(%rip), %rsi      # 0x8135
callq 0x21c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0x4f94(%rip), %rsi      # 0x803d
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x2100
leaq -0x2b8(%rbp), %rdi
callq 0x2080
leaq -0x70(%rbp), %rdi
callq 0x20f0
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 0x9ee1(%rip), %r14      # 0xcfd8
leaq 0x50a1(%rip), %r15      # 0x819f
leaq 0x507f(%rip), %r12      # 0x8184
leaq 0x50a6(%rip), %r13      # 0x81b2
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x30b9
movq %r14, %rdi
movq %r15, %rsi
callq 0x21c0
leaq 0x8(%rbx), %rsi
movq %rax, %rdi
callq 0x2190
movq %rax, %rdi
movq %r12, %rsi
callq 0x21c0
leaq 0x28(%rbx), %rsi
movq %rax, %rdi
callq 0x2190
movq %rax, %rdi
movq %r13, %rsi
callq 0x21c0
movq %rax, %rdi
callq 0x2100
jmp 0x310c
movq 0x9e7a(%rip), %rdi      # 0xcfd8
leaq 0x4ff5(%rip), %rsi      # 0x815a
callq 0x21c0
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2100
pushq $0x1
popq %rdi
callq 0x2200
movq %rax, %rbx
jmp 0x31d8
jmp 0x31bb
jmp 0x31c0
jmp 0x31a8
jmp 0x31c0
jmp 0x31c0
jmp 0x31c0
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x20f0
jmp 0x31c3
jmp 0x31c0
jmp 0x31bb
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x4d1c
jmp 0x31c3
jmp 0x31bb
movq %rax, %rbx
jmp 0x31cc
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x4ba2
leaq -0x2b8(%rbp), %rdi
callq 0x2080
leaq -0x70(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x22c0
nop