// File: /workspace/github_cpp_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movq %rsi, %r14
movq %rdi, %rbx
movq 0x6fbb(%rip), %rax      # 0xafb8
movq (%rax), %rdi
callq 0x21e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3df2
leaq -0xd8(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3adc
movq (%r15), %rsi
leaq 0x238(%rbx), %rdi
callq 0x4d38
movq -0xd8(%rbp), %rsi
addq $0x18, %rsi
leaq 0x250(%rbx), %rdi
callq 0x4d38
movslq 0x4(%rbx), %rsi
leaq -0x78(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x4e38
leaq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rcx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2bd0
leaq 0x2c8(%rbx), %r14
leaq -0x48(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x5ad6
movq %r15, %rdi
callq 0x257e
leaq -0x150(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x4e56
leaq -0x48(%rbp), %rdi
leaq -0x150(%rbp), %rdx
movq %rbx, %rsi
callq 0x2f52
leaq 0x268(%rbx), %r15
leaq -0x48(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5ad6
movq %r12, %rdi
callq 0x257e
leaq -0x150(%rbp), %rdi
callq 0x4ed4
leaq -0x128(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x4e56
leaq -0xc0(%rbp), %rdi
movq %r15, %rsi
callq 0x4ee8
leaq -0x48(%rbp), %rdi
leaq -0x128(%rbp), %rdx
leaq -0xc0(%rbp), %rcx
movq %rbx, %rsi
callq 0x3266
leaq 0x280(%rbx), %r12
leaq -0x48(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x5ad6
movq %r13, %rdi
callq 0x257e
leaq -0xc0(%rbp), %rdi
callq 0x257e
leaq -0x128(%rbp), %rdi
callq 0x4ed4
leaq -0x100(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x4e56
leaq -0xa8(%rbp), %rdi
movq %r15, %rsi
callq 0x4ee8
leaq -0x90(%rbp), %rdi
movq %r12, %rsi
callq 0x4ee8
leaq -0x48(%rbp), %rdi
leaq -0x100(%rbp), %rdx
leaq -0xa8(%rbp), %rcx
leaq -0x90(%rbp), %r8
movq %rbx, %rsi
callq 0x3764
leaq 0x298(%rbx), %rdi
leaq -0x48(%rbp), %r15
movq %r15, %rsi
callq 0x5ad6
movq %r15, %rdi
callq 0x257e
leaq -0x90(%rbp), %rdi
callq 0x257e
leaq -0xa8(%rbp), %rdi
callq 0x257e
leaq -0x100(%rbp), %rdi
callq 0x4ed4
movq 0x250(%rbx), %r13
movq 0x258(%rbx), %r12
movslq (%rbx), %rsi
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4b42
leaq 0x2b0(%rbx), %r15
subq %r13, %r12
sarq $0x5, %r12
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x4f42
leaq -0x48(%rbp), %rdi
callq 0x2632
movq 0x258(%rbx), %rax
subq 0x250(%rbx), %rax
sarq $0x5, %rax
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0x4256
imulq $0x18, %rcx, %rdx
addq (%r15), %rdx
xorl %esi, %esi
movslq (%rbx), %rdi
cmpq %rdi, %rsi
jge 0x4251
movq (%rdx), %rdi
andl $0x0, (%rdi,%rsi,4)
incq %rsi
jmp 0x423d
incq %rcx
jmp 0x422f
movq 0x298(%rbx), %rcx
movq 0x2a0(%rbx), %rax
subq %rcx, %rax
pushq $0x18
popq %rsi
cqto
idivq %rsi
xorl %edx, %edx
cmpq %rax, %rdx
je 0x42c7
imulq $0x18, %rdx, %rsi
movq (%rcx,%rsi), %rdi
movq 0x8(%rcx,%rsi), %r8
subq %rdi, %r8
sarq $0x2, %r8
addq (%r14), %rsi
movq (%r15), %r9
addq $-0x18, %r9
incq %rdx
xorl %r10d, %r10d
cmpq %r10, %r8
je 0x4271
movq (%rsi), %r11
movslq (%r11), %r11
imulq $0x18, %r11, %r12
movslq (%rdi,%r10,4), %r11
movq (%r9,%r12), %r12
cmpl $0x0, -0x4(%r12,%r11,4)
jne 0x43ba
movl %edx, -0x4(%r12,%r11,4)
incq %r10
jmp 0x429a
movq 0x2c8(%rbx), %r13
movq 0x2d0(%rbx), %r12
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rdx
xorl %esi, %esi
callq 0x4b42
leaq 0x2e0(%rbx), %r15
subq %r13, %r12
movq %r12, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x4f42
leaq -0x48(%rbp), %rdi
callq 0x2632
xorl %edi, %edi
movq 0x2c8(%rbx), %rcx
movq 0x2d0(%rbx), %rax
subq %rcx, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
cmpq %rdi, %rax
jbe 0x4393
movq %rdi, -0x50(%rbp)
imulq $0x18, %rdi, %r13
movq 0x8(%rcx,%r13), %rax
subq (%rcx,%r13), %rax
shrq $0x2, %rax
movl %eax, %r12d
decq %r12
testl %r12d, %r12d
jle 0x4377
movq (%r14), %rcx
movl %r12d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq (%rcx,%r13), %rcx
cmpl $0x0, (%rcx,%rax,4)
je 0x4349
leaq (%rcx,%rax,4), %rsi
movq (%r15), %rdi
addq %r13, %rdi
callq 0x4c6e
jmp 0x4349
addq (%r15), %r13
andl $0x0, -0x48(%rbp)
movq %r13, %rdi
leaq -0x48(%rbp), %rsi
callq 0x52cc
movq -0x50(%rbp), %rdi
incq %rdi
jmp 0x4313
leaq -0x78(%rbp), %rdi
callq 0x4ed4
leaq -0xd8(%rbp), %rdi
callq 0x4e0c
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6c0f(%rip), %rdi      # 0xafd0
leaq 0x2e15(%rip), %rsi      # 0x71dd
callq 0x21a0
xorl %edi, %edi
callq 0x2200
jmp 0x43d8
jmp 0x4457
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x2632
jmp 0x445a
jmp 0x4457
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x257e
jmp 0x43fc
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x257e
jmp 0x440d
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x4441
jmp 0x4457
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x257e
jmp 0x442c
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
jmp 0x4441
jmp 0x4457
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0x4ed4
jmp 0x445a
jmp 0x4457
jmp 0x4457
jmp 0x444e
movq %rax, %rbx
jmp 0x4463
jmp 0x4457
jmp 0x4457
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x4ed4
leaq -0xd8(%rbp), %rdi
callq 0x4e0c
movq %rbx, %rdi
callq 0x22c0
nop