// File: /workspace/github_cpp_makefile_star2_O1/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 0x9b0a
cmpl $0x4, %eax
je 0x9baa
cmpl $0x9, %eax
jne 0x9cfe
movq %r14, %rdi
callq 0x920e
movq %rax, %r12
movq %rax, -0x48(%rbp)
jmp 0x9b5d
cmpl $0x11, %eax
je 0x9be1
cmpl $0xf, %eax
jne 0x9cfe
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 0x903c
movq %r12, -0x48(%rbp)
movl 0x18(%r14), %eax
decl %eax
cmpl $0x1, %eax
ja 0x9c22
movl $0x20, %edi
callq 0x3290
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movl $0xb, (%rax)
movq %rax, -0x28(%rbp)
movq 0x10(%rax), %rsi
cmpq 0x18(%rax), %rsi
je 0x9c57
movq %r12, (%rsi)
addq $0x8, 0x10(%rax)
jmp 0x9c67
leaq -0x48(%rbp), %r12
movl $0x4, (%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x903c
movq %r14, %rdi
callq 0x9aa6
movq %rax, (%r12)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9c37
movq %rax, (%rsi)
addq $0x8, 0x10(%rbx)
jmp 0x9c43
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 0x903c
movq %r12, -0x48(%rbp)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9c31
movq %r12, (%rsi)
jmp 0x9c78
leaq -0x48(%rbp), %rdx
jmp 0x9c83
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0xaf02
leaq -0x48(%rbp), %rsi
movl $0x5, (%rsi)
movq %r14, %rdi
callq 0x903c
jmp 0x9c8b
addq $0x8, %rax
leaq -0x48(%rbp), %rdx
movq %rax, %rdi
callq 0xadc8
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9c7f
movq -0x28(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x10(%rbx)
jmp 0x9c8b
leaq -0x28(%rbp), %rdx
movq %r15, %rdi
callq 0xadc8
movl 0x18(%r14), %eax
decl %eax
cmpl $0x1, %eax
ja 0x9cee
movq %r14, %rdi
callq 0x9f2a
movq %rax, -0x48(%rbp)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9cb6
movq %rax, (%rsi)
addq $0x8, 0x10(%rbx)
jmp 0x9cc2
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0xaf02
movq %r14, %rdi
callq 0x9aa6
movq %rax, -0x48(%rbp)
movq 0x10(%rbx), %rsi
cmpq 0x18(%rbx), %rsi
je 0x9ce2
movq %rax, (%rsi)
addq $0x8, 0x10(%rbx)
jmp 0x9cee
leaq -0x48(%rbp), %rdx
movq %r15, %rdi
callq 0xaf02
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 0x8773(%rip), %rsi      # 0x12480
leaq 0x8795(%rip), %rdx      # 0x124a9
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x8354
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8b40
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x9d3c
callq 0x3250
movq %rbx, %rdi
callq 0x3420