// File: zhengwangsun[P]pas2c/semantics.cpp
// Function: expression(int, int)
int expression(int k,int useFlag)
{
    if(lookahead(k) == 31)//31是simple_expr
    {
        int flag1 = simple_expression(tree.node[k].child[0]); //
        
        int flag2 = expression1(tree.node[k].child[1]);
        
        if (flag1 >= flag2)//类型转换，低转高
        { 
        	if(useFlag==2)
            {
        		code[currentLine].insert(0,"printf(\"%d\",");
        		code[currentLine++].append(");\n");
        	}
            if(flag2 == 0)
                return flag1;
            else
                return 3;
    	}
		else if (flag2 >= flag1)//
        {
        	if(useFlag==2){
        		code[currentLine].insert(0,"printf(\"%f\",");
        		code[currentLine++].append(");\n");
        	}
            if(flag1 == 0)
                return flag2;
            else
                return 3;
		}
        else
        {
            cout<<"type not match where expression"<<endl;
            return -1;
        }
    }
    else
    {
        cout<<"expression error!"<<endl;
        return -1;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl -0x8(%rbp), %edi
callq 0xca50
cmpl $0x1f, %eax
jne 0x112b6
movslq -0x8(%rbp), %rcx
leaq 0xb4fde(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %edi
callq 0x11dd0
movl %eax, -0x10(%rbp)
movslq -0x8(%rbp), %rcx
leaq 0xb4fba(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edi
callq 0x120f0
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0x11214
cmpl $0x2, -0xc(%rbp)
jne 0x111f7
movslq 0xaf474(%rip), %rax     # 0xc0620
leaq 0xae7ed(%rip), %rdi     # 0xbf9a0
shlq $0x5, %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0xd83b(%rip), %rdx      # 0x1ea00
callq 0x3070
movl 0xaf450(%rip), %eax     # 0xc0620
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0xaf445(%rip)     # 0xc0620
cltq
leaq 0xae7bc(%rip), %rdi     # 0xbf9a0
shlq $0x5, %rax
addq %rax, %rdi
leaq 0xd81b(%rip), %rsi      # 0x1ea0d
callq 0x3490
cmpl $0x0, -0x14(%rbp)
jne 0x11208
movl -0x10(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x112df
movl $0x3, -0x4(%rbp)
jmp 0x112df
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jl 0x1128b
cmpl $0x2, -0xc(%rbp)
jne 0x11274
movslq 0xaf3f7(%rip), %rax     # 0xc0620
leaq 0xae770(%rip), %rdi     # 0xbf9a0
shlq $0x5, %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0xd7cf(%rip), %rdx      # 0x1ea11
callq 0x3070
movl 0xaf3d3(%rip), %eax     # 0xc0620
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0xaf3c8(%rip)     # 0xc0620
cltq
leaq 0xae73f(%rip), %rdi     # 0xbf9a0
shlq $0x5, %rax
addq %rax, %rdi
leaq 0xd79e(%rip), %rsi      # 0x1ea0d
callq 0x3490
cmpl $0x0, -0x10(%rbp)
jne 0x11282
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x112df
movl $0x3, -0x4(%rbp)
jmp 0x112df
movq 0x14d36(%rip), %rdi     # 0x25fc8
leaq 0xd785(%rip), %rsi      # 0x1ea1e
callq 0x3280
movq %rax, %rdi
movq 0x14d08(%rip), %rsi     # 0x25fb0
callq 0x32b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x112df
movq 0x14d0b(%rip), %rdi     # 0x25fc8
leaq 0xd7fe(%rip), %rsi      # 0x1eac2
callq 0x3280
movq %rax, %rdi
movq 0x14cdd(%rip), %rsi     # 0x25fb0
callq 0x32b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)