// File: richardposner[P]BioNetFit2/src/code/Parser.cpp
// Function: Parser::Parser(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, char**)
Parser::Parser(string configFile, char** envp) {

	/*while (*envp) {
		string envEntry = *envp;
		size_t pos = envEntry.find('=');
		if (pos != string::npos) {
			string name = envEntry.substr(0, pos);
			string value = envEntry.substr(pos+1, string::npos);
			envSymbols[name] = value;
			logDebug(cout << "environment symbol: '" << name << "' = '" << value << "'" << endl);
		}
		++envp;
	}*/

	debugInfo = configFile;
	groupStack.push_front(this);

	FILE* in = fopen(configFile.c_str(), "r");
	if (!in) {
		cerr << "cannot open input file '" << configFile << "'" << endl;
		exit(2);
	}

	char buff[1024];
	while (fgets(buff, 1024, in)) {

		string line=buff;
		if ( (line.length() > 2) && (line[0] != '#') && (line.find(')') == string::npos) ) {
			string name;
			string value;
			split(line, name, value, '=');

			if (value == "(") {
				//logDebug(cout << "   config: new group '" << name << "'" << endl);
				Parser* newGroup = new Parser(name, debugInfo);
				groupStack.front()->groups[name] = newGroup;
				groupStack.push_front(newGroup);
			} else {
				for (list<Parser*>::reverse_iterator i = groupStack.rbegin(); i != groupStack.rend(); ++i) {
					(*i)->symbolExpand(value);
				}
				envSymbolExpand(value);
				//logDebug(cout << "   config: name = '" << name << "', value = '" << value << "'" << endl);
				groupStack.front()->add(name, value);
			}
		}
		if ( (line.length() > 0) && (line[0] != '#') && (line.find(')') != string::npos) ) {
			//logDebug(cout << "   end of group" << endl);
			groupStack.pop_front();
		}
	}

	fclose(in);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x620, %rsp            # imm = 0x620
movq %rsi, -0x570(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x580(%rbp)
movq %rdi, %rax
movq %rax, -0x5a0(%rbp)
callq 0x50690
movq -0x580(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x598(%rbp)
callq 0x50690
movq -0x580(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0x590(%rbp)
callq 0xa0240
movq -0x580(%rbp), %rdi
addq $0x90, %rdi
movq %rdi, -0x588(%rbp)
callq 0xa0260
movq -0x580(%rbp), %rdi
addq $0xa8, %rdi
movq %rdi, -0x578(%rbp)
callq 0x2f880
movq -0x578(%rbp), %rdi
movq -0x570(%rbp), %rsi
callq 0x30fa0
jmp 0x9f0ef
movq -0x5a0(%rbp), %rax
movq %rax, %rdi
addq $0x90, %rdi
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rsi
callq 0xa02c0
jmp 0x9f10f
movq -0x570(%rbp), %rdi
callq 0x2f290
movq %rax, %rdi
leaq 0x13faa7(%rip), %rsi    # 0x1debcc
callq 0x310e0
movq %rax, -0x5a8(%rbp)
jmp 0x9f133
movq -0x5a8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x9f1cd
movq 0x235e88(%rip), %rdi    # 0x2d4fd8
leaq 0x13b965(%rip), %rsi    # 0x1daabc
callq 0x2ff50
movq %rax, -0x5b0(%rbp)
jmp 0x9f165
movq -0x570(%rbp), %rsi
movq -0x5b0(%rbp), %rdi
callq 0x2f780
movq %rax, -0x5b8(%rbp)
jmp 0x9f181
movq -0x5b8(%rbp), %rdi
leaq 0x136f86(%rip), %rsi    # 0x1d6115
callq 0x2ff50
movq %rax, -0x5c0(%rbp)
jmp 0x9f19d
movq -0x5c0(%rbp), %rdi
movq 0x235e1d(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x9f1b2
movl $0x2, %edi
callq 0x30200
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x9f71f
jmp 0x9f1cf
movq -0x38(%rbp), %rdx
leaq -0x440(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x300f0
movq %rax, -0x5c8(%rbp)
jmp 0x9f1ed
movq -0x5c8(%rbp), %rax
cmpq $0x0, %rax
je 0x9f70b
leaq -0x461(%rbp), %rdi
movq %rdi, -0x5d0(%rbp)
callq 0x30a70
movq -0x5d0(%rbp), %rdx
leaq -0x460(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x44470
jmp 0x9f22d
leaq -0x461(%rbp), %rdi
callq 0x311c0
leaq -0x460(%rbp), %rdi
callq 0x2ff30
cmpq $0x2, %rax
jbe 0x9f684
xorl %eax, %eax
movl %eax, %esi
leaq -0x460(%rbp), %rdi
callq 0x30f60
movq %rax, -0x5d8(%rbp)
jmp 0x9f268
movq -0x5d8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x9f684
leaq -0x460(%rbp), %rdi
movl $0x29, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x30dc0
cmpq $-0x1, %rax
jne 0x9f684
leaq -0x488(%rbp), %rdi
callq 0x2f880
leaq -0x4a8(%rbp), %rdi
callq 0x2f880
leaq -0x4c8(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0x2f300
jmp 0x9f2c7
movq -0x5a0(%rbp), %rdi
leaq -0x4c8(%rbp), %rsi
leaq -0x488(%rbp), %rdx
leaq -0x4a8(%rbp), %rcx
movl $0x3d, %r8d
callq 0x9f770
jmp 0x9f2f0
leaq -0x4c8(%rbp), %rdi
callq 0x311e8
leaq 0x13b901(%rip), %rsi    # 0x1dac04
leaq -0x4a8(%rbp), %rdi
callq 0x44930
movb %al, -0x5d9(%rbp)
jmp 0x9f317
movb -0x5d9(%rbp), %al
testb $0x1, %al
jne 0x9f326
jmp 0x9f4e6
movl $0xc8, %edi
callq 0x2f3b0
movq %rax, -0x5e8(%rbp)
jmp 0x9f339
movb $0x1, -0x511(%rbp)
leaq -0x4f0(%rbp), %rdi
leaq -0x488(%rbp), %rsi
callq 0x2f300
jmp 0x9f355
movq -0x5a0(%rbp), %rsi
addq $0xa8, %rsi
leaq -0x510(%rbp), %rdi
callq 0x2f300
jmp 0x9f371
movq -0x5e8(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
leaq -0x510(%rbp), %rdx
callq 0x9eef0
jmp 0x9f38d
movb $0x0, -0x511(%rbp)
leaq -0x510(%rbp), %rdi
callq 0x311e8
leaq -0x4f0(%rbp), %rdi
callq 0x311e8
movq -0x5e8(%rbp), %rax
movq -0x5a0(%rbp), %rdi
movq %rax, -0x4d0(%rbp)
movq -0x4d0(%rbp), %rax
movq %rax, -0x5f8(%rbp)
addq $0x90, %rdi
callq 0xa0300
movq (%rax), %rdi
addq $0x60, %rdi
leaq -0x488(%rbp), %rsi
callq 0xa0330
movq %rax, -0x5f0(%rbp)
jmp 0x9f3f7
movq -0x5a0(%rbp), %rdi
movq -0x5f0(%rbp), %rax
movq -0x5f8(%rbp), %rcx
movq %rcx, (%rax)
addq $0x90, %rdi
leaq -0x4d0(%rbp), %rsi
callq 0xa0410
jmp 0x9f424
jmp 0x9f650
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x461(%rbp), %rdi
callq 0x311c0
jmp 0x9f71f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x9f6fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x9f66a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x4c8(%rbp), %rdi
callq 0x311e8
jmp 0x9f66a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x9f4c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x9f4b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x510(%rbp), %rdi
callq 0x311e8
leaq -0x4f0(%rbp), %rdi
callq 0x311e8
testb $0x1, -0x511(%rbp)
jne 0x9f4d0
jmp 0x9f4e1
movq -0x5e8(%rbp), %rdi
movl $0xc8, %esi
callq 0x2f2a0
jmp 0x9f66a
movq -0x5a0(%rbp), %rsi
addq $0x90, %rsi
leaq -0x520(%rbp), %rdi
callq 0xa0450
movq -0x5a0(%rbp), %rsi
addq $0x90, %rsi
leaq -0x528(%rbp), %rdi
movq %rdi, -0x608(%rbp)
callq 0xa04d0
movq -0x608(%rbp), %rsi
leaq -0x520(%rbp), %rdi
callq 0xa04a0
movb %al, -0x5f9(%rbp)
jmp 0x9f53c
movb -0x5f9(%rbp), %al
testb $0x1, %al
jne 0x9f548
jmp 0x9f58a
leaq -0x520(%rbp), %rdi
callq 0xa0520
movq %rax, -0x610(%rbp)
jmp 0x9f55d
movq -0x610(%rbp), %rax
movq (%rax), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x9f900
jmp 0x9f575
jmp 0x9f577
leaq -0x520(%rbp), %rdi
callq 0xa0550
jmp 0x9f585
jmp 0x9f500
movq -0x5a0(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x9f930
jmp 0x9f59f
movq -0x5a0(%rbp), %rdi
addq $0x90, %rdi
callq 0xa0300
movq (%rax), %rax
movq %rax, -0x618(%rbp)
leaq -0x548(%rbp), %rdi
leaq -0x488(%rbp), %rsi
callq 0x2f300
jmp 0x9f5d1
leaq -0x568(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x2f300
jmp 0x9f5e6
movq -0x618(%rbp), %rdi
leaq -0x548(%rbp), %rsi
leaq -0x568(%rbp), %rdx
callq 0x9f960
jmp 0x9f602
leaq -0x568(%rbp), %rdi
callq 0x311e8
leaq -0x548(%rbp), %rdi
callq 0x311e8
jmp 0x9f650
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x9f642
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x568(%rbp), %rdi
callq 0x311e8
leaq -0x548(%rbp), %rdi
callq 0x311e8
jmp 0x9f66a
leaq -0x4a8(%rbp), %rdi
callq 0x311e8
leaq -0x488(%rbp), %rdi
callq 0x311e8
jmp 0x9f684
leaq -0x4a8(%rbp), %rdi
callq 0x311e8
leaq -0x488(%rbp), %rdi
callq 0x311e8
jmp 0x9f6fd
leaq -0x460(%rbp), %rdi
callq 0x2ff30
cmpq $0x0, %rax
jbe 0x9f6ec
xorl %eax, %eax
movl %eax, %esi
leaq -0x460(%rbp), %rdi
callq 0x30f60
movq %rax, -0x620(%rbp)
jmp 0x9f6af
movq -0x620(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x9f6ec
leaq -0x460(%rbp), %rdi
movl $0x29, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x30dc0
cmpq $-0x1, %rax
je 0x9f6ec
movq -0x5a0(%rbp), %rdi
addq $0x90, %rdi
callq 0xa0580
leaq -0x460(%rbp), %rdi
callq 0x311e8
jmp 0x9f1cf
leaq -0x460(%rbp), %rdi
callq 0x311e8
jmp 0x9f71f
movq -0x38(%rbp), %rdi
callq 0x2fa90
jmp 0x9f716
addq $0x620, %rsp            # imm = 0x620
popq %rbp
retq
movq -0x578(%rbp), %rdi
callq 0x311e8
movq -0x588(%rbp), %rdi
callq 0xa0280
movq -0x590(%rbp), %rdi
callq 0xa02a0
movq -0x598(%rbp), %rdi
callq 0x50c20
movq -0x580(%rbp), %rdi
callq 0x50c20
movq -0x20(%rbp), %rdi
callq 0x30170
nopw %cs:(%rax,%rax)