// File: /workspace/github_c_makefile_star2_O3/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:
movl $0x0, 0x25027(%rip)     # 0x2f700
movl $0x8, %eax
leaq 0xcc9b(%rip), %rcx      # 0x17380
movl $0xffffffff, -0x8(%rax,%rcx) # imm = 0xFFFFFFFF
movq $0x0, (%rax,%rcx)
addq $0x10, %rax
cmpq $0xc88, %rax            # imm = 0xC88
jne 0xa6e5
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
leaq 0x6e63(%rip), %rsi      # 0x1157f
leaq -0x250(%rbp), %rbx
movl $0x47, %edx
movq %rbx, %rdi
callq 0x1110
movq %rbx, %rdi
callq 0x10a0
incl %eax
leal -0x2(%rax), %ecx
movslq %ecx, %rcx
decl %eax
cmpb $0x2f, -0x250(%rbp,%rcx)
jne 0xa73a
cltq
movb $0x0, -0x250(%rbp,%rax)
leaq -0x250(%rbp), %rbx
movq %rbx, %rdi
callq 0x10a0
movabsq $0x2e72616d6d617267, %rcx # imm = 0x2E72616D6D617267
movq %rcx, -0x250(%rbp,%rax)
movl $0x747874, -0x248(%rbp,%rax) # imm = 0x747874
leaq 0x6c6c(%rip), %rsi      # 0x113f5
movq %rbx, %rdi
callq 0x1130
movq %rax, %rbx
leaq 0x6e37(%rip), %rsi      # 0x115d2
leaq -0x50(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x1060
cmpl $-0x1, %eax
je 0xa8b4
leaq 0x6e19(%rip), %r13      # 0x115d2
leaq -0x50(%rbp), %r15
xorl %r14d, %r14d
cmpl $-0x1, %r14d
je 0xa876
movq %r15, %rdi
cmpl $0x1, %r14d
je 0xa804
testl %r14d, %r14d
jne 0xa84a
callq 0x882a
movslq 0x24f1c(%rip), %rdi     # 0x2f700
movq %rdi, %rcx
shlq $0x4, %rcx
leaq 0x24f1e(%rip), %rdx     # 0x2f710
movl %eax, (%rcx,%rdx)
movl %eax, %esi
callq 0x87dc
movl $0x1, %r14d
jmp 0xa876
callq 0x882a
movl %eax, %r13d
movl $0x10, %edi
callq 0x1120
movq %rax, %r12
movl %r13d, (%rax)
leaq 0x6daf(%rip), %r13      # 0x115d2
movq $0x0, 0x8(%rax)
movslq 0x24ece(%rip), %rax     # 0x2f700
shlq $0x4, %rax
leaq 0x24ed3(%rip), %rcx     # 0x2f710
movq %r12, 0x8(%rax,%rcx)
movl $0x2, %r14d
jmp 0xa876
callq 0x882a
movl %eax, %r13d
movl $0x10, %edi
callq 0x1120
movl %r13d, (%rax)
leaq 0x6d6c(%rip), %r13      # 0x115d2
movq $0x0, 0x8(%rax)
movq %rax, 0x8(%r12)
movq %rax, %r12
movq %rbx, %rdi
callq 0x10d0
cmpb $0xd, %al
je 0xa895
movzbl %al, %eax
cmpl $0xa, %eax
jne 0xa89b
incl 0x24e70(%rip)           # 0x2f700
xorl %r14d, %r14d
jmp 0xa89b
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1060
cmpl $-0x1, %eax
jne 0xa7c0
incl 0x24e46(%rip)           # 0x2f700
movq %rbx, %rdi
callq 0x1090
leaq 0x26107(%rip), %rbx     # 0x309d0
xorl %r14d, %r14d
cmpq $0x36, %r14
jb 0xa8e9
movl $0x10, %edi
callq 0x1120
movl %r14d, (%rax)
movq $0x0, 0x8(%rax)
jmp 0xa8eb
xorl %eax, %eax
movq %rax, (%rbx)
incq %r14
addq $0x8, %rbx
cmpq $0x73, %r14
jne 0xa8cc
leaq 0x260ce(%rip), %r14     # 0x309d0
xorl %ebx, %ebx
cmpq $0x35, %rbx
ja 0xa917
cmpq $0x0, (%r14)
jne 0xa917
movl %ebx, %edi
callq 0xa311
incq %rbx
addq $0x8, %r14
cmpq $0x73, %rbx
jne 0xa904
movl $0x10, %edi
callq 0x1120
movl $0x70, (%rax)
movq $0x0, 0x8(%rax)
movq %rax, 0x25a4d(%rip)     # 0x30390
leaq 0x25a4e(%rip), %rdi     # 0x30398
movl $0x1a8, %edx            # imm = 0x1A8
xorl %esi, %esi
callq 0x10c0
movl $0x1, %ebx
movl %ebx, %edi
callq 0xa40b
incl %ebx
cmpl $0x36, %ebx
jne 0xa95b
callq 0xa0a7
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq