// File: /workspace/github_cpp_makefile_star2_O3/taurheim[P]AgNES/parser.cpp
// Function: Parser::expression()
ASTNode * Parser::expression() {
    /*
        "-" <expression>
        | "!" <expression>
        | "(" <expression> ")"
        | <number>
        | <character>
        | <string>
        | <identifier> "(" [ <expression> { "," <expression> }] ")" 
        | <identifier>  "[" <expression> "]"
        | <identifier>
        | <expression> <binaryOperation> <expression>
    */
    ASTNode * node = new ASTNode(AST_EXPRESSION);

    switch(t.type) {
        case T_INTVALUE: {
            ASTNode * numberNode = number();
            if (t.type == T_PLUS || t.type == T_MINUS) {
                ASTNode * expressionNode = new ASTNode(AST_EXPRESSION);
                expressionNode->children.push_back(numberNode);
                node->children.push_back(expressionNode);
            } else {
                node->children.push_back(numberNode);
            }
            break;
        }
        case T_CHARVALUE: {
            ASTNode * charNode = character();
            node->children.push_back(charNode);
            break;
        }
        case T_IDENT: {
            ASTNode * identNode = identifier();
            if (t.type == T_PLUS || t.type == T_MINUS) {
                ASTNode * expressionNode = new ASTNode(AST_EXPRESSION);
                expressionNode->children.push_back(identNode);
                node->children.push_back(expressionNode);
            } else {
                node->children.push_back(identNode);
            }
            break;
        }
        case T_LPAREN: {
            expect(T_LPAREN);
            node->children.push_back(expression());
            expect(T_RPAREN);
            break;
        }
        default: {
            reject("Expression expected T_IDENT or T_INTVALUE");
        }
    }

    if(t.type == T_PLUS || t.type == T_MINUS) {
        node->children.push_back(op());
        node->children.push_back(expression());
    } else if (t.type == T_LPAREN) {
        // Function call
    }

    return node;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %r14
movl $0x20, %edi
callq 0x3290
movq %rax, %rbx
leaq 0x8(%rax), %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movl $0xb, (%rax)
movl 0x18(%r14), %eax
cmpl $0xe, %eax
jg 0x9a3e
cmpl $0x4, %eax
je 0x9aec
cmpl $0x9, %eax
jne 0x9c17
movq %r14, %rdi
callq 0x9154
movq %rax, -0x48(%rbp)
movl 0x18(%r14), %ecx
decl %ecx
cmpl $0x1, %ecx
jbe 0x9aa0
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9b78
movq %rax, (%rsi)
jmp 0x9b71
cmpl $0x11, %eax
je 0x9b23
cmpl $0xf, %eax
jne 0x9c17
movl $0x28, %edi
callq 0x3290
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movl $0x5, (%rax)
movl 0x40(%r14), %eax
movl %eax, 0x20(%r12)
leaq -0x28(%rbp), %rsi
movl $0xf, (%rsi)
movq %r14, %rdi
callq 0x8f9a
movq %r12, -0x48(%rbp)
movl 0x18(%r14), %eax
decl %eax
cmpl $0x1, %eax
ja 0x9b64
movl $0x20, %edi
callq 0x3290
movq %rax, %r12
leaq 0x8(%rax), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movl $0xb, (%rax)
movq %rax, -0x28(%rbp)
leaq -0x48(%rbp), %rdx
xorl %esi, %esi
callq 0xac72
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
jne 0x9b6e
leaq -0x28(%rbp), %rdx
jmp 0x9b7c
leaq -0x48(%rbp), %r12
movl $0x4, (%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x8f9a
movq %r14, %rdi
callq 0x99be
movq %rax, (%r12)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9b86
movq %rax, (%rsi)
addq $0x8, 0x10(%rbx)
jmp 0x9b92
movl $0x28, %edi
callq 0x3290
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movl $0x12, (%rax)
movb 0x44(%r14), %al
movb %al, 0x20(%r12)
leaq -0x28(%rbp), %rsi
movl $0x11, (%rsi)
movq %r14, %rdi
callq 0x8f9a
movq %r12, -0x48(%rbp)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9b78
movq %r12, (%rsi)
addq $0x8, 0x10(%rbx)
jmp 0x9ba4
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0xac72
jmp 0x9ba4
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0xadac
leaq -0x48(%rbp), %rsi
movl $0x5, (%rsi)
movq %r14, %rdi
callq 0x8f9a
movl 0x18(%r14), %eax
decl %eax
cmpl $0x1, %eax
ja 0x9c07
movq %r14, %rdi
callq 0x9e20
movq %rax, -0x48(%rbp)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9bcf
movq %rax, (%rsi)
addq $0x8, 0x10(%rbx)
jmp 0x9bdb
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0xadac
movq %r14, %rdi
callq 0x99be
movq %rax, -0x48(%rbp)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9bfb
movq %rax, (%rsi)
addq $0x8, 0x10(%rbx)
jmp 0x9c07
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0xadac
movq %rbx, %rax
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x885a(%rip), %rsi      # 0x12480
leaq 0x887c(%rip), %rdx      # 0x124a9
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x82f0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8ad6
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x9c55
callq 0x3250
movq %rbx, %rdi
callq 0x3420
nop