// File: /workspace/github_cpp_makefile_star2_O1/KJTang[P]SimpleCompiler/Parser.cpp
// Function: Parser::parseExpression()
ASTNode *Parser::parseExpression() {
    #ifdef DEBUG
    std::cout<<curToken.second<<"\tparseExpression"<<std::endl;
    #endif
    std::stack<ASTNode*> numStack;
    std::stack<int> opStack;
    while (true) {
        switch (curToken.first) {
            case Token::NUMBER: {
                numStack.push(this->parseNumber());
                break;
            }
            case Token::IDENTIFIER: {
                numStack.push(this->parseIdentifier());
                break;
            }
            case static_cast<Token>('('): {
                numStack.push(this->parseParenExpr());
                break;
            }
            case static_cast<Token>(','): 
            case static_cast<Token>(';'): {
                // expression end
                getNextToken(); // eat ',' or ';'
            }
            case static_cast<Token>(')'): {
                // expression end
                while (!opStack.empty()) {
                    char op = opStack.top();
                    opStack.pop();
                    ASTNode *l, *r;
                    r = numStack.top();
                    numStack.pop();
                    l = numStack.top();
                    numStack.pop();
                    BinaryExprAST *binExpr = new BinaryExprAST(op, l, r);
                    numStack.push(binExpr);
                }
                if (!numStack.empty()) {
                    return numStack.top();
                } else {
                    // std::cout<<"empty expression!"<<std::endl;
                    return nullptr;
                }
            }
            default: {
                // std::cout<<"op"<<std::endl;
                if (!opStack.empty() && 
                    getOperatorPrecedence(opStack.top()) >= getOperatorPrecedence(static_cast<int>(curToken.first))) {
                    char op = opStack.top();
                    opStack.pop();
                    ASTNode *l, *r;
                    r = numStack.top();
                    numStack.pop();
                    l = numStack.top();
                    numStack.pop();
                    BinaryExprAST *binExpr = new BinaryExprAST(op, l, r);
                    numStack.push(binExpr);
                }
                opStack.push(static_cast<int>(curToken.first));
                getNextToken();
                break;
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0xb17c
leaq -0xd0(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0xb2f6
leaq 0x88(%rbx), %r12
leaq 0x60(%rbx), %r15
leaq -0x80(%rbp), %r13
leaq 0x9fb4(%rip), %rax      # 0x13ba0
addq $0x10, %rax
movq %rax, -0xe0(%rbp)
movq %r15, -0xd8(%rbp)
movl 0x58(%rbx), %eax
cmpl $0x27, %eax
jg 0x9c3e
testl %eax, %eax
je 0x9c6e
cmpl $0x1, %eax
jne 0x9cc1
movq %rbx, %rdi
callq 0xa17e
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
jne 0x9c8b
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0xb470
jmp 0x9bfe
cmpl $0x29, %eax
jge 0x9ca9
movq %rbx, %rdi
callq 0xa212
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
jne 0x9c8b
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0xb470
jmp 0x9bfe
movq %rbx, %rdi
callq 0xa2d8
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rdx
addq $-0x8, %rdx
cmpq %rdx, %rcx
je 0x9c98
movq %rax, (%rcx)
addq $0x8, -0x50(%rbp)
jmp 0x9bfe
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0xb470
jmp 0x9bfe
je 0x9f61
cmpl $0x2c, %eax
je 0x9f37
cmpl $0x3b, %eax
je 0x9f37
movq -0xa0(%rbp), %rax
cmpq -0xc0(%rbp), %rax
je 0x9ecc
cmpq -0x98(%rbp), %rax
jne 0x9cf1
movq -0x88(%rbp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movl -0x4(%rax), %eax
movl %eax, -0x30(%rbp)
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0xaec8
movl (%rax), %r14d
movl 0x58(%rbx), %eax
movl %eax, -0x30(%rbp)
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0xaec8
cmpl (%rax), %r14d
jl 0x9ecc
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rdi
movq %rax, %rcx
cmpq %rdi, %rax
jne 0x9d4a
movq -0x88(%rbp), %rcx
movq -0x8(%rcx), %rcx
movl $0x200, %edx            # imm = 0x200
addq %rdx, %rcx
movl -0x4(%rcx), %r13d
cmpq %rdi, %rax
je 0x9d59
addq $-0x4, %rax
jmp 0x9d8f
callq 0x31c0
movq -0x88(%rbp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, -0x88(%rbp)
movq -0x8(%rax), %rax
movq %rax, -0x98(%rbp)
leaq 0x200(%rax), %rcx
movq %rcx, -0x90(%rbp)
addq $0x1fc, %rax            # imm = 0x1FC
movq %rax, -0xa0(%rbp)
movq -0x50(%rbp), %r15
movq -0x48(%rbp), %rdi
movq %r15, %rax
cmpq %rdi, %r15
jne 0x9db6
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %rax
cmpq %rdi, %r15
movq %rax, -0xe8(%rbp)
je 0x9dcc
addq $-0x8, %r15
jmp 0x9df7
callq 0x31c0
movq -0x38(%rbp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, -0x38(%rbp)
movq -0x8(%rax), %r15
movq %r15, -0x48(%rbp)
leaq 0x200(%r15), %rax
movq %rax, -0x40(%rbp)
addq $0x1f8, %r15            # imm = 0x1F8
movq %r12, %r14
movq %r15, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq %r15, %rax
cmpq %rdi, %r15
jne 0x9e1a
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %r12
cmpq %rdi, %r15
je 0x9e29
addq $-0x8, %r15
jmp 0x9e54
callq 0x31c0
movq -0x38(%rbp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, -0x38(%rbp)
movq -0x8(%rax), %r15
movq %r15, -0x48(%rbp)
leaq 0x200(%r15), %rax
movq %rax, -0x40(%rbp)
addq $0x1f8, %r15            # imm = 0x1F8
movq %r15, -0x50(%rbp)
movl $0x20, %edi
callq 0x31e0
movsbl %r13b, %ecx
movl $0x0, 0x8(%rax)
movq -0xe0(%rbp), %rdx
movq %rdx, (%rax)
movl %ecx, 0xc(%rax)
movq %r12, 0x10(%rax)
movq -0xe8(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %r15
je 0x9eb2
movq %rax, (%r15)
addq $0x8, -0x50(%rbp)
movq -0xd8(%rbp), %r15
movq %r14, %r12
leaq -0x80(%rbp), %r13
jmp 0x9ecc
leaq -0x80(%rbp), %r13
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0xb470
movq -0xd8(%rbp), %r15
movq %r14, %r12
movl 0x58(%rbx), %ecx
movl %ecx, -0x30(%rbp)
movq -0xa0(%rbp), %rax
movq -0x90(%rbp), %rdx
addq $-0x4, %rdx
cmpq %rdx, %rax
je 0x9ef8
movl %ecx, (%rax)
addq $0x4, %rax
movq %rax, -0xa0(%rbp)
jmp 0x9f08
leaq -0xd0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb67a
movslq 0x80(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x80(%rbx)
movq (%rbx), %rcx
leaq (%rax,%rax,4), %rax
leaq 0x8(%rcx,%rax,8), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rbx)
movq %r15, %rdi
callq 0x3130
jmp 0x9bfe
movslq 0x80(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x80(%rbx)
movq (%rbx), %rcx
leaq (%rax,%rax,4), %rax
leaq 0x8(%rcx,%rax,8), %rsi
movl -0x8(%rsi), %eax
movl %eax, 0x58(%rbx)
movq %r15, %rdi
callq 0x3130
movq -0xa0(%rbp), %rax
cmpq -0xc0(%rbp), %rax
je 0xa0f8
movl $0x200, %r15d           # imm = 0x200
movq -0x98(%rbp), %rdi
movq %rax, %rcx
cmpq %rdi, %rax
jne 0x9f98
movq -0x88(%rbp), %rcx
movq -0x8(%rcx), %rcx
addq %r15, %rcx
movl -0x4(%rcx), %r13d
cmpq %rdi, %rax
je 0x9fa7
addq $-0x4, %rax
jmp 0x9fdd
callq 0x31c0
movq -0x88(%rbp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, -0x88(%rbp)
movq -0x8(%rax), %rax
movq %rax, -0x98(%rbp)
leaq 0x200(%rax), %rcx
movq %rcx, -0x90(%rbp)
addq $0x1fc, %rax            # imm = 0x1FC
movq %rax, -0xa0(%rbp)
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %rdi
movq %rbx, %rax
cmpq %rdi, %rbx
jne 0x9fff
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rax
addq %r15, %rax
movq -0x8(%rax), %r14
cmpq %rdi, %rbx
je 0xa00e
addq $-0x8, %rbx
jmp 0xa039
callq 0x31c0
movq -0x38(%rbp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, -0x38(%rbp)
movq -0x8(%rax), %rbx
movq %rbx, -0x48(%rbp)
leaq 0x200(%rbx), %rax
movq %rax, -0x40(%rbp)
addq $0x1f8, %rbx            # imm = 0x1F8
movq %rbx, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq %rbx, %rax
cmpq %rdi, %rbx
jne 0xa054
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rax
addq %r15, %rax
movq -0x8(%rax), %r12
cmpq %rdi, %rbx
je 0xa063
addq $-0x8, %rbx
jmp 0xa08e
callq 0x31c0
movq -0x38(%rbp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, -0x38(%rbp)
movq -0x8(%rax), %rbx
movq %rbx, -0x48(%rbp)
leaq 0x200(%rbx), %rax
movq %rax, -0x40(%rbp)
addq $0x1f8, %rbx            # imm = 0x1F8
movq %rbx, -0x50(%rbp)
movl $0x20, %edi
callq 0x31e0
movsbl %r13b, %ecx
movl $0x0, 0x8(%rax)
movq -0xe0(%rbp), %rdx
movq %rdx, (%rax)
movl %ecx, 0xc(%rax)
movq %r12, 0x10(%rax)
movq %r14, 0x18(%rax)
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rbx
je 0xa0d7
movq %rax, (%rbx)
addq $0x8, -0x50(%rbp)
jmp 0xa0e4
leaq -0x80(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb470
movq -0xa0(%rbp), %rax
cmpq -0xc0(%rbp), %rax
jne 0x9f7b
movq -0x50(%rbp), %rax
cmpq -0x70(%rbp), %rax
je 0xa11b
cmpq -0x48(%rbp), %rax
jne 0xa115
movq -0x38(%rbp), %rcx
movl $0x200, %eax            # imm = 0x200
addq -0x8(%rcx), %rax
movq -0x8(%rax), %rbx
jmp 0xa11d
xorl %ebx, %ebx
leaq -0xd0(%rbp), %rdi
callq 0x4e62
leaq -0x80(%rbp), %rdi
callq 0xb012
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa15e
jmp 0xa15e
movq %rax, %rbx
jmp 0xa16d
jmp 0xa15e
jmp 0xa15e
jmp 0xa15e
jmp 0xa15e
jmp 0xa15e
jmp 0xa15e
jmp 0xa15e
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x4e62
leaq -0x80(%rbp), %rdi
callq 0xb012
movq %rbx, %rdi
callq 0x3330