// File: /workspace/github_cpp_makefile_star2_O2/Mespyr[P]bop-lisp/src/parser.cpp
// Function: parse(TokenList)
AST parse(TokenList tokens) 
{
    AST ast;
    Reader reader{tokens};

    if ((int) tokens.token_stream.size() == 0) 
    {
        ast.error = ParsingError{"Unexpected EOF while parsing."};
        ast.error.empty_stream = true;
        ast.error_found = true;
        return ast;
    }

    while(!reader.eof) 
    {
        Node node = read_next(reader);
        if (reader.error_found) 
        {
            ast.error_found = true;
            ast.error = reader.error;
            break;
        } 
        else if (node.type == ATOM) 
        {
            ast.error_found = true;
            ast.error = ParsingError{"Unexpected '" + node.atom.token.value + "' token found while parsing.", node.atom.token};
            break;
        }
        ast.nodes.push_back(node);
    }
    return ast;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movq %rsi, %r14
movq %rdi, %rbx
callq 0xbdfe
leaq -0x128(%rbp), %rdi
movq %r14, %rsi
callq 0xada2
leaq -0xf8(%rbp), %rax
andl $0x0, -0x18(%rax)
xorl %ecx, %ecx
movb %cl, -0x14(%rax)
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
andl $0x0, 0x10(%rax)
leaq -0xd0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movb %cl, 0x10(%rax)
movb %cl, 0x18(%rax)
movq 0x8(%r14), %rax
subq (%r14), %rax
pushq $0x28
popq %rcx
cqto
idivq %rcx
testl %eax, %eax
je 0xbb46
leaq -0x108(%rbp), %r14
xorl %eax, %eax
leaq -0xb0(%rbp), %r15
leaq -0x128(%rbp), %r12
testb $0x1, %al
jne 0xbc26
movq %r15, %rdi
movq %r12, %rsi
callq 0xb706
cmpb $0x1, -0xb8(%rbp)
je 0xbba0
cmpl $0x1, -0xb0(%rbp)
je 0xbbb2
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbe62
movq %r15, %rdi
callq 0x99c0
movb -0x10c(%rbp), %al
jmp 0xbafe
leaq 0x2334(%rip), %rsi      # 0xde81
leaq -0xb0(%rbp), %rdi
leaq -0x178(%rbp), %rdx
callq 0x294e
leaq -0x78(%rbp), %rax
andl $0x0, -0x18(%rax)
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
movb %cl, 0x10(%rax)
leaq 0x20(%rbx), %rdi
leaq -0xb0(%rbp), %r14
movq %r14, %rsi
callq 0xbd4c
movq %r14, %rdi
callq 0xb226
movb $0x1, %al
movb %al, 0x68(%rbx)
movb %al, 0x18(%rbx)
jmp 0xbc26
movb $0x1, 0x18(%rbx)
leaq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0xbe34
jmp 0xbc1a
movb $0x1, 0x18(%rbx)
leaq -0x60(%rbp), %rdx
leaq 0x2308(%rip), %rsi      # 0xdec9
leaq -0x40(%rbp), %rdi
callq 0x9867
leaq 0x22db(%rip), %rdx      # 0xdeac
leaq -0x178(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3ebd
leaq -0x68(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0x9f10
leaq -0x178(%rbp), %r14
movb $0x0, 0x48(%r14)
leaq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0xbd4c
movq %r14, %rdi
callq 0xb226
leaq -0x40(%rbp), %rdi
callq 0x2130
leaq -0xb0(%rbp), %rdi
callq 0x99c0
leaq -0x128(%rbp), %rdi
callq 0xbe9e
movq %rbx, %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x178(%rbp), %rdi
callq 0x2130
jmp 0xbc59
movq %rax, %r14
leaq -0x40(%rbp), %rdi
callq 0x2130
jmp 0xbc72
jmp 0xbc6f
jmp 0xbc6f
jmp 0xbc80
movq %rax, %r14
jmp 0xbc8f
movq %rax, %r14
leaq -0xb0(%rbp), %rdi
callq 0x99c0
jmp 0xbc83
movq %rax, %r14
leaq -0x128(%rbp), %rdi
callq 0xbe9e
movq %rbx, %rdi
callq 0xad82
movq %r14, %rdi
callq 0x2380
nop