// File: SeanLee97[P]LL1-Parser/grammar.cpp
// Function: Grammar::print_table()
void Grammar::print_table(){
    cout<<"+++++++++++++++++ parse table ++++++++++++++++++++++"<<endl<<endl;

	int n_idx, t_idx, rule_idx = 0;
	for(int i = 0; i < predict_sets.size(); i++) {
		n_idx = full_rules[i][0];
		rule_idx = i;

		if ( nonterminal_names[n_idx] == " "){
			continue;
		}
		// nonterminal
		cout<< nonterminal_names[n_idx]<<"\t\t";

		for(int j = 0; j < predict_sets[i].size(); j++) {

			t_idx = predict_sets[i][j];

			cout<< terminal_names[t_idx] << " | ";

			cout << nonterminal_names[n_idx] << " -> ";


			vector<int> pred_rule = right_hand_sides[rule_idx];

			int k = 0;
			while(pred_rule[k] != 0 && pred_rule[k] != 999) {
				++k;
			}

			for(k = k-1; k >= 0; k--) {
				if(pred_rule[k] < 0)
					cout << terminal_names[abs(pred_rule[k])] << " ";
				else
					cout << nonterminal_names[abs(pred_rule[k])] << " ";
			}
			cout<< " # ";
			k = 0; 
		}
		cout<<endl<<endl;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq 0x10e62(%rip), %rdi     # 0x18fd0
leaq 0x919e(%rip), %rsi      # 0x11313
callq 0x3200
movq %rax, %rdi
movq 0x10e3c(%rip), %rsi     # 0x18fc0
callq 0x3230
movq %rax, %rdi
movq 0x10e2d(%rip), %rsi     # 0x18fc0
callq 0x3230
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
addq $0x298, %rdi            # imm = 0x298
callq 0x8790
movq %rax, %rcx
movq -0x60(%rbp), %rax
cmpq %rcx, %rax
jae 0x84fb
movq -0x58(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x18(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x86c0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0xc(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
addq $0x250, %rdi            # imm = 0x250
movslq -0xc(%rbp), %rsi
callq 0x8db0
movq %rax, %rdi
leaq 0x913a(%rip), %rsi      # 0x11351
callq 0x9360
testb $0x1, %al
jne 0x8222
jmp 0x8227
jmp 0x84ed
movq -0x58(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
movslq -0xc(%rbp), %rsi
callq 0x8db0
movq %rax, %rsi
movq 0x10d8b(%rip), %rdi     # 0x18fd0
callq 0x31e0
movq %rax, %rdi
leaq 0x90f4(%rip), %rsi      # 0x11348
callq 0x3200
movl $0x0, -0x1c(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x1c(%rbp), %rax
movq %rax, -0x68(%rbp)
addq $0x298, %rdi            # imm = 0x298
movslq -0x18(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
callq 0x87c0
movq %rax, %rcx
movq -0x68(%rbp), %rax
cmpq %rcx, %rax
jae 0x84cb
movq -0x58(%rbp), %rdi
addq $0x298, %rdi            # imm = 0x298
movslq -0x18(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x86c0
movq -0x58(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x10(%rbp)
addq $0x238, %rdi            # imm = 0x238
movslq -0x10(%rbp), %rsi
callq 0x8db0
movq %rax, %rsi
movq 0x10cf9(%rip), %rdi     # 0x18fd0
callq 0x31e0
movq %rax, %rdi
leaq 0x9065(%rip), %rsi      # 0x1134b
callq 0x3200
movq -0x58(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
movslq -0xc(%rbp), %rsi
callq 0x8db0
movq %rax, %rsi
movq 0x10cc7(%rip), %rdi     # 0x18fd0
callq 0x31e0
movq %rax, %rdi
leaq 0x8fed(%rip), %rsi      # 0x11305
callq 0x3200
movq -0x58(%rbp), %rdi
addq $0x2e0, %rdi            # imm = 0x2E0
movslq -0x14(%rbp), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x87e0
movl $0x0, -0x3c(%rbp)
movslq -0x3c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x86c0
movq %rax, %rcx
xorl %eax, %eax
cmpl $0x0, (%rcx)
movb %al, -0x69(%rbp)
je 0x8377
movslq -0x3c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x86c0
cmpl $0x3e7, (%rax)          # imm = 0x3E7
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x8380
jmp 0x838b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x8344
movl -0x3c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x8498
movslq -0x3c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x86c0
cmpl $0x0, (%rax)
jge 0x8423
movq -0x58(%rbp), %rax
addq $0x238, %rax            # imm = 0x238
movq %rax, -0x80(%rbp)
movslq -0x3c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x86c0
movq -0x80(%rbp), %rdi
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movslq %eax, %rsi
callq 0x8db0
movq %rax, %rsi
movq 0x10be6(%rip), %rdi     # 0x18fd0
callq 0x31e0
movq %rax, -0x78(%rbp)
jmp 0x83f5
movq -0x78(%rbp), %rdi
leaq 0x8f51(%rip), %rsi      # 0x11351
callq 0x3200
jmp 0x8407
jmp 0x8488
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3900
jmp 0x8504
movq -0x58(%rbp), %rax
addq $0x250, %rax            # imm = 0x250
movq %rax, -0x90(%rbp)
movslq -0x3c(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x86c0
movq -0x90(%rbp), %rdi
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movslq %eax, %rsi
callq 0x8db0
movq %rax, %rsi
movq 0x10b6d(%rip), %rdi     # 0x18fd0
callq 0x31e0
movq %rax, -0x88(%rbp)
jmp 0x8471
movq -0x88(%rbp), %rdi
leaq 0x8ed2(%rip), %rsi      # 0x11351
callq 0x3200
jmp 0x8486
jmp 0x8488
jmp 0x848a
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x8394
movq 0x10b31(%rip), %rdi     # 0x18fd0
leaq 0x8ea9(%rip), %rsi      # 0x1134f
callq 0x3200
jmp 0x84ad
movl $0x0, -0x3c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3900
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x8260
movq 0x10afe(%rip), %rdi     # 0x18fd0
movq 0x10ae7(%rip), %rsi     # 0x18fc0
callq 0x3230
movq %rax, %rdi
movq 0x10ad8(%rip), %rsi     # 0x18fc0
callq 0x3230
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x81a6
addq $0x90, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3390
nopl (%rax)