// File: zhengwangsun[P]pas2c/semantics.cpp
// Function: factor1(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int factor1(int k, string idValue)
{
	TreeNode tNode= tree.node[k];
	TreeNode childNode;
	childNode=tree.node[tNode.child[0]];
    if(lookahead(k) == 102)//102是(
    {
        int flag = 0;
    	code[currentLine].append("(");
        int temp = expression_list(tree.node[k].child[1],3," ");
        code[currentLine].append(")");
        
        for(vector<subTableItem>::iterator it = subTable.begin(); it != subTable.end();it++)
        {
            if (it->name == idValue)
            {
                if (procArgument.size() != it->argument.size())
                {
                    cout<<"argument num wrong where factor1!"<<endl;
                    exit(1);
                }
                else
                {
                    int i = 0;//计数作用
                    for(vector<Tuple>::iterator it1 = it->argument.begin(); it1 != it->argument.end();it1++)
                    {
                        if (it1->type != procArgument[i])
                        {
                            cout<<"the no."<<i+1<<" argument type wrong where factor1!"<<endl;
                            exit(1);
                        }
                        i++;
                    }
                    procArgument.clear();//每用一次procA，就清空一次
                    flag = 1;
                }
            }
            if (flag == 0)
            {
                cout<<"this func/proc is not defined where factor'!"<<endl;
                exit(1);
            }
            
        }
        if (temp != -1)//expr_list里面正确
        {
            return 10;//10代表factor’推出了( expr_list )
        }
        else
        {
            cout<<"( expr_list ) type wrong where factor'!"<<endl;
            return -1;
        }
        return temp;
    }
    else if (lookahead(k) == 110)//110是[
    {
    	code[currentLine].append("[");
        int temp = expression(tree.node[k].child[1],1);
    	code[currentLine].append("]");
        if (temp == 1)
        {
            return 11;//11代表factor’推出了[expression]
        }
        else
        {
            cout<<"[expression] type wrong where factor'!"<<endl;
            return -1;
        }
        return temp;
    }
    else if (lookahead(k) == 106)//106是e
    {
        return 0;
    }
    else
    {
        cout<<"factor' error!"<<endl;
        return -1;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rsi, -0x1f8(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb2c3d(%rip), %rax     # 0xc6138
movq %rax, -0x1f0(%rbp)
leaq 0x8(%rax,%rcx), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x14920
leaq -0x160(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x149d0
movq -0x1f0(%rbp), %rax
movq -0x1e8(%rbp), %rdi
movslq -0xb4(%rbp), %rcx
imulq $0xa8, %rcx, %rcx
leaq 0x8(%rax,%rcx), %rsi
callq 0x14a10
jmp 0x1354e
movl -0x8(%rbp), %edi
callq 0xca50
movl %eax, -0x1fc(%rbp)
jmp 0x1355e
movl -0x1fc(%rbp), %eax
cmpl $0x66, %eax
jne 0x1399c
movl $0x0, -0x170(%rbp)
movslq 0xad0a2(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xac417(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xbba3(%rip), %rsi      # 0x1f136
callq 0x3490
jmp 0x1359a
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb2b8c(%rip), %rax     # 0xc6138
movl 0x10(%rax,%rcx), %eax
movl %eax, -0x20c(%rbp)
leaq -0x199(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x3460
movq -0x208(%rbp), %rdx
leaq 0xaf24(%rip), %rsi      # 0x1e4fb
leaq -0x198(%rbp), %rdi
callq 0x8750
jmp 0x135e5
movl -0x20c(%rbp), %edi
movl $0x3, %esi
leaq -0x198(%rbp), %rdx
callq 0x112f0
movl %eax, -0x210(%rbp)
jmp 0x13604
leaq -0x198(%rbp), %rdi
callq 0x34c8
leaq -0x199(%rbp), %rdi
callq 0x32d0
movl -0x210(%rbp), %eax
movl %eax, -0x174(%rbp)
movslq 0xacff1(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xac366(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xbcb8(%rip), %rsi      # 0x1f2fc
callq 0x3490
jmp 0x1364b
leaq 0xac2f6(%rip), %rdi     # 0xbf948
callq 0x14b00
movq %rax, -0x1a8(%rbp)
leaq 0xac2e3(%rip), %rdi     # 0xbf948
callq 0x14b70
movq %rax, -0x1b0(%rbp)
leaq -0x1a8(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x14b30
testb $0x1, %al
jne 0x1368d
jmp 0x13936
leaq -0x1a8(%rbp), %rdi
callq 0x14ba0
movq -0x1f8(%rbp), %rsi
movq %rax, %rdi
addq $0x30, %rdi
callq 0xc840
testb $0x1, %al
jne 0x136b5
jmp 0x138d6
leaq 0xac2a4(%rip), %rdi     # 0xbf960
callq 0x14c00
movq %rax, -0x218(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x14ba0
movq %rax, %rdi
addq $0x18, %rdi
callq 0x14c20
movq %rax, %rcx
movq -0x218(%rbp), %rax
cmpq %rcx, %rax
je 0x13788
movq 0x128ce(%rip), %rdi     # 0x25fc8
leaq 0xb4b3(%rip), %rsi      # 0x1ebb4
callq 0x3280
movq %rax, -0x220(%rbp)
jmp 0x1370f
movq -0x220(%rbp), %rdi
movq 0x12893(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x13724
movl $0x1, %edi
callq 0x3340
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x168(%rbp)
movl %eax, -0x16c(%rbp)
jmp 0x13b2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x168(%rbp)
movl %eax, -0x16c(%rbp)
jmp 0x13777
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x168(%rbp)
movl %eax, -0x16c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x34c8
leaq -0x199(%rbp), %rdi
callq 0x32d0
jmp 0x13b2c
movl $0x0, -0x1b4(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x14ba0
movq %rax, %rdi
addq $0x18, %rdi
callq 0x14c50
movq %rax, -0x1c0(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x14ba0
movq %rax, %rdi
addq $0x18, %rdi
callq 0x14cc0
movq %rax, -0x1c8(%rbp)
leaq -0x1c0(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x14c80
testb $0x1, %al
jne 0x137ec
jmp 0x138be
leaq -0x1c0(%rbp), %rdi
callq 0x14cf0
movl 0x20(%rax), %eax
movl %eax, -0x224(%rbp)
movslq -0x1b4(%rbp), %rsi
leaq 0xac151(%rip), %rdi     # 0xbf960
callq 0x14d10
movq %rax, %rcx
movl -0x224(%rbp), %eax
cmpl (%rcx), %eax
je 0x13895
movq 0x127a0(%rip), %rdi     # 0x25fc8
leaq 0xb3a7(%rip), %rsi      # 0x1ebd6
callq 0x3280
movq %rax, -0x230(%rbp)
jmp 0x1383d
movq -0x230(%rbp), %rdi
movl -0x1b4(%rbp), %esi
incl %esi
callq 0x3440
movq %rax, -0x238(%rbp)
jmp 0x1385a
movq -0x238(%rbp), %rdi
leaq 0xb376(%rip), %rsi      # 0x1ebde
callq 0x3280
movq %rax, -0x240(%rbp)
jmp 0x13876
movq -0x240(%rbp), %rdi
movq 0x1272c(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x1388b
movl $0x1, %edi
callq 0x3340
movl -0x1b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1b4(%rbp)
leaq -0x1c0(%rbp), %rdi
xorl %esi, %esi
callq 0x14d30
movq %rax, -0x1d0(%rbp)
jmp 0x137b1
leaq 0xac09b(%rip), %rdi     # 0xbf960
callq 0x14d70
movl $0x1, -0x170(%rbp)
jmp 0x138d6
cmpl $0x0, -0x170(%rbp)
jne 0x1391a
movq 0x126e2(%rip), %rdi     # 0x25fc8
leaq 0xb315(%rip), %rsi      # 0x1ec02
callq 0x3280
movq %rax, -0x248(%rbp)
jmp 0x138fb
movq -0x248(%rbp), %rdi
movq 0x126a7(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x13910
movl $0x1, %edi
callq 0x3340
jmp 0x1391c
leaq -0x1a8(%rbp), %rdi
xorl %esi, %esi
callq 0x14bc0
movq %rax, -0x1d8(%rbp)
jmp 0x1365e
cmpl $-0x1, -0x174(%rbp)
je 0x13955
movl $0xa, -0x4(%rbp)
movl $0x1, -0x1dc(%rbp)
jmp 0x13b08
movq 0x1266c(%rip), %rdi     # 0x25fc8
leaq 0xb2cc(%rip), %rsi      # 0x1ec2f
callq 0x3280
movq %rax, -0x250(%rbp)
jmp 0x13971
movq -0x250(%rbp), %rdi
movq 0x12631(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x13986
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x1dc(%rbp)
jmp 0x13b08
movl -0x8(%rbp), %edi
callq 0xca50
movl %eax, -0x254(%rbp)
jmp 0x139ac
movl -0x254(%rbp), %eax
cmpl $0x6e, %eax
jne 0x13a98
movslq 0xacc5e(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xabfd3(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xa875(%rip), %rsi      # 0x1e24c
callq 0x3490
jmp 0x139de
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb2748(%rip), %rax     # 0xc6138
movl 0x10(%rax,%rcx), %edi
movl $0x1, %esi
callq 0x11130
movl %eax, -0x258(%rbp)
jmp 0x13a06
movl -0x258(%rbp), %eax
movl %eax, -0x1e0(%rbp)
movslq 0xacc07(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xabf7c(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xa820(%rip), %rsi      # 0x1e24e
callq 0x3490
jmp 0x13a35
cmpl $0x1, -0x1e0(%rbp)
jne 0x13a54
movl $0xb, -0x4(%rbp)
movl $0x1, -0x1dc(%rbp)
jmp 0x13b08
movq 0x1256d(%rip), %rdi     # 0x25fc8
leaq 0xb1f5(%rip), %rsi      # 0x1ec57
callq 0x3280
movq %rax, -0x260(%rbp)
jmp 0x13a70
movq -0x260(%rbp), %rdi
movq 0x12532(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x13a85
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x1dc(%rbp)
jmp 0x13b08
movl -0x8(%rbp), %edi
callq 0xca50
movl %eax, -0x264(%rbp)
jmp 0x13aa8
movl -0x264(%rbp), %eax
cmpl $0x6a, %eax
jne 0x13ac6
movl $0x0, -0x4(%rbp)
movl $0x1, -0x1dc(%rbp)
jmp 0x13b08
movq 0x124fb(%rip), %rdi     # 0x25fc8
leaq 0xb1aa(%rip), %rsi      # 0x1ec7e
callq 0x3280
movq %rax, -0x270(%rbp)
jmp 0x13ae2
movq -0x270(%rbp), %rdi
movq 0x124c0(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0x13af7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x1dc(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x14a90
leaq -0xb8(%rbp), %rdi
callq 0x14a90
movl -0x4(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0x160(%rbp), %rdi
callq 0x14a90
leaq -0xb8(%rbp), %rdi
callq 0x14a90
movq -0x168(%rbp), %rdi
callq 0x3450