// File: /workspace/github_cpp_makefile_star2_O1/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 $0x138, %rsp            # imm = 0x138
movq %rsi, %r14
movq %rdi, %rbx
movq 0x63ad(%rip), %rax      # 0xafb0
movq (%rax), %rdi
callq 0x2210
movq %rbx, %rdi
movq %r14, %rsi
callq 0x48ca
leaq -0x160(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4400
movq (%r15), %rsi
leaq 0x238(%rbx), %rdi
callq 0x60c4
movq -0x160(%rbp), %rsi
addq $0x18, %rsi
leaq 0x250(%rbx), %rdi
callq 0x60c4
movslq 0x4(%rbx), %rsi
leaq -0x40(%rbp), %rdx
movb $0x0, (%rdx)
leaq -0x68(%rbp), %rdi
leaq -0x80(%rbp), %rcx
callq 0x6a46
leaq -0x80(%rbp), %rdi
leaq -0x68(%rbp), %rcx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2e02
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x2c8(%rbx), %rax
movups 0x2d0(%rbx), %xmm0
leaq -0x80(%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)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
callq 0x2650
movq %r14, %rdi
callq 0x2650
leaq -0x100(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x62a2
leaq -0x80(%rbp), %rdi
leaq -0x100(%rbp), %rdx
movq %rbx, %rsi
callq 0x33d4
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x268(%rbx), %rax
movups 0x270(%rbx), %xmm0
movq (%r14), %rcx
movq %rcx, 0x268(%rbx)
movq 0x8(%r14), %rcx
movq %rcx, 0x270(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x278(%rbx)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
callq 0x2650
movq %r14, %rdi
callq 0x2650
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x4db5
movq -0xe0(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0x100(%rbp)
movl %eax, -0xf8(%rbp)
movq %rax, -0xf0(%rbp)
movl %eax, -0xe8(%rbp)
movq %rax, -0xe0(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x62a2
leaq 0x268(%rbx), %r14
leaq -0x148(%rbp), %rdi
movq %r14, %rsi
callq 0x6340
leaq -0x80(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
leaq -0x148(%rbp), %rcx
movq %rbx, %rsi
callq 0x3838
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x280(%rbx), %rax
movups 0x288(%rbx), %xmm0
leaq -0x80(%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)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, (%r15)
movq %rdx, 0x8(%r15)
movq %rsi, 0x10(%r15)
callq 0x2650
movq %r15, %rdi
callq 0x2650
leaq -0x148(%rbp), %rdi
callq 0x2650
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x4ead
movq -0xb0(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0xd0(%rbp)
movl %eax, -0xc8(%rbp)
movq %rax, -0xc0(%rbp)
movl %eax, -0xb8(%rbp)
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x62a2
leaq -0x130(%rbp), %rdi
movq %r14, %rsi
callq 0x6340
leaq 0x280(%rbx), %rsi
leaq -0x118(%rbp), %rdi
callq 0x6340
leaq -0x80(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
leaq -0x130(%rbp), %rcx
leaq -0x118(%rbp), %r8
movq %rbx, %rsi
callq 0x3f1e
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x298(%rbx), %rax
movups 0x2a0(%rbx), %xmm0
leaq -0x80(%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)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
callq 0x2650
movq %r14, %rdi
callq 0x2650
leaq -0x118(%rbp), %rdi
callq 0x2650
leaq -0x130(%rbp), %rdi
callq 0x2650
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x4fc4
movq -0x88(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0xa8(%rbp)
movl %eax, -0xa0(%rbp)
movq %rax, -0x98(%rbp)
movl %eax, -0x90(%rbp)
movq %rax, -0x88(%rbp)
movq 0x250(%rbx), %r12
movq 0x258(%rbx), %r15
movslq (%rbx), %rsi
leaq -0x40(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x5e84
leaq 0x2b0(%rbx), %r14
subq %r12, %r15
sarq $0x5, %r15
leaq -0x40(%rbp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x63e4
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x5014
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x258(%rbx), %rax
subq 0x250(%rbx), %rax
je 0x505e
sarq $0x5, %rax
movq (%r14), %rcx
cmpq $0x1, %rax
adcq $0x0, %rax
xorl %edx, %edx
cmpl $0x0, (%rbx)
jle 0x5056
leaq (%rdx,%rdx,2), %rsi
movq (%rcx,%rsi,8), %rsi
xorl %edi, %edi
movl $0x0, (%rsi,%rdi,4)
incq %rdi
movslq (%rbx), %r8
cmpq %r8, %rdi
jl 0x5044
incq %rdx
cmpq %rax, %rdx
jne 0x5035
movq 0x298(%rbx), %rax
movq 0x2a0(%rbx), %rcx
subq %rax, %rcx
je 0x50fc
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
movq 0x2b0(%rbx), %rdx
movq 0x2c8(%rbx), %rsi
addq $-0x18, %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edi, %edi
leaq (%rdi,%rdi,2), %r10
movq (%rax,%r10,8), %r8
movq 0x8(%rax,%r10,8), %r9
subq %r8, %r9
je 0x50f4
sarq $0x2, %r9
movq (%rsi,%r10,8), %r10
cmpq $0x1, %r9
adcq $0x0, %r9
leal 0x1(%rdi), %r11d
xorl %r14d, %r14d
movslq (%r10), %r15
leaq (%r15,%r15,2), %r12
movslq (%r8,%r14,4), %r15
movq (%rdx,%r12,8), %r12
cmpl $0x0, -0x4(%r12,%r15,4)
jne 0x528c
movl %r11d, -0x4(%r12,%r15,4)
incq %r14
cmpq %r14, %r9
jne 0x50cc
incq %rdi
cmpq %rcx, %rdi
jne 0x50a3
leaq 0x2e0(%rbx), %r14
movq 0x2d0(%rbx), %rsi
subq 0x2c8(%rbx), %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 0x63e4
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x5152
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq 0x2c8(%rbx), %rax
cmpq %rax, 0x2d0(%rbx)
je 0x5245
xorl %esi, %esi
movq %rsi, -0xd8(%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 0x51d7
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 0x51ca
movq (%r14), %rcx
leaq (%rcx,%r15,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x51c2
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x51ca
addq %r12, %rdx
callq 0x677c
decq %r13
addq $-0x4, %r12
cmpq $0x1, %r13
jg 0x5192
movq (%r14), %rax
leaq (%rax,%r15,8), %rdi
movl $0x0, -0x40(%rbp)
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5206
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
movq -0xd8(%rbp), %rsi
jmp 0x5216
leaq -0x40(%rbp), %rdx
callq 0x665a
movq -0xd8(%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 0x5168
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x526e
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0x68(%rbp)
movl %eax, -0x60(%rbp)
movq %rax, -0x58(%rbp)
movl %eax, -0x50(%rbp)
movq %rax, -0x48(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x6252
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5d3d(%rip), %rdi      # 0xafd0
leaq 0x2f43(%rip), %rsi      # 0x81dd
callq 0x21b0
xorl %edi, %edi
callq 0x2230
jmp 0x52a8
movq %rax, %rbx
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x53c4
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
jmp 0x53c4
jmp 0x53c1
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x2650
jmp 0x52e2
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x2650
jmp 0x52f3
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x53c4
movq -0x88(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0xa8(%rbp)
movl %eax, -0xa0(%rbp)
movq %rax, -0x98(%rbp)
movl %eax, -0x90(%rbp)
movq %rax, -0x88(%rbp)
jmp 0x53c4
jmp 0x53c1
movq %rax, %rbx
leaq -0x148(%rbp), %rdi
callq 0x2650
jmp 0x5353
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x53c4
movq -0xb0(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0xd0(%rbp)
movl %eax, -0xc8(%rbp)
movq %rax, -0xc0(%rbp)
movl %eax, -0xb8(%rbp)
movq %rax, -0xb0(%rbp)
jmp 0x53c4
jmp 0x53c1
movq %rax, %rbx
movq -0x100(%rbp), %rsi
testq %rsi, %rsi
je 0x53c4
leaq -0x100(%rbp), %rdi
callq 0x2320
jmp 0x53c4
jmp 0x53c1
jmp 0x53c1
jmp 0x53b8
movq %rax, %rbx
jmp 0x53ed
jmp 0x53c1
jmp 0x53c1
movq %rax, %rbx
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x53ed
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
xorl %eax, %eax
movq %rax, -0x68(%rbp)
movl %eax, -0x60(%rbp)
movq %rax, -0x58(%rbp)
movl %eax, -0x50(%rbp)
movq %rax, -0x48(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x6252
movq %rbx, %rdi
callq 0x22e0
nop