// File: 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
subq $0x330, %rsp            # imm = 0x330
movq %rdi, -0x2c8(%rbp)
movq %rdi, %rax
movq %rax, -0x2c0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x2b8(%rbp)
movb $0x0, -0x21(%rbp)
movslq 0x8(%rcx), %rax
movq %rax, -0x2b0(%rbp)
movl (%rcx), %eax
movl 0x4(%rcx), %ecx
addl %ecx, %eax
cltq
movq %rax, -0x2a8(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x8550
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x8570
jmp 0x48ef
leaq -0x55(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x85e0
movq -0x2c8(%rbp), %rdi
movq -0x2b0(%rbp), %rsi
movq -0x2d0(%rbp), %rcx
leaq -0x40(%rbp), %rdx
callq 0x8600
jmp 0x491f
leaq -0x55(%rbp), %rdi
callq 0x3bd0
leaq -0x40(%rbp), %rdi
callq 0x3900
leaq -0x41(%rbp), %rdi
callq 0x3ae0
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x32f0
movq -0x2b8(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rsi
movl $0x8, %edx
callq 0x3140
jmp 0x496c
jmp 0x496e
movq -0x2b8(%rbp), %rsi
movq %rsi, %rdi
addq $0x10, %rdi
addq $0x218, %rsi            # imm = 0x218
callq 0x3070
movq %rax, -0x2d8(%rbp)
jmp 0x4991
movq -0x2d8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32e0
movb %al, -0x2d9(%rbp)
jmp 0x49af
movb -0x2d9(%rbp), %al
testb $0x1, %al
jne 0x49bb
jmp 0x4a2c
movq -0x2b8(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
leaq 0xc97a(%rip), %rsi      # 0x1134a
callq 0x30b0
cmpl $0x0, %eax
jne 0x4a27
jmp 0x4a2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4a08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x55(%rbp), %rdi
callq 0x3bd0
leaq -0x40(%rbp), %rdi
callq 0x3900
leaq -0x41(%rbp), %rdi
callq 0x3ae0
jmp 0x4e04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4dd1
jmp 0x496e
jmp 0x4a2e
movq -0x2b8(%rbp), %rsi
movq %rsi, %rdi
addq $0x10, %rdi
addq $0x218, %rsi            # imm = 0x218
callq 0x3070
movq %rax, -0x2e8(%rbp)
jmp 0x4a51
movq -0x2e8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32e0
movb %al, -0x2e9(%rbp)
jmp 0x4a6f
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0x4a7e
jmp 0x4daa
movq -0x2b8(%rbp), %rax
movl $0x0, -0x5c(%rbp)
addq $0x218, %rax            # imm = 0x218
movq %rax, -0x2f8(%rbp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x8680
movl %eax, -0x2f0(%rbp)
jmp 0x4ab0
movl -0x2f0(%rbp), %edx
movq -0x2f8(%rbp), %rsi
leaq -0x208(%rbp), %rdi
callq 0x3340
jmp 0x4acb
leaq -0x208(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x20, %edx
callq 0x33d0
jmp 0x4ae2
leaq -0x228(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x30f0
jmp 0x4af4
leaq -0x248(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x30f0
jmp 0x4b06
movq -0x2b8(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x4e10
movl %eax, -0x2fc(%rbp)
jmp 0x4b21
movq -0x2c8(%rbp), %rdi
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x5c(%rbp), %rsi
callq 0x86c0
movl -0x2fc(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x248(%rbp), %rdi
callq 0x3130
movl -0x5c(%rbp), %eax
incl %eax
movl %eax, -0x5c(%rbp)
leaq -0x208(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x20, %edx
callq 0x33d0
jmp 0x4b70
movq -0x208(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x208(%rbp,%rax), %rdi
callq 0x33c0
movb %al, -0x2fd(%rbp)
jmp 0x4b90
movb -0x2fd(%rbp), %al
testb $0x1, %al
jne 0x4b9f
jmp 0x4c98
movq -0x20(%rbp), %rax
movq %rax, -0x308(%rbp)
leaq -0x278(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x30f0
jmp 0x4bbf
movq -0x2b8(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x4e10
movl %eax, -0x30c(%rbp)
jmp 0x4bda
movq -0x308(%rbp), %rdi
movl -0x30c(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x86e0
movq %rdx, -0x320(%rbp)
movq %rax, -0x318(%rbp)
jmp 0x4c01
movq -0x320(%rbp), %rax
movq -0x318(%rbp), %rcx
movq %rcx, -0x258(%rbp)
movq %rax, -0x250(%rbp)
leaq -0x258(%rbp), %rdi
movl $0x1, %esi
callq 0x8740
leaq -0x278(%rbp), %rdi
callq 0x3130
jmp 0x4c98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4d9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4d90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x3130
jmp 0x4d90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x3130
jmp 0x4d90
jmp 0x4c9a
leaq -0x208(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x20, %edx
callq 0x33d0
movq %rax, -0x328(%rbp)
jmp 0x4cb8
movq -0x328(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32e0
movb %al, -0x329(%rbp)
jmp 0x4cd6
movb -0x329(%rbp), %al
testb $0x1, %al
jne 0x4ce5
jmp 0x4d6a
leaq -0x298(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x30f0
jmp 0x4cf7
movq -0x2b8(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x4e10
movl %eax, -0x330(%rbp)
jmp 0x4d12
movq -0x2c8(%rbp), %rdi
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x5c(%rbp), %rsi
callq 0x86c0
movl -0x330(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x298(%rbp), %rdi
callq 0x3130
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x4c9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x3130
jmp 0x4d90
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x3130
leaq -0x208(%rbp), %rdi
callq 0x3180
jmp 0x4a2e
leaq -0x228(%rbp), %rdi
callq 0x3130
leaq -0x208(%rbp), %rdi
callq 0x3180
jmp 0x4dd1
movq -0x2b8(%rbp), %rdi
addq $0x10, %rdi
callq 0x3080
jmp 0x4dbc
movb $0x1, -0x21(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x3130
testb $0x1, -0x21(%rbp)
jne 0x4df4
jmp 0x4de8
leaq -0x80(%rbp), %rdi
callq 0x3130
movq -0x2c8(%rbp), %rdi
callq 0x3710
jmp 0x4e04
movq -0x2c8(%rbp), %rdi
callq 0x3710
movq -0x2c0(%rbp), %rax
addq $0x330, %rsp            # imm = 0x330
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x3390
nopl (%rax)