// File: Caproner[P]Naive_Compiler/Grammar/Grammar.cpp
// Function: Grammar::Handle_Analysis(int)
bool Grammar::Handle_Analysis(int pos)
{
	while(!(this->Status_Stack.empty()))
		this->Status_Stack.pop();
	while(!(this->Symbol_Stack.empty()))
	{
		TreeNode *p=this->Symbol_Stack.top();
		this->Symbol_Stack.pop();
		this->Delete(p);
	}
	
	Word_List &WL=this->Handle_List[pos];
	WL.List.push_back(Word(14,0));
	this->Status_Stack.push(0);
	
	int cur=0;
	
	bool ret=true;
	
	#ifdef TEST
	int Count=1;
	#endif
	
	while(true)
	{
		#ifdef TEST
		printf("%d: ",Count++);
		#endif
		if(cur==WL.List.size())
		{
			ret=false;
			break;
		}
		char &C=this->Number_to_Symbol[WL.List[cur].Number];
		int &S=this->Status_Stack.top();
		if(this->ACTION.find(std::make_pair(C,S))==this->ACTION.end())
		{
			ret=false;
			break;
		}
		int Status_Code=this->ACTION[std::make_pair(C,S)];
		#ifdef TEST
		printf("Find ACTION[%c,%d] = %d, ",C,S,Status_Code);
		#endif
		if(Status_Code==0)
		{
			#ifdef TEST
			printf("Accept!\n");
			#endif
			break;
		}
		else if(Status_Code>0)
		{
			#ifdef TEST
			printf("Push_Back %d\n",Status_Code);
			#endif
			this->Status_Stack.push(Status_Code);
			TreeNode *p=new TreeNode;
			p->Next.clear();
			p->Parent=NULL;
			p->Node_Word=WL.List[cur];
			this->Symbol_Stack.push(p);
			cur++;
		}
		else
		{
			Status_Code=-Status_Code;
			char U_Symbol=this->Grammars[Status_Code][0];
			#ifdef TEST
			printf("Reduce: %s, ",this->Grammars[Status_Code].c_str());
			#endif
			int len=this->Grammars[Status_Code].length();
			TreeNode *p=new TreeNode;
			p->Next.clear();
			p->Parent=NULL;
			p->Node_Word=Word(13,0);
			for(int i=0;i<len-2;i++)
			{
				if(this->Symbol_Stack.empty())
				{
					ret=false;
					break;
				}
				TreeNode *q=this->Symbol_Stack.top();
				this->Symbol_Stack.pop();
				p->Next.push_back(q);
				q->Parent=p;
				this->Status_Stack.pop();
			}
			if(!ret)break;
			std::reverse(p->Next.begin(),p->Next.end());
			if(this->GOTO.find(std::make_pair(U_Symbol,this->Status_Stack.top()))==this->GOTO.end())
			{
				ret=false;
				break;
			}
			#ifdef TEST
			printf("Push_Back GOTO[%c,%d]=%d\n",U_Symbol,this->Status_Stack.top(),this->GOTO[std::make_pair(U_Symbol,this->Status_Stack.top())]);
			#endif
			this->Status_Stack.push(this->GOTO[std::make_pair(U_Symbol,this->Status_Stack.top())]);
			this->Symbol_Stack.push(p);
		}
	}
	if(ret)
	{
		this->Grammar_Forest.forest.push_back(this->Symbol_Stack.top());
		this->Symbol_Stack.pop();
	}
	else
	{
		while(!(this->Symbol_Stack.empty()))
		{
			TreeNode *p=this->Symbol_Stack.top();
			this->Symbol_Stack.pop();
			this->Delete(p);
		}
	}
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
addq $0xa8, %rdi
callq 0x9a20
xorb $-0x1, %al
testb $0x1, %al
jne 0x8d78
jmp 0x8d8d
movq -0x100(%rbp), %rdi
addq $0xa8, %rdi
callq 0x9a40
jmp 0x8d5d
jmp 0x8d8f
movq -0x100(%rbp), %rdi
addq $0xf8, %rdi
callq 0x9a60
xorb $-0x1, %al
testb $0x1, %al
jne 0x8daa
jmp 0x8de9
movq -0x100(%rbp), %rdi
addq $0xf8, %rdi
callq 0x9a80
movq -0x100(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x18(%rbp)
addq $0xf8, %rdi
callq 0x9aa0
movq -0x100(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x8ca0
jmp 0x8d8f
movq -0x100(%rbp), %rdi
movslq -0xc(%rbp), %rsi
callq 0x9ac0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x30(%rbp), %rdi
movl $0xe, %esi
xorps %xmm0, %xmm0
callq 0x7450
movq -0x108(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x9ae0
movq -0x100(%rbp), %rdi
addq $0xa8, %rdi
movl $0x0, -0x34(%rbp)
leaq -0x34(%rbp), %rsi
callq 0x9b10
movl $0x0, -0x38(%rbp)
movb $0x1, -0x39(%rbp)
movslq -0x38(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x20(%rbp), %rdi
callq 0x52e0
movq %rax, %rcx
movq -0x110(%rbp), %rax
cmpq %rcx, %rax
jne 0x8e7e
movb $0x0, -0x39(%rbp)
jmp 0x9363
movq -0x100(%rbp), %rax
addq $0x148, %rax            # imm = 0x148
movq %rax, -0x120(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x9c20
movq -0x120(%rbp), %rdi
movq %rax, %rsi
callq 0x9b40
movq -0x100(%rbp), %rdi
movq %rax, -0x48(%rbp)
addq $0xa8, %rdi
callq 0x9c40
movq %rax, %rcx
movq -0x100(%rbp), %rax
movq %rcx, -0x50(%rbp)
addq $0x48, %rax
movq %rax, -0x118(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x9cc0
movq -0x118(%rbp), %rdi
movq %rax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x9c90
movq -0x100(%rbp), %rdi
movq %rax, -0x58(%rbp)
addq $0x48, %rdi
callq 0x9cf0
movq %rax, -0x68(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x9c60
testb $0x1, %al
jne 0x8f2a
jmp 0x8f33
movb $0x0, -0x39(%rbp)
jmp 0x9363
movq -0x100(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x128(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x9cc0
movq -0x128(%rbp), %rdi
movq %rax, -0x74(%rbp)
leaq -0x74(%rbp), %rsi
callq 0x9d20
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jne 0x8f76
jmp 0x9363
cmpl $0x0, -0x6c(%rbp)
jle 0x9048
movq -0x100(%rbp), %rdi
addq $0xa8, %rdi
leaq -0x6c(%rbp), %rsi
callq 0x9e00
movl $0x30, %edi
callq 0x2210
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x130(%rbp)
callq 0x9e30
jmp 0x8fb5
movq -0x130(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
addq $0x10, %rdi
callq 0x9e70
movq -0x80(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x20(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x9c20
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
addq $0xf8, %rdi
leaq -0x80(%rbp), %rsi
callq 0x9e90
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x935c
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
movl $0x30, %esi
callq 0x2220
jmp 0x9420
movq -0x100(%rbp), %rdi
movl -0x6c(%rbp), %eax
negl %eax
movl %eax, -0x6c(%rbp)
addq $0x30, %rdi
movq %rdi, -0x140(%rbp)
movslq -0x6c(%rbp), %rsi
callq 0x9ec0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x23b0
movq -0x140(%rbp), %rdi
movb (%rax), %al
movb %al, -0x8d(%rbp)
movslq -0x6c(%rbp), %rsi
callq 0x9ec0
movq %rax, %rdi
callq 0x22e0
movl %eax, -0x94(%rbp)
movl $0x30, %edi
callq 0x2210
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x138(%rbp)
callq 0x9e30
jmp 0x90bb
movq -0x138(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
addq $0x10, %rdi
callq 0x9e70
movq -0xa0(%rbp), %rax
movq $0x0, 0x28(%rax)
leaq -0xb0(%rbp), %rdi
movl $0xd, %esi
xorps %xmm0, %xmm0
callq 0x7450
movq -0xa0(%rbp), %rax
movq -0xb0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xa8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movl -0x94(%rbp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x9203
movq -0x100(%rbp), %rdi
addq $0xf8, %rdi
callq 0x9a60
testb $0x1, %al
jne 0x9152
jmp 0x9183
movb $0x0, -0x39(%rbp)
jmp 0x9203
movq -0x138(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
movl $0x30, %esi
callq 0x2220
jmp 0x9420
movq -0x100(%rbp), %rdi
addq $0xf8, %rdi
callq 0x9a80
movq -0x100(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
addq $0xf8, %rdi
callq 0x9aa0
movq -0xa0(%rbp), %rdi
addq $0x10, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x9ee0
movq -0x100(%rbp), %rdi
movq -0xa0(%rbp), %rcx
movq -0xc0(%rbp), %rax
movq %rcx, 0x28(%rax)
addq $0xa8, %rdi
callq 0x9a40
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x9122
testb $0x1, -0x39(%rbp)
jne 0x920e
jmp 0x9363
movq -0xa0(%rbp), %rdi
addq $0x10, %rdi
callq 0x9f90
movq %rax, -0xc8(%rbp)
movq -0xa0(%rbp), %rdi
addq $0x10, %rdi
callq 0x9fc0
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x9f50
movq -0x100(%rbp), %rdi
movq %rdi, %rax
addq $0x78, %rax
movq %rax, -0x148(%rbp)
addq $0xa8, %rdi
callq 0x9c40
movq %rax, %rsi
leaq -0x8d(%rbp), %rdi
callq 0x9cc0
movq -0x148(%rbp), %rdi
movq %rax, -0xe0(%rbp)
leaq -0xe0(%rbp), %rsi
callq 0x9c90
movq -0x100(%rbp), %rdi
movq %rax, -0xd8(%rbp)
addq $0x78, %rdi
callq 0x9cf0
movq %rax, -0xe8(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x9c60
testb $0x1, %al
jne 0x92d0
jmp 0x92d9
movb $0x0, -0x39(%rbp)
jmp 0x9363
movq -0x100(%rbp), %rdi
movq %rdi, %rax
addq $0xa8, %rax
movq %rax, -0x150(%rbp)
movq %rdi, %rax
addq $0x78, %rax
movq %rax, -0x158(%rbp)
addq $0xa8, %rdi
callq 0x9c40
movq %rax, %rsi
leaq -0x8d(%rbp), %rdi
callq 0x9cc0
movq -0x158(%rbp), %rdi
movq %rax, -0xf0(%rbp)
leaq -0xf0(%rbp), %rsi
callq 0x9d20
movq -0x150(%rbp), %rdi
movq %rax, %rsi
callq 0x9e00
movq -0x100(%rbp), %rdi
addq $0xf8, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x9e90
jmp 0x935e
jmp 0x8e52
testb $0x1, -0x39(%rbp)
je 0x93ae
movq -0x100(%rbp), %rdi
movq %rdi, %rax
addq $0x18, %rax
movq %rax, -0x160(%rbp)
addq $0xf8, %rdi
callq 0x9a80
movq -0x160(%rbp), %rdi
movq %rax, %rsi
callq 0x9ee0
movq -0x100(%rbp), %rdi
addq $0xf8, %rdi
callq 0x9aa0
jmp 0x9412
jmp 0x93b0
movq -0x100(%rbp), %rdi
addq $0xf8, %rdi
callq 0x9a60
xorb $-0x1, %al
testb $0x1, %al
jne 0x93cb
jmp 0x9410
movq -0x100(%rbp), %rdi
addq $0xf8, %rdi
callq 0x9a80
movq -0x100(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
addq $0xf8, %rdi
callq 0x9aa0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x8ca0
jmp 0x93b0
jmp 0x9412
movb -0x39(%rbp), %al
andb $0x1, %al
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x2350
nopl (%rax)