// File: /workspace/github_c_makefile_star2_O0/anuwu[P]ERPLAG-Compiler/parser.c
// Function: init_parser
void init_parser()
{
	rule_count =0;

	for(int i=0;i<SIZE;i++)
	{
		heads[i].ind=-1;
		heads[i].next=NULL;
	}

 
	// file handling

	int slash = 0 ;
	char grammarPath[500] ;
	strcpy (grammarPath, __FILE__) ;

	slash = strlen (grammarPath) - 1 ;

	#ifdef _WIN64
	while (grammarPath[slash] != '\\')
	#endif
	#if defined __linux__ || defined __MACH__	
	while (grammarPath[slash] != '/')
	#endif
		slash-- ;

	grammarPath[slash+1] = '\0' ;
	strcat (grammarPath, "grammar.txt") ;
	FILE* file_pointer=fopen(grammarPath, "r");
	
	int st=0; // 3 states 0-LHS 1-RHS_head 2-rests
	char tempstr[TNTLENGTH];
	node* tmp;
	
	while( fscanf(file_pointer,"%[^\n\r ])",tempstr) != EOF)
	{
		if(st==0){
			rule[rule_count].LHS = grammarStringToTokenID(tempstr);
			populate_hash(rule_count,grammarStringToTokenID(tempstr));
			st++;
		}
		else if(st==1){
			rule[rule_count].RHS = initnode(grammarStringToTokenID(tempstr));
			tmp = rule[rule_count].RHS;
			st++;
		}
		else if(st!=-1){
			tmp->next = initnode(grammarStringToTokenID(tempstr));
			tmp = tmp->next;
		}
 
		char ch;
		ch=fgetc(file_pointer);
		if(ch=='\r') st=-1;
		else if(ch=='\n'){
			rule_count++;
			st=0;
		}
	}
	rule_count++;
	fclose(file_pointer);

 
 	int id ;
	for (id = program ; id <= TK_RNUM ; id++)
	{
		if(isTerminal(id))
			firsts[id] = initnode (id) ;	
		else 
			firsts[id] = NULL;
	}



	for (id = program ; id <= TK_RNUM ; id++)
	{
		if(isNonTerminal(id) && firsts[id] == NULL)
			populateFirst((tokenID)id);	
	}
	
	
	follows[program] = initnode (TK_EOF) ;
	for (id = program + 1 ; id <= idL ; id++)
		follows[id] = NULL ;


	for (id = program + 1 ; id <= idL ; id++)
	{
		if (isNonTerminal(id))
			populateFollow ((tokenID)id) ;
	}

	traverse_grammar() ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movl $0x0, 0x2640b(%rip)     # 0x356e0
movl $0x0, -0x4(%rbp)
cmpl $0xc8, -0x4(%rbp)
jge 0xf322
movslq -0x4(%rbp), %rcx
leaq 0xe070(%rip), %rax      # 0x1d360
shlq $0x4, %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movslq -0x4(%rbp), %rcx
leaq 0xe058(%rip), %rax      # 0x1d360
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xf2dc
movl $0x0, -0x8(%rbp)
leaq -0x200(%rbp), %rdi
leaq 0x8352(%rip), %rsi      # 0x17689
callq 0x1040
leaq -0x200(%rbp), %rdi
callq 0x1080
subq $0x1, %rax
movl %eax, -0x8(%rbp)
movslq -0x8(%rbp), %rax
movsbl -0x200(%rbp,%rax), %eax
cmpl $0x2f, %eax
je 0xf36b
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xf34f
movl -0x8(%rbp), %eax
addl $0x1, %eax
cltq
movb $0x0, -0x200(%rbp,%rax)
leaq -0x200(%rbp), %rdi
leaq 0x8347(%rip), %rsi      # 0x176d0
callq 0x1110
leaq -0x200(%rbp), %rdi
leaq 0x8151(%rip), %rsi      # 0x174ed
callq 0x10f0
movq %rax, -0x208(%rbp)
movl $0x0, -0x20c(%rbp)
movq -0x208(%rbp), %rdi
leaq -0x240(%rbp), %rdx
leaq 0x8315(%rip), %rsi      # 0x176dc
movb $0x0, %al
callq 0x1050
cmpl $-0x1, %eax
je 0xf53d
cmpl $0x0, -0x20c(%rbp)
jne 0xf43e
leaq -0x240(%rbp), %rdi
callq 0xd050
movl %eax, %ecx
movslq 0x262eb(%rip), %rdx     # 0x356e0
leaq 0x262f4(%rip), %rax     # 0x356f0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl 0x262d5(%rip), %eax     # 0x356e0
movl %eax, -0x254(%rbp)
leaq -0x240(%rbp), %rdi
callq 0xd050
movl -0x254(%rbp), %edi
movl %eax, %esi
callq 0xcfa0
movl -0x20c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20c(%rbp)
jmp 0xf4e7
cmpl $0x1, -0x20c(%rbp)
jne 0xf4a7
leaq -0x240(%rbp), %rdi
callq 0xd050
movl %eax, %edi
callq 0xdfe0
movq %rax, %rcx
movslq 0x2627c(%rip), %rdx     # 0x356e0
leaq 0x26285(%rip), %rax     # 0x356f0
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movslq 0x26263(%rip), %rcx     # 0x356e0
leaq 0x2626c(%rip), %rax     # 0x356f0
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x248(%rbp)
movl -0x20c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20c(%rbp)
jmp 0xf4e5
cmpl $-0x1, -0x20c(%rbp)
je 0xf4e3
leaq -0x240(%rbp), %rdi
callq 0xd050
movl %eax, %edi
callq 0xdfe0
movq %rax, %rcx
movq -0x248(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x248(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x248(%rbp)
jmp 0xf4e5
jmp 0xf4e7
movq -0x208(%rbp), %rdi
callq 0x10b0
movb %al, -0x249(%rbp)
movsbl -0x249(%rbp), %eax
cmpl $0xd, %eax
jne 0xf511
movl $0xffffffff, -0x20c(%rbp) # imm = 0xFFFFFFFF
jmp 0xf538
movsbl -0x249(%rbp), %eax
cmpl $0xa, %eax
jne 0xf536
movl 0x261bd(%rip), %eax     # 0x356e0
addl $0x1, %eax
movl %eax, 0x261b4(%rip)     # 0x356e0
movl $0x0, -0x20c(%rbp)
jmp 0xf538
jmp 0xf3b2
movl 0x2619d(%rip), %eax     # 0x356e0
addl $0x1, %eax
movl %eax, 0x26194(%rip)     # 0x356e0
movq -0x208(%rbp), %rdi
callq 0x1070
movl $0x0, -0x250(%rbp)
cmpl $0x72, -0x250(%rbp)
jg 0xf5c8
cmpl $0x36, -0x250(%rbp)
jl 0xf59f
cmpl $0x72, -0x250(%rbp)
jg 0xf59f
movl -0x250(%rbp), %edi
callq 0xdfe0
movq %rax, %rdx
movslq -0x250(%rbp), %rcx
leaq 0x27417(%rip), %rax     # 0x369b0
movq %rdx, (%rax,%rcx,8)
jmp 0xf5b5
movslq -0x250(%rbp), %rcx
leaq 0x27403(%rip), %rax     # 0x369b0
movq $0x0, (%rax,%rcx,8)
jmp 0xf5b7
movl -0x250(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x250(%rbp)
jmp 0xf562
movl $0x0, -0x250(%rbp)
cmpl $0x72, -0x250(%rbp)
jg 0xf620
cmpl $0x0, -0x250(%rbp)
jl 0xf60d
cmpl $0x35, -0x250(%rbp)
jg 0xf60d
movslq -0x250(%rbp), %rcx
leaq 0x273b5(%rip), %rax     # 0x369b0
cmpq $0x0, (%rax,%rcx,8)
jne 0xf60d
movl -0x250(%rbp), %edi
callq 0xecf0
jmp 0xf60f
movl -0x250(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x250(%rbp)
jmp 0xf5d2
movl $0x70, %edi
callq 0xdfe0
movq %rax, 0x26d3f(%rip)     # 0x36370
movl $0x1, -0x250(%rbp)
cmpl $0x35, -0x250(%rbp)
jg 0xf66b
movslq -0x250(%rbp), %rcx
leaq 0x26d1e(%rip), %rax     # 0x36370
movq $0x0, (%rax,%rcx,8)
movl -0x250(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x250(%rbp)
jmp 0xf63b
movl $0x1, -0x250(%rbp)
cmpl $0x35, -0x250(%rbp)
jg 0xf6ae
cmpl $0x0, -0x250(%rbp)
jl 0xf69b
cmpl $0x35, -0x250(%rbp)
jg 0xf69b
movl -0x250(%rbp), %edi
callq 0xee70
jmp 0xf69d
movl -0x250(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x250(%rbp)
jmp 0xf675
callq 0xe8a0
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nopl (%rax)