// File: SeanLee97[P]LL1-Parser/grammar.cpp
// Function: Grammar::_grammar_counter(char*)
void Grammar::_grammar_counter(char* inputFile) {
	input.open(inputFile);
	// 获取出现次数最多的字符
	string cur_maxfreq_terminals;

	while(getline(input, line)){
		if(line.compare("") == 0) break;

		stringstream ss(line);

		getline(ss, cur_maxfreq_terminals, ' ');
		getline(ss, cur_maxfreq_terminals, ' ');
		// 最大id-terminal
		// atoi字符串转换成整型数的一个函数
		maxidx_terminal = atoi(cur_maxfreq_terminals.c_str());
	}

	string last_unique_nonterminal(""); 
	string this_nonterminal;

	while(getline(input, line)) {
		stringstream ss(line); 
		getline(ss, this_nonterminal, ' ');

		if(this_nonterminal.compare(last_unique_nonterminal) != 0) {
			++num_nonterminals;
			last_unique_nonterminal = this_nonterminal;
		}

		++num_rules;
	}

	input.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3e0, %rsp            # imm = 0x3E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
addq $0x10, %rdi
movq -0x10(%rbp), %rsi
movl $0x8, %edx
callq 0x3140
leaq -0x30(%rbp), %rdi
callq 0x32f0
movq -0x3a0(%rbp), %rsi
movq %rsi, %rdi
addq $0x10, %rdi
addq $0x218, %rsi            # imm = 0x218
callq 0x3070
movq %rax, -0x3a8(%rbp)
jmp 0x6c2c
movq -0x3a8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32e0
movb %al, -0x3a9(%rbp)
jmp 0x6c4a
movb -0x3a9(%rbp), %al
testb $0x1, %al
jne 0x6c59
jmp 0x6d4c
movq -0x3a0(%rbp), %rdi
addq $0x218, %rdi            # imm = 0x218
leaq 0xa6dc(%rip), %rsi      # 0x1134a
callq 0x30b0
cmpl $0x0, %eax
jne 0x6c8e
jmp 0x6d4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6f49
movq -0x3a0(%rbp), %rax
addq $0x218, %rax            # imm = 0x218
movq %rax, -0x3b8(%rbp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x8680
movl %eax, -0x3b0(%rbp)
jmp 0x6cb9
movl -0x3b0(%rbp), %edx
movq -0x3b8(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0x3340
jmp 0x6cd4
leaq -0x1c8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x20, %edx
callq 0x33d0
jmp 0x6ceb
leaq -0x1c8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x20, %edx
callq 0x33d0
jmp 0x6d02
leaq -0x30(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x3330
movl %eax, %ecx
movq -0x3a0(%rbp), %rax
movl %ecx, (%rax)
leaq -0x1c8(%rbp), %rdi
callq 0x3180
jmp 0x6c09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x3180
jmp 0x6f49
leaq -0x1e9(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
callq 0x33a0
movq -0x3c0(%rbp), %rdx
leaq 0xa5dd(%rip), %rsi      # 0x1134a
leaq -0x1e8(%rbp), %rdi
callq 0x4440
jmp 0x6d7b
leaq -0x1e9(%rbp), %rdi
callq 0x3250
leaq -0x210(%rbp), %rdi
callq 0x32f0
movq -0x3a0(%rbp), %rsi
movq %rsi, %rdi
addq $0x10, %rdi
addq $0x218, %rsi            # imm = 0x218
callq 0x3070
movq %rax, -0x3c8(%rbp)
jmp 0x6db6
movq -0x3c8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32e0
movb %al, -0x3c9(%rbp)
jmp 0x6dd4
movb -0x3c9(%rbp), %al
testb $0x1, %al
jne 0x6de3
jmp 0x6ef5
movq -0x3a0(%rbp), %rax
addq $0x218, %rax            # imm = 0x218
movq %rax, -0x3d8(%rbp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x8680
movl %eax, -0x3d0(%rbp)
jmp 0x6e0e
movl -0x3d0(%rbp), %edx
movq -0x3d8(%rbp), %rsi
leaq -0x398(%rbp), %rdi
callq 0x3340
jmp 0x6e29
leaq -0x398(%rbp), %rdi
leaq -0x210(%rbp), %rsi
movl $0x20, %edx
callq 0x33d0
jmp 0x6e43
leaq -0x210(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x3030
movl %eax, -0x3dc(%rbp)
jmp 0x6e5e
movl -0x3dc(%rbp), %eax
cmpl $0x0, %eax
je 0x6ed4
movq -0x3a0(%rbp), %rax
movl 0x4(%rax), %ecx
incl %ecx
movl %ecx, 0x4(%rax)
leaq -0x1e8(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x3040
jmp 0x6e8d
jmp 0x6ed4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1e9(%rbp), %rdi
callq 0x3250
jmp 0x6f49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6f31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x398(%rbp), %rdi
callq 0x3180
jmp 0x6f31
movq -0x3a0(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
leaq -0x398(%rbp), %rdi
callq 0x3180
jmp 0x6d93
movq -0x3a0(%rbp), %rdi
addq $0x10, %rdi
callq 0x3080
jmp 0x6f07
leaq -0x210(%rbp), %rdi
callq 0x3130
leaq -0x1e8(%rbp), %rdi
callq 0x3130
leaq -0x30(%rbp), %rdi
callq 0x3130
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
leaq -0x210(%rbp), %rdi
callq 0x3130
leaq -0x1e8(%rbp), %rdi
callq 0x3130
leaq -0x30(%rbp), %rdi
callq 0x3130
movq -0x38(%rbp), %rdi
callq 0x3390
nopl (%rax,%rax)