// File: zhengwangsun[P]pas2c/grammar.cpp
// Function: Analyze()
bool Analyze(void)                     //语法分析函数,返回分析结果
{
	int ip=1,X,a;
	int i,j,k,m,flag=1;
	AnalysisStack.push($);             //将$压栈 
	AnalysisStack.push(0);             //将文法开始符号Program压栈

	initTree(); 
	do{
		X=AnalysisStack.top();
		a=token[ip].type;
		
		if(X>=100||X==$)               //X是终结符或 $ 
		{
			if(X==a)                   //106: ε
			{
				AnalysisStack.pop();
				ip++;
			}
			else if(X==106)
				AnalysisStack.pop();
			else 
				return false;
		}
		else                           //X是非终结符
		{
			if(AnalysisTable[X][a-100]!=-1)
			{
				k=AnalysisTable[X][a-100];		
				AnalysisStack.pop();
				for(m=0;g[k].right[m+1]!=-1;m++)
					;
				for(int n=m;n>=0;n--)
					AnalysisStack.push(g[k].right[n]);
			
				// M[X,a]=X->Y1Y2.....Yk
				//构造树节点操作
			    int temp=DFS(0);//X节点的下标 
			    if(tree.node[temp].type==g[k].left) //搜索正确
			    {
			    	for(int i=0;g[k].right[i]!=-1;i++)
			    	{
			    		//1.对X节点：需要进行儿子节点的处理；
					    tree.node[temp].child[tree.node[temp].childNum++]=tree.size+1;
					    
					    //2.对Y1Y2......Yk需要新建节点
						tree.node[tree.size+1].type=g[k].right[i];
						if(g[k].right[i]>=100)
						{
							tree.node[tree.size+1].isT=true;
							if(g[k].right[i]!=106)
							{
							//	tree.node[tree.size+1].row=token[tokenCount].line;
							//	tree.node[tree.size+1].numType=tokenCount;  //测试 
							//    tokenCount++;
							}	
						}	 
						 	
						tree.node[tree.size+1].code=getVnVtString(g[k].right[i]);
				       // tree.node[tree.szie+1].value= 
				        //id单独处理 （把值和行数填入） 
						if(g[k].right[i]==101)
						{
							tree.node[tree.size+1].value=token[findTthId(idCount)].value;
							tree.node[tree.size+1].row=token[findTthId(idCount)].line;
							idCount++;
						}
						//num单独处理（把值、行数、类型填入）
						else if(g[k].right[i]==119) 
						{
							tree.node[tree.size+1].value=token[findTthNum(numCount)].value;
							tree.node[tree.size+1].row=token[findTthNum(numCount)].line;
							tree.node[tree.size+1].numType=token[findTthNum(numCount)].append;
							numCount++;
						}
						else if(g[k].right[i]==131 || g[k].right[i]==133)
						{
							tree.node[tree.size+1].value=token[findTthOp(opCount)].value;
							opCount++;
						}
						tree.size++;
			    	}
			    }
			}
			else
				return false;
		}
	}while(X!=$);
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x1, -0x8(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x8d, -0x28(%rbp)
leaq 0xac744(%rip), %rdi     # 0xc60e8
leaq -0x28(%rbp), %rsi
callq 0x1bf50
movl $0x0, -0x2c(%rbp)
leaq 0xac72d(%rip), %rdi     # 0xc60e8
leaq -0x2c(%rbp), %rsi
callq 0x1bf50
callq 0x19fa0
leaq 0xac718(%rip), %rdi     # 0xc60e8
callq 0x1bf80
movl (%rax), %eax
movl %eax, -0xc(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0xf5fb(%rip), %rax      # 0x28fe0
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x10(%rbp)
cmpl $0x64, -0xc(%rbp)
jge 0x19a00
cmpl $0x8d, -0xc(%rbp)
jne 0x19a43
movl -0xc(%rbp), %eax
cmpl -0x10(%rbp), %eax
jne 0x19a1f
leaq 0xac6d9(%rip), %rdi     # 0xc60e8
callq 0x1bfa0
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x19a3e
cmpl $0x6a, -0xc(%rbp)
jne 0x19a33
leaq 0xac6bc(%rip), %rdi     # 0xc60e8
callq 0x1bfa0
jmp 0x19a3c
movb $0x0, -0x1(%rbp)
jmp 0x19f93
jmp 0x19a3e
jmp 0x19f80
movslq -0xc(%rbp), %rcx
leaq 0xaad02(%rip), %rax     # 0xc4750
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl -0x10(%rbp), %ecx
subl $0x64, %ecx
movslq %ecx, %rcx
cmpl $-0x1, (%rax,%rcx,4)
je 0x19f78
movslq -0xc(%rbp), %rcx
leaq 0xaacda(%rip), %rax     # 0xc4750
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl -0x10(%rbp), %ecx
subl $0x64, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x1c(%rbp)
leaq 0xac652(%rip), %rdi     # 0xc60e8
callq 0x1bfa0
movl $0x0, -0x20(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0xa6e93(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $-0x1, 0x8(%rax,%rcx,4)
je 0x19ad4
jmp 0x19ac9
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x19aa2
movl -0x20(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jl 0x19b1b
movslq -0x1c(%rbp), %rax
leaq 0xa6e55(%rip), %rsi     # 0xc0940
imulq $0xd0, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movslq -0x30(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rsi
leaq 0xac5dd(%rip), %rdi     # 0xc60e8
callq 0x1bfc0
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x19ada
xorl %edi, %edi
callq 0x1a0e0
movl %eax, -0x34(%rbp)
movslq -0x34(%rbp), %rcx
leaq 0xac608(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x54(%rax), %eax
movslq -0x1c(%rbp), %rdx
leaq 0xa6df4(%rip), %rcx     # 0xc0940
imulq $0xd0, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
jne 0x19f76
movl $0x0, -0x38(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0xa6dcf(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
cmpl $-0x1, 0x8(%rax,%rcx,4)
je 0x19f74
movl 0xac5a8(%rip), %edx     # 0xc6138
addl $0x1, %edx
movslq -0x34(%rbp), %rcx
leaq 0xac59a(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movslq -0x34(%rbp), %rcx
leaq 0xac581(%rip), %rsi     # 0xc6138
addq $0x8, %rsi
imulq $0xa8, %rcx, %rcx
addq %rcx, %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movslq %ecx, %rcx
movl %edx, 0x4(%rax,%rcx,4)
movslq -0x1c(%rbp), %rcx
leaq 0xa6d60(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
movl 0x8(%rax,%rcx,4), %ecx
movl 0xac540(%rip), %eax     # 0xc6138
addl $0x1, %eax
movslq %eax, %rdx
leaq 0xac533(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x54(%rax)
movslq -0x1c(%rbp), %rcx
leaq 0xa6d1f(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
cmpl $0x64, 0x8(%rax,%rcx,4)
jl 0x19c7f
movl 0xac4fc(%rip), %eax     # 0xc6138
addl $0x1, %eax
movslq %eax, %rcx
leaq 0xac4ef(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movb $0x1, 0x58(%rax)
movslq -0x1c(%rbp), %rcx
leaq 0xa6cda(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
cmpl $0x6a, 0x8(%rax,%rcx,4)
je 0x19c7d
jmp 0x19c7d
jmp 0x19c7f
movslq -0x1c(%rbp), %rcx
leaq 0xa6cb6(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
movl 0x8(%rax,%rcx,4), %esi
leaq -0x58(%rbp), %rdi
callq 0x1a1c0
movl 0xac48d(%rip), %eax     # 0xc6138
addl $0x1, %eax
cltq
leaq 0xac481(%rip), %rdi     # 0xc6138
addq $0x8, %rdi
imulq $0xa8, %rax, %rax
addq %rax, %rdi
addq $0x60, %rdi
leaq -0x58(%rbp), %rsi
callq 0x3350
leaq -0x58(%rbp), %rdi
callq 0x34c8
movslq -0x1c(%rbp), %rcx
leaq 0xa6c5a(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
cmpl $0x65, 0x8(%rax,%rcx,4)
jne 0x19da4
movl 0x2466db(%rip), %edi    # 0x2603e0
callq 0x1a2e0
cltq
leaq 0xf2cd(%rip), %rsi      # 0x28fe0
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movl 0xac414(%rip), %eax     # 0xc6138
addl $0x1, %eax
cltq
leaq 0xac408(%rip), %rdi     # 0xc6138
addq $0x8, %rdi
imulq $0xa8, %rax, %rax
addq %rax, %rdi
addq $0x80, %rdi
callq 0x3030
movl 0x246690(%rip), %edi    # 0x2603e0
callq 0x1a2e0
movslq %eax, %rcx
leaq 0xf281(%rip), %rax      # 0x28fe0
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %ecx
movl 0xac3c9(%rip), %eax     # 0xc6138
addl $0x1, %eax
movslq %eax, %rdx
leaq 0xac3bc(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xa4(%rax)
movl 0x24664a(%rip), %eax    # 0x2603e0
addl $0x1, %eax
movl %eax, 0x246641(%rip)    # 0x2603e0
jmp 0x19f57
movslq -0x1c(%rbp), %rcx
leaq 0xa6b91(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
cmpl $0x77, 0x8(%rax,%rcx,4)
jne 0x19eb3
movl 0x246616(%rip), %edi    # 0x2603e4
callq 0x1a350
cltq
leaq 0xf204(%rip), %rsi      # 0x28fe0
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movl 0xac34b(%rip), %eax     # 0xc6138
addl $0x1, %eax
cltq
leaq 0xac33f(%rip), %rdi     # 0xc6138
addq $0x8, %rdi
imulq $0xa8, %rax, %rax
addq %rax, %rdi
addq $0x80, %rdi
callq 0x3030
movl 0x2465cb(%rip), %edi    # 0x2603e4
callq 0x1a350
movslq %eax, %rcx
leaq 0xf1b8(%rip), %rax      # 0x28fe0
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %ecx
movl 0xac300(%rip), %eax     # 0xc6138
addl $0x1, %eax
movslq %eax, %rdx
leaq 0xac2f3(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xa4(%rax)
movl 0x246585(%rip), %edi    # 0x2603e4
callq 0x1a350
movslq %eax, %rcx
leaq 0xf172(%rip), %rax      # 0x28fe0
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x30(%rax), %ecx
movl 0xac2ba(%rip), %eax     # 0xc6138
addl $0x1, %eax
movslq %eax, %rdx
leaq 0xac2ad(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xa0(%rax)
movl 0x24653f(%rip), %eax    # 0x2603e4
addl $0x1, %eax
movl %eax, 0x246536(%rip)    # 0x2603e4
jmp 0x19f55
movslq -0x1c(%rbp), %rcx
leaq 0xa6a82(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
cmpl $0x83, 0x8(%rax,%rcx,4)
je 0x19ef9
movslq -0x1c(%rbp), %rcx
leaq 0xa6a5f(%rip), %rax     # 0xc0940
imulq $0xd0, %rcx, %rcx
addq %rcx, %rax
movslq -0x38(%rbp), %rcx
cmpl $0x85, 0x8(%rax,%rcx,4)
jne 0x19f53
movl 0x2464e9(%rip), %edi    # 0x2603e8
callq 0x1a3c0
cltq
leaq 0xf0d3(%rip), %rsi      # 0x28fe0
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x8, %rsi
movl 0xac21a(%rip), %eax     # 0xc6138
addl $0x1, %eax
cltq
leaq 0xac20e(%rip), %rdi     # 0xc6138
addq $0x8, %rdi
imulq $0xa8, %rax, %rax
addq %rax, %rdi
addq $0x80, %rdi
callq 0x3030
movl 0x24649e(%rip), %eax    # 0x2603e8
addl $0x1, %eax
movl %eax, 0x246495(%rip)    # 0x2603e8
jmp 0x19f55
jmp 0x19f57
movl 0xac1db(%rip), %eax     # 0xc6138
addl $0x1, %eax
movl %eax, 0xac1d2(%rip)     # 0xc6138
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x19b66
jmp 0x19f76
jmp 0x19f7e
movb $0x0, -0x1(%rbp)
jmp 0x19f93
jmp 0x19f80
jmp 0x19f82
cmpl $0x8d, -0xc(%rbp)
jne 0x199c9
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nop