// File: kiven-li[P]xbytes/xbytes.cpp
// Function: xbytes::xbytes::make_parser(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void xbytes::make_parser(const string& file_name)
{
	int start_time = time(NULL);

	//open file
	std::ifstream ifs;
	ifs.open(file_name.c_str(), std::ifstream::in);

	//read file
	char cc;
	while(ifs.good())
	{
		ifs.get(cc);
		lexical_rule(cc);
	}
	
	//close file
	ifs.close();

	//check program file is complete
	if(bracket_count)
	{
		error_on_line(line, "expect }", char_index_in_line);
	}
	if(start == NULL)
	{
		std::cout << "ERROR: not found start symbol [program] ." << std::endl;
		exit(1);
	}
	if(token_code.size() == 0)
	{
		std::cout << "ERROR: not found token declare ." << std::endl;
		exit(1);		
	}

	//parse rule 
	sort_symbol();
	std::cout << "set precedence & associativity" << std::endl;
	find_symbol_precedence();
	find_rule_precedence();
	std::cout << "find_nullable" << std::endl;
	find_nullable();
	std::cout << "find_first_set" << std::endl;
	find_first_set();
	std::cout << "find_follow_set" << std::endl;
	find_follow_set();
	std::cout << "find_lr_state" << std::endl;
	find_lr_state();
	std::cout << "make_action_table" << std::endl;
	make_action_table();

	//dump
	//dump();

	//emit code
	emit_hxx_file();
	emit_cxx_file();

	emit_action_table();

	int eslape = time(NULL) - start_time;
	std::cout << "CONSULE:" << eslape << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x268(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x32b0
movl %eax, -0x14(%rbp)
leaq -0x220(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x3370
movq -0x10(%rbp), %rdi
callq 0x3120
movq -0x260(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0x31c0
jmp 0x42ec
jmp 0x42ee
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x34a0
movb %al, -0x269(%rbp)
jmp 0x430e
movb -0x269(%rbp), %al
testb $0x1, %al
jne 0x431a
jmp 0x435d
leaq -0x220(%rbp), %rdi
leaq -0x22d(%rbp), %rsi
callq 0x3400
jmp 0x432f
movq -0x268(%rbp), %rdi
movsbl -0x22d(%rbp), %esi
callq 0x4730
jmp 0x4344
jmp 0x42ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x470f
leaq -0x220(%rbp), %rdi
callq 0x3090
jmp 0x436b
movq -0x268(%rbp), %rax
cmpl $0x0, 0x610(%rax)
je 0x4441
movq -0x268(%rbp), %rax
addq $0x208, %rax            # imm = 0x208
movq %rax, -0x280(%rbp)
leaq -0x251(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x34f0
movq -0x278(%rbp), %rdx
leaq 0x14d0c(%rip), %rsi     # 0x190c0
leaq -0x250(%rbp), %rdi
callq 0x3830
jmp 0x43c2
movq -0x280(%rbp), %rsi
movq -0x268(%rbp), %rdi
movl 0x608(%rdi), %ecx
leaq -0x250(%rbp), %rdx
callq 0x5ae0
jmp 0x43e4
leaq -0x250(%rbp), %rdi
callq 0x31b0
leaq -0x251(%rbp), %rdi
callq 0x3340
jmp 0x4441
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x4430
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x31b0
leaq -0x251(%rbp), %rdi
callq 0x3340
jmp 0x470f
movq -0x268(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x4489
movq 0x1fb83(%rip), %rdi     # 0x23fd8
leaq 0x14c6d(%rip), %rsi     # 0x190c9
callq 0x32e0
movq %rax, -0x288(%rbp)
jmp 0x446a
movq -0x288(%rbp), %rdi
movq 0x1fb50(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x447f
movl $0x1, %edi
callq 0x33a0
movq -0x268(%rbp), %rdi
addq $0x70, %rdi
callq 0x3200
cmpq $0x0, %rax
jne 0x44da
movq 0x1fb32(%rip), %rdi     # 0x23fd8
leaq 0x14c46(%rip), %rsi     # 0x190f3
callq 0x32e0
movq %rax, -0x290(%rbp)
jmp 0x44bb
movq -0x290(%rbp), %rdi
movq 0x1faff(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x44d0
movl $0x1, %edi
callq 0x33a0
movq -0x268(%rbp), %rdi
callq 0x5c30
jmp 0x44e8
movq 0x1fae9(%rip), %rdi     # 0x23fd8
leaq 0x14c1e(%rip), %rsi     # 0x19114
callq 0x32e0
movq %rax, -0x298(%rbp)
jmp 0x4504
movq -0x298(%rbp), %rdi
movq 0x1fab6(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x4519
movq -0x268(%rbp), %rdi
callq 0x5e40
jmp 0x4527
movq -0x268(%rbp), %rdi
callq 0x5f40
jmp 0x4535
movq 0x1fa9c(%rip), %rdi     # 0x23fd8
leaq 0x14bf0(%rip), %rsi     # 0x19133
callq 0x32e0
movq %rax, -0x2a0(%rbp)
jmp 0x4551
movq -0x2a0(%rbp), %rdi
movq 0x1fa69(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x4566
movq -0x268(%rbp), %rdi
callq 0x6060
jmp 0x4574
movq 0x1fa5d(%rip), %rdi     # 0x23fd8
leaq 0x14bbf(%rip), %rsi     # 0x19141
callq 0x32e0
movq %rax, -0x2a8(%rbp)
jmp 0x4590
movq -0x2a8(%rbp), %rdi
movq 0x1fa2a(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x45a5
movq -0x268(%rbp), %rdi
callq 0x61e0
jmp 0x45b3
movq 0x1fa1e(%rip), %rdi     # 0x23fd8
leaq 0x14b8f(%rip), %rsi     # 0x19150
callq 0x32e0
movq %rax, -0x2b0(%rbp)
jmp 0x45cf
movq -0x2b0(%rbp), %rdi
movq 0x1f9eb(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x45e4
movq -0x268(%rbp), %rdi
callq 0x63e0
jmp 0x45f2
movq 0x1f9df(%rip), %rdi     # 0x23fd8
leaq 0x14b60(%rip), %rsi     # 0x19160
callq 0x32e0
movq %rax, -0x2b8(%rbp)
jmp 0x460e
movq -0x2b8(%rbp), %rdi
movq 0x1f9ac(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x4623
movq -0x268(%rbp), %rdi
callq 0x6710
jmp 0x4631
movq 0x1f9a0(%rip), %rdi     # 0x23fd8
leaq 0x14b2f(%rip), %rsi     # 0x1916e
callq 0x32e0
movq %rax, -0x2c0(%rbp)
jmp 0x464d
movq -0x2c0(%rbp), %rdi
movq 0x1f96d(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x4662
movq -0x268(%rbp), %rdi
callq 0x6990
jmp 0x4670
movq -0x268(%rbp), %rdi
callq 0x70e0
jmp 0x467e
movq -0x268(%rbp), %rdi
callq 0x75c0
jmp 0x468c
movq -0x268(%rbp), %rdi
callq 0x7a80
jmp 0x469a
xorl %eax, %eax
movl %eax, %edi
callq 0x32b0
movl -0x14(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x258(%rbp)
movq 0x1f923(%rip), %rdi     # 0x23fd8
leaq 0x14ac4(%rip), %rsi     # 0x19180
callq 0x32e0
movq %rax, -0x2c8(%rbp)
jmp 0x46ca
movq -0x2c8(%rbp), %rdi
movl -0x258(%rbp), %esi
callq 0x34d0
movq %rax, -0x2d0(%rbp)
jmp 0x46e5
movq -0x2d0(%rbp), %rdi
movq 0x1f8d5(%rip), %rsi     # 0x23fc8
callq 0x3320
jmp 0x46fa
leaq -0x220(%rbp), %rdi
callq 0x30b0
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
leaq -0x220(%rbp), %rdi
callq 0x30b0
movq -0x228(%rbp), %rdi
callq 0x34e0
nopw (%rax,%rax)