// File: /workspace/github_cpp_makefile_star2_O3/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, -0xd8(%rbp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movslq 0x8(%rsi), %r15
movslq (%rsi), %rax
movslq 0x4(%rsi), %rsi
addq %rax, %rsi
leaq -0x280(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x5d84
leaq -0x280(%rbp), %rdx
leaq -0x88(%rbp), %rcx
movq %rbx, -0x30(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5e1a
movq -0x280(%rbp), %rdi
testq %rdi, %rdi
je 0x2ebc
movq -0x270(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x10(%r12), %rdi
movq %rdi, -0x60(%rbp)
movq %r14, %rsi
movl $0x8, %edx
movq -0x30(%rbp), %r15
callq 0x2120
leaq 0x218(%r12), %rax
movq %rax, -0x38(%rbp)
leaq 0x53d2(%rip), %r14      # 0x82ce
movq -0x60(%rbp), %rbx
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %edx
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
callq 0x2300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2f41
movq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0x2090
testl %eax, %eax
jne 0x2f00
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
leaq -0xe8(%rbp), %rbx
movq $0x0, -0x68(%rbp)
leaq -0xf8(%rbp), %r13
addq $0x3f, %rax
movq %rax, -0xd0(%rbp)
movq -0x60(%rbp), %r14
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %edx
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x2300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x31ee
leaq -0x280(%rbp), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movl $0x18, %edx
callq 0x2290
movq %r14, %rdi
leaq -0x58(%rbp), %rsi
movl $0x20, %edx
callq 0x2300
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x63cc
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x63cc
movq %r12, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3336
movq (%r15), %rcx
movq -0x68(%rbp), %rdx
leaq (%rdx,%rdx,2), %r14
movq (%rcx,%r14,8), %rcx
movl %eax, (%rcx)
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x3057
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x21d0
leaq -0x280(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x20, %edx
callq 0x2300
movq -0x280(%rbp), %rax
movq -0x18(%rax), %rax
testb $0x2, -0x260(%rbp,%rax)
je 0x3128
leaq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %r15
movq %r15, %rdi
callq 0x63cc
movq %r12, %rdi
movq %r15, %rsi
callq 0x3336
leal -0x1(%rax), %ecx
movslq %ecx, %rcx
addl $0x3e, %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
movq -0xd8(%rbp), %rdx
addq (%rdx), %rax
movq %rcx, %rdx
andq -0xd0(%rbp), %rdx
xorl %esi, %esi
movabsq $-0x8000000000000000, %rdi # imm = 0x8000000000000000
cmpq %rdi, %rdx
setbe %sil
movl $0x1, %edx
shlq %cl, %rdx
orq %rdx, -0x8(%rax,%rsi,8)
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x3128
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x21d0
movl $0x4, %r15d
leaq -0x280(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x20, %edx
callq 0x2300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x31a6
movq %rbx, -0xf8(%rbp)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x63cc
movq %r12, %rdi
movq %r13, %rsi
callq 0x3336
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx,%r14,8), %rcx
movl %eax, (%rcx,%r15)
movq -0xf8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x31a0
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x21d0
addq $0x4, %r15
jmp 0x312e
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x31c2
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x21d0
incq -0x68(%rbp)
leaq -0x280(%rbp), %rdi
movq 0x7de4(%rip), %rsi      # 0xafb8
callq 0x2160
leaq -0x200(%rbp), %rdi
callq 0x20a0
movq -0x30(%rbp), %r15
jmp 0x2f6c
movq -0x60(%rbp), %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x3210
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x21d0
movq %r15, %rax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq -0x280(%rbp), %rdi
testq %rdi, %rdi
je 0x332e
movq -0x270(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
jmp 0x332e
movq %rax, %r14
jmp 0x332e
jmp 0x32a6
movq %rax, %r14
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x32ce
movq -0xb8(%rbp), %rsi
jmp 0x32c1
jmp 0x32cb
movq %rax, %r14
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x32ce
movq -0x98(%rbp), %rsi
jmp 0x32c1
jmp 0x32a6
jmp 0x329a
movq %rax, %r14
jmp 0x32ee
jmp 0x32a6
movq %rax, %r14
jmp 0x32d2
movq %rax, %r14
jmp 0x330d
movq %rax, %r14
movq -0xf8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x32ce
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x32ce
movq %rax, %r14
movq -0x30(%rbp), %r15
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x32ee
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x21d0
movq 0x7cc3(%rip), %rsi      # 0xafb8
leaq -0x280(%rbp), %rdi
callq 0x2160
leaq -0x200(%rbp), %rdi
callq 0x20a0
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x3326
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x21d0
movq %r15, %rdi
callq 0x2690
movq %r14, %rdi
callq 0x22e0