// File: /workspace/github_c_makefile_star2_O1/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, 0x2557b(%rip)     # 0x30700
movl $0x8, %eax
leaq 0xd1ef(%rip), %rcx      # 0x18380
movl $0xffffffff, -0x8(%rax,%rcx) # imm = 0xFFFFFFFF
movq $0x0, (%rax,%rcx)
addq $0x10, %rax
cmpq $0xc88, %rax            # imm = 0xC88
jne 0xb191
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
leaq 0x71e3(%rip), %rsi      # 0x123ab
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 0xb1e6
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 0x6fec(%rip), %rsi      # 0x12221
movq %rbx, %rdi
callq 0x1130
movq %rax, %rbx
leaq 0x71b7(%rip), %rsi      # 0x123fe
leaq -0x50(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x1060
cmpl $-0x1, %eax
je 0xb360
leaq 0x7199(%rip), %r13      # 0x123fe
leaq -0x50(%rbp), %r15
xorl %r14d, %r14d
cmpl $-0x1, %r14d
je 0xb322
movq %r15, %rdi
cmpl $0x1, %r14d
je 0xb2b0
testl %r14d, %r14d
jne 0xb2f6
callq 0x92e4
movslq 0x25470(%rip), %rdi     # 0x30700
movq %rdi, %rcx
shlq $0x4, %rcx
leaq 0x25472(%rip), %rdx     # 0x30710
movl %eax, (%rcx,%rdx)
movl %eax, %esi
callq 0x9294
movl $0x1, %r14d
jmp 0xb322
callq 0x92e4
movl %eax, %r13d
movl $0x10, %edi
callq 0x1120
movq %rax, %r12
movl %r13d, (%rax)
leaq 0x712f(%rip), %r13      # 0x123fe
movq $0x0, 0x8(%rax)
movslq 0x25422(%rip), %rax     # 0x30700
shlq $0x4, %rax
leaq 0x25427(%rip), %rcx     # 0x30710
movq %r12, 0x8(%rax,%rcx)
movl $0x2, %r14d
jmp 0xb322
callq 0x92e4
movl %eax, %r13d
movl $0x10, %edi
callq 0x1120
movl %r13d, (%rax)
leaq 0x70ec(%rip), %r13      # 0x123fe
movq $0x0, 0x8(%rax)
movq %rax, 0x8(%r12)
movq %rax, %r12
movq %rbx, %rdi
callq 0x10d0
cmpb $0xd, %al
je 0xb341
movzbl %al, %eax
cmpl $0xa, %eax
jne 0xb347
incl 0x253c4(%rip)           # 0x30700
xorl %r14d, %r14d
jmp 0xb347
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1060
cmpl $-0x1, %eax
jne 0xb26c
incl 0x2539a(%rip)           # 0x30700
movq %rbx, %rdi
callq 0x1090
leaq 0x2665b(%rip), %rbx     # 0x319d0
xorl %r14d, %r14d
cmpq $0x36, %r14
jb 0xb395
movl $0x10, %edi
callq 0x1120
movl %r14d, (%rax)
movq $0x0, 0x8(%rax)
jmp 0xb397
xorl %eax, %eax
movq %rax, (%rbx)
incq %r14
addq $0x8, %rbx
cmpq $0x73, %r14
jne 0xb378
leaq 0x26622(%rip), %r14     # 0x319d0
xorl %ebx, %ebx
cmpq $0x35, %rbx
ja 0xb3c3
cmpq $0x0, (%r14)
jne 0xb3c3
movl %ebx, %edi
callq 0xadbe
incq %rbx
addq $0x8, %r14
cmpq $0x73, %rbx
jne 0xb3b0
movl $0x10, %edi
callq 0x1120
movl $0x70, (%rax)
movq $0x0, 0x8(%rax)
movq %rax, 0x25fa1(%rip)     # 0x31390
leaq 0x25fa2(%rip), %rdi     # 0x31398
movl $0x1a8, %edx            # imm = 0x1A8
xorl %esi, %esi
callq 0x10c0
movl $0x1, %ebx
movl %ebx, %edi
callq 0xaeb6
incl %ebx
cmpl $0x36, %ebx
jne 0xb407
callq 0xab26
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq