// File: /workspace/github_cpp_makefile_star2_O2/SeanLee97[P]LL1-Parser/grammar.cpp
// Function: Grammar::get_rule(char*, std::vector<bool, std::allocator<bool>>&)
vector<vector<int> > Grammar::get_rule(char* inputFile, vector<bool> &func_is_epsilon) {
	vector<vector<int> > temp_rules(num_rules, vector<int> (maxidx_terminal + num_nonterminals));

	int symbol_pos = 0;	// symbol 位置
	int line_pos = 0;  // line 位置
	string cur_symbol;

	input.open(inputFile);

	// skip terminal define
	while(getline(input, line)) {
		if(line.compare("") == 0) break;
	}

	// process rule
	while(getline(input, line)) {
		symbol_pos = 0;
		
		stringstream ss(line);

		getline(ss, cur_symbol, ' ');

		string left_side = cur_symbol;
		temp_rules[line_pos][symbol_pos] = _get_idx_by_symbol(cur_symbol);
		++symbol_pos;

		getline(ss, cur_symbol, ' ');
		if(ss.eof()) {
			// 导空符号的记录，Nonterminal -> epsilon 说明导空, 为true
			func_is_epsilon[_get_idx_by_symbol(left_side) - 1] = true;
		}
		while(getline(ss, cur_symbol, ' ')) {
			temp_rules[line_pos][symbol_pos] = _get_idx_by_symbol(cur_symbol);
			++symbol_pos; 
		}

		++line_pos;
	}
	input.close();

	return temp_rules;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rcx, -0x50(%rbp)
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
movslq 0x8(%rsi), %r14
movslq (%rsi), %rax
movslq 0x4(%rsi), %rsi
addq %rax, %rsi
leaq -0x278(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x4b42
leaq -0x278(%rbp), %rdx
leaq -0x70(%rbp), %rcx
movq %r12, -0x30(%rbp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x4b94
leaq -0x278(%rbp), %rdi
callq 0x2632
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x10(%r15), %rdi
pushq $0x8
popq %rdx
movq %rdi, -0x38(%rbp)
movq %rbx, %rsi
callq 0x2120
leaq 0x218(%r15), %r14
leaq 0x4665(%rip), %rbx      # 0x72ce
movq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2c92
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2090
testl %eax, %eax
jne 0x2c69
movq %r14, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
leaq -0x90(%rbp), %r12
leaq -0xd0(%rbp), %rbx
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2e09
leaq -0x278(%rbp), %r14
movq %r14, %rdi
movq -0x48(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x2270
movq %r14, %rdi
movq %r12, %rsi
pushq $0x20
popq %rdx
callq 0x22e0
leaq -0x70(%rbp), %rdi
movq %r12, %rsi
callq 0x2220
leaq -0xf0(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2220
movq %r15, %rdi
movq %r14, %rsi
callq 0x2ebe
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
imulq $0x18, -0x40(%rbp), %r13
movq (%rcx,%r13), %rcx
movl %eax, (%rcx)
movq %r14, %rdi
callq 0x20d0
leaq -0x278(%rbp), %rdi
movq %r12, %rsi
pushq $0x20
popq %rdx
callq 0x22e0
movq -0x278(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x258(%rbp,%rax)
je 0x2d94
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
leaq -0x70(%rbp), %rsi
callq 0x2220
movq %r15, %rdi
movq %r14, %rsi
callq 0x2ebe
decl %eax
movslq %eax, %rsi
movq -0x50(%rbp), %rdi
callq 0x4bf4
orq %rdx, (%rax)
leaq -0xb0(%rbp), %rdi
callq 0x20d0
pushq $0x4
popq %r14
leaq -0x278(%rbp), %rdi
movq %r12, %rsi
pushq $0x20
popq %rdx
callq 0x22e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2deb
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2220
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2ebe
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx,%r13), %rcx
movl %eax, (%rcx,%r14)
movq %rbx, %rdi
callq 0x20d0
addq $0x4, %r14
jmp 0x2d98
incq -0x40(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x20d0
leaq -0x278(%rbp), %rdi
callq 0x2150
jmp 0x2cac
movq -0x38(%rbp), %rdi
callq 0x2060
leaq -0x90(%rbp), %rdi
callq 0x20d0
movq -0x30(%rbp), %rax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x278(%rbp), %rdi
callq 0x2632
jmp 0x2eb6
movq %rax, %rbx
jmp 0x2eb6
jmp 0x2e71
jmp 0x2e89
jmp 0x2e71
jmp 0x2e6c
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x2e82
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
jmp 0x2e82
jmp 0x2e71
movq %rax, %rbx
jmp 0x2e95
movq %rax, %rbx
jmp 0x2ea1
jmp 0x2e89
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x20d0
jmp 0x2e8c
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x20d0
leaq -0x278(%rbp), %rdi
callq 0x2150
leaq -0x90(%rbp), %rdi
callq 0x20d0
movq -0x30(%rbp), %rdi
callq 0x257e
movq %rbx, %rdi
callq 0x22c0