// File: 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
subq $0x450, %rsp            # imm = 0x450
movq %rsi, -0x338(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x330(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x22a0
leaq -0x238(%rbp), %rdi
callq 0x2210
jmp 0x374c
movq -0x338(%rbp), %rdi
callq 0x20e0
movq %rax, %rsi
leaq -0x238(%rbp), %rdi
movl $0x8, %edx
callq 0x2150
jmp 0x376e
leaq -0x238(%rbp), %rdi
callq 0x22f0
movb %al, -0x339(%rbp)
jmp 0x3782
movb -0x339(%rbp), %al
testb $0x1, %al
jne 0x3791
jmp 0x3e77
jmp 0x3793
movq -0x238(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x238(%rbp,%rax), %rdi
callq 0x2320
movb %al, -0x33a(%rbp)
jmp 0x37b3
movb -0x33a(%rbp), %al
testb $0x1, %al
jne 0x37c2
jmp 0x3d4c
leaq -0x238(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2050
jmp 0x37d4
leaq -0x30(%rbp), %rdi
callq 0x2160
cmpq $0x0, %rax
jne 0x3813
jmp 0x3793
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x3f0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x3f00
movq 0x187be(%rip), %rdi     # 0x1bfd8
leaq 0xf7eb(%rip), %rsi      # 0x1300c
callq 0x21c0
movq %rax, -0x348(%rbp)
jmp 0x382f
movq -0x348(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x21a0
movq %rax, -0x350(%rbp)
jmp 0x3848
movq -0x350(%rbp), %rdi
movq 0x18772(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x385d
leaq -0x260(%rbp), %rdi
callq 0x6c50
leaq -0x281(%rbp), %rdi
movq %rdi, -0x358(%rbp)
callq 0x2350
movq -0x358(%rbp), %rdx
leaq 0xf78c(%rip), %rsi      # 0x13016
leaq -0x280(%rbp), %rdi
callq 0x2290
jmp 0x3898
movq -0x330(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x260(%rbp), %rdx
leaq -0x280(%rbp), %rcx
xorl %r8d, %r8d
callq 0x35c0
jmp 0x38bb
leaq -0x280(%rbp), %rdi
callq 0x2140
leaq -0x281(%rbp), %rdi
callq 0x2200
xorl %eax, %eax
movl %eax, %esi
leaq -0x260(%rbp), %rdi
callq 0x7090
movq %rax, -0x360(%rbp)
jmp 0x38ec
movq -0x360(%rbp), %rdi
leaq 0xf71f(%rip), %rsi      # 0x13019
callq 0x7060
movb %al, -0x361(%rbp)
jmp 0x3907
movb -0x361(%rbp), %al
testb $0x1, %al
jne 0x3913
jmp 0x397c
movl $0x2, -0x288(%rbp)
jmp 0x3d19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x3954
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x280(%rbp), %rdi
callq 0x2140
leaq -0x281(%rbp), %rdi
callq 0x2200
jmp 0x3d3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
jmp 0x3d3b
movl $0x0, -0x28c(%rbp)
movl -0x28c(%rbp), %eax
movq %rax, -0x370(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x6c90
movq %rax, %rcx
movq -0x370(%rbp), %rax
cmpq %rcx, %rax
jae 0x3a6a
movq 0x1861f(%rip), %rdi     # 0x1bfd8
leaq 0xf64c(%rip), %rsi      # 0x1300c
callq 0x21c0
movq %rax, -0x378(%rbp)
jmp 0x39ce
movq -0x378(%rbp), %rdi
leaq 0xf63f(%rip), %rsi      # 0x1301b
callq 0x21c0
movq %rax, -0x380(%rbp)
jmp 0x39ea
movl -0x28c(%rbp), %eax
movl %eax, %esi
leaq -0x260(%rbp), %rdi
callq 0x7090
movq %rax, -0x388(%rbp)
jmp 0x3a07
movq -0x388(%rbp), %rsi
movq -0x380(%rbp), %rdi
callq 0x21a0
movq %rax, -0x390(%rbp)
jmp 0x3a23
movq -0x390(%rbp), %rdi
leaq 0xf5f8(%rip), %rsi      # 0x13029
callq 0x21c0
movq %rax, -0x398(%rbp)
jmp 0x3a3f
movq -0x398(%rbp), %rdi
movq 0x1857b(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x3a54
jmp 0x3a56
movl -0x28c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28c(%rbp)
jmp 0x3986
movq -0x330(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x3a8(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x260(%rbp), %rdi
callq 0x7090
movq %rax, -0x3a0(%rbp)
jmp 0x3a95
movq -0x3a0(%rbp), %rsi
movq -0x3a8(%rbp), %rdi
callq 0x7580
movq %rax, -0x3b0(%rbp)
jmp 0x3ab1
movq -0x330(%rbp), %rdi
movq -0x3b0(%rbp), %rax
movq %rax, -0x298(%rbp)
addq $0x48, %rdi
callq 0x75e0
movq %rax, -0x2a0(%rbp)
leaq -0x298(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
callq 0x75b0
testb $0x1, %al
jne 0x3aef
jmp 0x3b46
movq 0x184e2(%rip), %rdi     # 0x1bfd8
leaq 0xf649(%rip), %rsi      # 0x13146
callq 0x21c0
movq %rax, -0x3b8(%rbp)
jmp 0x3b0b
movq -0x3b8(%rbp), %rdi
movq 0x184af(%rip), %rsi     # 0x1bfc8
callq 0x21f0
movq %rax, -0x3c0(%rbp)
jmp 0x3b27
movq -0x3c0(%rbp), %rdi
movq 0x18493(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x3b3c
movl $0x1, %edi
callq 0x2220
xorl %eax, %eax
movl %eax, %esi
leaq -0x260(%rbp), %rdi
callq 0x7090
movq %rax, -0x3c8(%rbp)
jmp 0x3b5f
leaq -0x260(%rbp), %rdi
movl $0x1, %esi
callq 0x7090
movq %rax, -0x3d0(%rbp)
jmp 0x3b79
movq -0x3d0(%rbp), %rdx
movq -0x3c8(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
callq 0x7610
jmp 0x3b95
leaq -0x2f0(%rbp), %rdi
callq 0x7670
jmp 0x3ba3
movq -0x330(%rbp), %rdi
addq $0x48, %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x76b0
movb %dl, -0x3d9(%rbp)
movq %rax, -0x3d8(%rbp)
jmp 0x3bc9
movb -0x3d9(%rbp), %al
movq -0x3d8(%rbp), %rcx
movq %rcx, -0x310(%rbp)
movb %al, -0x308(%rbp)
movq -0x310(%rbp), %rax
movq %rax, -0x300(%rbp)
movb -0x308(%rbp), %al
movb %al, -0x2f8(%rbp)
leaq -0x2f0(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0x76f0
movb -0x2e8(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x3d03
movq 0x183ad(%rip), %rdi     # 0x1bfd8
leaq 0xf533(%rip), %rsi      # 0x13165
callq 0x21c0
movq %rax, -0x3e8(%rbp)
jmp 0x3c40
movq -0x3e8(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x21a0
movq %rax, -0x3f0(%rbp)
jmp 0x3c5c
movq -0x3f0(%rbp), %rdi
leaq 0xf506(%rip), %rsi      # 0x13170
callq 0x21c0
movq %rax, -0x3f8(%rbp)
jmp 0x3c78
movq -0x3f8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x21a0
movq %rax, -0x400(%rbp)
jmp 0x3c94
movq -0x400(%rbp), %rdi
leaq 0xf4d1(%rip), %rsi      # 0x13173
callq 0x21c0
movq %rax, -0x408(%rbp)
jmp 0x3cb0
movq -0x408(%rbp), %rdi
movq 0x1830a(%rip), %rsi     # 0x1bfc8
callq 0x21f0
movq %rax, -0x410(%rbp)
jmp 0x3ccc
movq -0x410(%rbp), %rdi
movq 0x182ee(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x3ce1
jmp 0x3d03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0x7720
jmp 0x3d3b
leaq -0x2e0(%rbp), %rdi
callq 0x7720
movl $0x0, -0x288(%rbp)
leaq -0x260(%rbp), %rdi
callq 0x6f60
movl -0x288(%rbp), %eax
testl %eax, %eax
je 0x3d36
jmp 0x3d31
jmp 0x3793
jmp 0x3793
leaq -0x260(%rbp), %rdi
callq 0x6f60
jmp 0x3f00
leaq -0x238(%rbp), %rdi
callq 0x2070
jmp 0x3d5a
movq -0x330(%rbp), %rdi
addq $0x48, %rdi
callq 0x7750
movq %rax, -0x318(%rbp)
movq -0x330(%rbp), %rdi
addq $0x48, %rdi
callq 0x75e0
movq %rax, -0x320(%rbp)
leaq -0x318(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0x75b0
testb $0x1, %al
jne 0x3da4
jmp 0x3e75
movq 0x1822d(%rip), %rdi     # 0x1bfd8
leaq 0xf3d9(%rip), %rsi      # 0x1318b
callq 0x21c0
movq %rax, -0x418(%rbp)
jmp 0x3dc0
leaq -0x318(%rbp), %rdi
callq 0x7780
movq -0x418(%rbp), %rdi
movq %rax, %rsi
callq 0x21a0
movq %rax, -0x420(%rbp)
jmp 0x3de4
movq -0x420(%rbp), %rdi
leaq 0xf37e(%rip), %rsi      # 0x13170
callq 0x21c0
movq %rax, -0x428(%rbp)
jmp 0x3e00
leaq -0x318(%rbp), %rdi
callq 0x7780
movq -0x428(%rbp), %rdi
movq %rax, %rsi
addq $0x20, %rsi
callq 0x21a0
movq %rax, -0x430(%rbp)
jmp 0x3e28
movq -0x430(%rbp), %rdi
leaq 0xf368(%rip), %rsi      # 0x1319e
callq 0x21c0
movq %rax, -0x438(%rbp)
jmp 0x3e44
movq -0x438(%rbp), %rdi
movq 0x18176(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x3e59
jmp 0x3e5b
leaq -0x318(%rbp), %rdi
xorl %esi, %esi
callq 0x77b0
movq %rax, -0x328(%rbp)
jmp 0x3d71
jmp 0x3ee2
movq 0x1815a(%rip), %rdi     # 0x1bfd8
leaq 0xf29c(%rip), %rsi      # 0x13121
callq 0x21c0
movq %rax, -0x440(%rbp)
jmp 0x3e93
movq -0x338(%rbp), %rsi
movq -0x440(%rbp), %rdi
callq 0x21a0
movq %rax, -0x448(%rbp)
jmp 0x3eaf
movq -0x448(%rbp), %rdi
leaq 0xf16c(%rip), %rsi      # 0x13029
callq 0x21c0
movq %rax, -0x450(%rbp)
jmp 0x3ecb
movq -0x450(%rbp), %rdi
movq 0x180ef(%rip), %rsi     # 0x1bfc8
callq 0x21f0
jmp 0x3ee0
jmp 0x3ee2
leaq -0x238(%rbp), %rdi
callq 0x2090
leaq -0x30(%rbp), %rdi
callq 0x2140
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
leaq -0x238(%rbp), %rdi
callq 0x2090
leaq -0x30(%rbp), %rdi
callq 0x2140
movq -0x240(%rbp), %rdi
callq 0x2340
nopw %cs:(%rax,%rax)