// File: /workspace/github_cpp_makefile_star2_O3/SeanLee97[P]LL1-Parser/grammar.cpp
// Function: Grammar::init(char*)
void Grammar::init(char* inputName) {
	fflush(stdout);
	_grammar_counter(inputName); 

	vector<vector<string> > nonterm_and_term_names = _process_grammar(inputName); 
	terminal_names = nonterm_and_term_names[0]; 
	nonterminal_names = nonterm_and_term_names[1];

	// 导空符号的记录，若Nonterminal -> epsilon 说明导空则为true
	vector<bool> is_epsilon(num_nonterminals); 
	full_rules = get_rule(inputName, is_epsilon); 
	first_sets = get_first(is_epsilon);
	follow_sets = get_follow(is_epsilon, first_sets);
	predict_sets = get_predict(is_epsilon, first_sets, follow_sets);

	parse_table.resize(nonterminal_names.size(), vector<int>(maxidx_terminal));
	for(int i = 0; i < nonterminal_names.size(); i++) {
		for(int j = 0; j < maxidx_terminal; j++) {
			parse_table[i][j] = 0;
		}
	}

	for(int i = 0; i < predict_sets.size(); i++) {
		for(int j = 0; j < predict_sets[i].size(); j++) {
			if(parse_table[full_rules[i][0] - 1][predict_sets[i][j] - 1]) {
				cout << "Error: table exist!";
				exit(0);
			}
			parse_table[full_rules[i][0] - 1][predict_sets[i][j] - 1] = i + 1;
		}
	}

	// 在此标记结束符，在每行末尾追加 0 作为结束标记
	right_hand_sides.resize(full_rules.size(), vector<int>(0));
	for(int i = 0; i < full_rules.size(); i++) {
		for(int j = full_rules[i].size() - 1; j > 0; j--) {
			if(full_rules[i][j] != 0) right_hand_sides[i].push_back(full_rules[i][j]); 
		}
		right_hand_sides[i].push_back(0); 
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %r14
movq %rdi, %rbx
movq 0x644d(%rip), %rax      # 0xafb0
movq (%rax), %rdi
callq 0x2210
movq %rbx, %rdi
movq %r14, %rsi
callq 0x482a
leaq -0x168(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4376
movq (%r15), %rsi
leaq 0x238(%rbx), %rdi
callq 0x5fc8
movq -0x168(%rbp), %rsi
addq $0x18, %rsi
leaq 0x250(%rbx), %rdi
callq 0x5fc8
movslq 0x4(%rbx), %rsi
leaq -0x40(%rbp), %rdx
movb $0x0, (%rdx)
leaq -0xe0(%rbp), %rdi
leaq -0x60(%rbp), %rcx
callq 0x6982
leaq -0x60(%rbp), %rdi
leaq -0xe0(%rbp), %rcx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2e42
movups 0x2c8(%rbx), %xmm0
movq 0x2d8(%rbx), %rax
leaq -0x60(%rbp), %r14
movq (%r14), %rcx
movq %rcx, 0x2c8(%rbx)
movq 0x8(%r14), %rcx
movq %rcx, 0x2d0(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x2d8(%rbx)
leaq -0x40(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x2690
movq %r14, %rdi
callq 0x2690
leaq -0x108(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x61cc
leaq -0x60(%rbp), %rdi
leaq -0x108(%rbp), %rdx
movq %rbx, %rsi
callq 0x33f4
movups 0x268(%rbx), %xmm0
movq 0x278(%rbx), %rax
movq (%r14), %rcx
movq %rcx, 0x268(%rbx)
movq 0x8(%r14), %rcx
movq %rcx, 0x270(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x278(%rbx)
leaq -0x40(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x2690
movq %r14, %rdi
callq 0x2690
movq -0x108(%rbp), %rdi
testq %rdi, %rdi
je 0x4cf4
movq -0xe8(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0x108(%rbp)
movl %eax, -0x100(%rbp)
movq %rax, -0xf8(%rbp)
movl %eax, -0xf0(%rbp)
movq %rax, -0xe8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x61cc
leaq 0x268(%rbx), %r14
leaq -0x150(%rbp), %rdi
movq %r14, %rsi
callq 0x626a
leaq -0x60(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
leaq -0x150(%rbp), %rcx
movq %rbx, %rsi
callq 0x3802
movups 0x280(%rbx), %xmm0
movq 0x290(%rbx), %rax
leaq -0x60(%rbp), %r15
movq (%r15), %rcx
movq %rcx, 0x280(%rbx)
movq 0x8(%r15), %rcx
movq %rcx, 0x288(%rbx)
movq 0x10(%r15), %rcx
movq %rcx, 0x290(%rbx)
leaq -0x40(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
callq 0x2690
movq %r15, %rdi
callq 0x2690
leaq -0x150(%rbp), %rdi
callq 0x2690
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x4dda
movq -0x90(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0xb0(%rbp)
movl %eax, -0xa8(%rbp)
movq %rax, -0xa0(%rbp)
movl %eax, -0x98(%rbp)
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x61cc
leaq -0x138(%rbp), %rdi
movq %r14, %rsi
callq 0x626a
leaq 0x280(%rbx), %rsi
leaq -0x120(%rbp), %rdi
callq 0x626a
leaq -0x60(%rbp), %rdi
leaq -0x88(%rbp), %rdx
leaq -0x138(%rbp), %rcx
leaq -0x120(%rbp), %r8
movq %rbx, %rsi
callq 0x3ea0
movups 0x298(%rbx), %xmm0
movq 0x2a8(%rbx), %rax
leaq -0x60(%rbp), %r14
movq (%r14), %rcx
movq %rcx, 0x298(%rbx)
movq 0x8(%r14), %rcx
movq %rcx, 0x2a0(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x2a8(%rbx)
leaq -0x40(%rbp), %rdi
movups %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x2690
movq %r14, %rdi
callq 0x2690
leaq -0x120(%rbp), %rdi
callq 0x2690
leaq -0x138(%rbp), %rdi
callq 0x2690
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x4ed0
movq -0x68(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0x88(%rbp)
movl %eax, -0x80(%rbp)
movq %rax, -0x78(%rbp)
movl %eax, -0x70(%rbp)
movq %rax, -0x68(%rbp)
movq 0x250(%rbx), %r12
movq 0x258(%rbx), %r15
movslq (%rbx), %rsi
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x5d84
leaq 0x2b0(%rbx), %r14
subq %r12, %r15
sarq $0x5, %r15
leaq -0x40(%rbp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x630e
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x4f20
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x258(%rbx), %rax
subq 0x250(%rbx), %rax
je 0x4f71
sarq $0x5, %rax
movq 0x2b0(%rbx), %rcx
cmpq $0x1, %rax
adcq $0x0, %rax
movl (%rbx), %esi
xorl %edx, %edx
testl %esi, %esi
jle 0x4f69
leaq (%rdx,%rdx,2), %rsi
movq (%rcx,%rsi,8), %rdi
xorl %r8d, %r8d
movl $0x0, (%rdi,%r8,4)
incq %r8
movslq (%rbx), %rsi
cmpq %rsi, %r8
jl 0x4f56
incq %rdx
cmpq %rax, %rdx
jne 0x4f47
movq 0x298(%rbx), %rcx
movq 0x2a0(%rbx), %rdx
movq 0x2c8(%rbx), %rax
subq %rcx, %rdx
je 0x5008
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rdx
movq (%r14), %rsi
addq $-0x18, %rsi
cmpq $0x1, %rdx
adcq $0x0, %rdx
xorl %edi, %edi
leaq (%rdi,%rdi,2), %r10
movq (%rcx,%r10,8), %r8
movq 0x8(%rcx,%r10,8), %r9
subq %r8, %r9
je 0x5000
sarq $0x2, %r9
movq (%rax,%r10,8), %r10
incq %rdi
cmpq $0x1, %r9
adcq $0x0, %r9
xorl %r11d, %r11d
movslq (%r10), %r14
leaq (%r14,%r14,2), %r15
movslq (%r8,%r11,4), %r14
movq (%rsi,%r15,8), %r15
cmpl $0x0, -0x4(%r15,%r14,4)
jne 0x5186
movl %edi, -0x4(%r15,%r14,4)
incq %r11
cmpq %r11, %r9
jne 0x4fd6
jmp 0x5003
incq %rdi
cmpq %rdx, %rdi
jne 0x4fae
leaq 0x2e0(%rbx), %r14
movq 0x2d0(%rbx), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rsi
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movq %r14, %rdi
callq 0x630e
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x505a
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x2c8(%rbx), %rax
cmpq %rax, 0x2d0(%rbx)
je 0x514d
xorl %esi, %esi
movq %rsi, -0xb8(%rbp)
leaq (%rsi,%rsi,2), %r15
movq 0x8(%rax,%r15,8), %rcx
subq (%rax,%r15,8), %rcx
shrq $0x2, %rcx
decl %ecx
testl %ecx, %ecx
jle 0x50df
movl %ecx, %r12d
leaq 0x1(%r12), %r13
shlq $0x2, %r12
movq 0x2c8(%rbx), %rax
movq (%rax,%r15,8), %rdx
movl (%rdx,%r12), %eax
testl %eax, %eax
je 0x50d2
movq (%r14), %rcx
leaq (%rcx,%r15,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x50ca
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x50d2
addq %r12, %rdx
callq 0x66b8
decq %r13
addq $-0x4, %r12
cmpq $0x1, %r13
jg 0x509a
movq (%r14), %rax
leaq (%rax,%r15,8), %rdi
movl $0x0, -0x40(%rbp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x510e
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
movq -0xb8(%rbp), %rsi
jmp 0x511e
leaq -0x40(%rbp), %rdx
callq 0x6596
movq -0xb8(%rbp), %rsi
incq %rsi
movq 0x2c8(%rbx), %rax
movq 0x2d0(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq %rsi, %rcx
ja 0x5070
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x5168
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
leaq -0x168(%rbp), %rdi
callq 0x6176
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5e43(%rip), %rdi      # 0xafd0
leaq 0x3049(%rip), %rsi      # 0x81dd
callq 0x21b0
xorl %edi, %edi
callq 0x2230
jmp 0x51a2
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x52af
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
jmp 0x52af
jmp 0x52ac
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x2690
jmp 0x51dc
movq %rax, %rbx
leaq -0x138(%rbp), %rdi
callq 0x2690
jmp 0x51ed
movq %rax, %rbx
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x52af
movq -0x68(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0x88(%rbp)
movl %eax, -0x80(%rbp)
movq %rax, -0x78(%rbp)
movl %eax, -0x70(%rbp)
movq %rax, -0x68(%rbp)
jmp 0x52af
jmp 0x52ac
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0x2690
jmp 0x523e
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x52af
movq -0x90(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0xb0(%rbp)
movl %eax, -0xa8(%rbp)
movq %rax, -0xa0(%rbp)
movl %eax, -0x98(%rbp)
movq %rax, -0x90(%rbp)
jmp 0x52af
jmp 0x52ac
movq %rax, %rbx
movq -0x108(%rbp), %rsi
testq %rsi, %rsi
je 0x52af
leaq -0x108(%rbp), %rdi
callq 0x2320
jmp 0x52af
jmp 0x52ac
jmp 0x52ac
jmp 0x52a3
movq %rax, %rbx
jmp 0x52e6
jmp 0x52ac
jmp 0x52ac
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x52e6
movq -0xc0(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
movl %eax, -0xd8(%rbp)
movq %rax, -0xd0(%rbp)
movl %eax, -0xc8(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x6176
movq %rbx, %rdi
callq 0x22e0