// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/crossassemblers/macro11/parse.c
// Function: parse_unary
EX_TREE        *parse_unary(
    char *cp)
{
    EX_TREE        *tp;

    /* Skip leading whitespace */
    cp = skipwhite(cp);

    if (*cp == '%') {                  /* Register notation */
        unsigned        reg;

        cp++;
        reg = strtoul(cp, &cp, 8);
        if (reg > 7)
            return ex_err(NULL, cp);

        /* This returns references to the built-in register symbols */
        tp = new_ex_tree();
        tp->type = EX_SYM;
        tp->data.symbol = reg_sym[reg];
        tp->cp = cp;
        return tp;
    }

    /* Unary negate */
    if (*cp == '-') {
        tp = new_ex_tree();
        tp->type = EX_NEG;
        tp->data.child.left = parse_unary(cp + 1);
        tp->cp = tp->data.child.left->cp;
        return tp;
    }

    /* Unary + I can ignore. */
    if (*cp == '+')
        return parse_unary(cp + 1);

    if (*cp == '^') {
        int             save_radix;

        switch (tolower((unsigned char)cp[1])) {
        case 'c':
            /* ^C, ones complement */
            tp = new_ex_tree();
            tp->type = EX_COM;
            tp->data.child.left = parse_unary(cp + 2);
            tp->cp = tp->data.child.left->cp;
            return tp;
        case 'b':
            /* ^B, binary radix modifier */
            save_radix = radix;
            radix = 2;
            tp = parse_unary(cp + 2);
            radix = save_radix;
            return tp;
        case 'o':
            /* ^O, octal radix modifier */
            save_radix = radix;
            radix = 8;
            tp = parse_unary(cp + 2);
            radix = save_radix;
            return tp;
        case 'd':
            /* ^D, decimal radix modifier */
            save_radix = radix;
            radix = 10;
            tp = parse_unary(cp + 2);
            radix = save_radix;
            return tp;
        case 'x':
            /* ^X, hexadecimal radix modifier */
            save_radix = radix;
            radix = 16;
            tp = parse_unary(cp + 2);
            radix = save_radix;
            return tp;
        case 'r':
            /* ^R, RAD50 literal */  {
                int             start,
                                len;
                char           *endcp;
                unsigned        value;

                cp += 2; /* bracketed range is an extension */
                if (brackrange(cp, &start, &len, &endcp))
                    value = rad50(cp + start, NULL);
                else
                    value = rad50(cp, &endcp);
                tp = new_ex_lit(value);
                tp->cp = endcp;
                return tp;
            }
        case 'f':
            /* ^F, single-word floating point literal indicator */  {
                unsigned        flt[1];
                char           *endcp;

                if (!parse_float(cp + 2, &endcp, 1, flt)) {
                    tp = ex_err(NULL, cp + 2);
                } else {
                    tp = new_ex_lit(flt[0]);
                    tp->cp = endcp;
                }
                return tp;
            }
        }

        if (ispunct((unsigned char)cp[1])) {
            char           *ecp;

            /* oddly-bracketed expression like this: ^/expression/ */
            tp = parse_binary(cp + 2, cp[1], 0);
            ecp = skipwhite(tp->cp);

            if (*ecp != cp[1])
                return ex_err(tp, ecp);

            tp->cp = ecp + 1;
            return tp;
        }
    }

    /* Bracketed subexpression */
    if (*cp == '<') {
        char           *ecp;

        tp = parse_binary(cp + 1, '>', 0);
        ecp = skipwhite(tp->cp);
        if (*ecp != '>')
            return ex_err(tp, ecp);

        tp->cp = ecp + 1;
        return tp;
    }

    /* Check for ASCII constants */

    if (*cp == '\'') {
        /* 'x single ASCII character */
        cp++;
        tp = new_ex_lit(*cp & 0xff);
        tp->cp = ++cp;
        return tp;
    }

    if (*cp == '\"') {
        /* "xx ASCII character pair */
        cp++;
        tp = new_ex_lit((cp[0] & 0xff) | ((cp[1] & 0xff) << 8));
        tp->cp = cp + 2;
        return tp;
    }

    /* Numeric constants are trickier than they need to be, */
    /* since local labels start with a digit too. */
    if (isdigit((unsigned char)*cp)) {
        char           *label;
        int             local;

        if ((label = get_symbol(cp, NULL, &local)) == NULL) {
            char           *endcp;
            unsigned long   value;
            int             rad = radix;

            /* get_symbol returning NULL assures me that it's not a
               local label.  */

            /* Look for a trailing period, to indicate decimal... */
            for (endcp = cp; isdigit((unsigned char)*endcp); endcp++) ;
            if (*endcp == '.')
                rad = 10;

            value = strtoul(cp, &endcp, rad);
            if (*endcp == '.')
                endcp++;

            tp = new_ex_lit(value);
            tp->cp = endcp;

            return tp;
        }

        free(label);
    }

    /* Now check for a symbol */
    {
        char           *label;
        int             local;
        SYMBOL         *sym;

        /* Optimization opportunity: I don't really need to call
           get_symbol a second time. */

        if (!(label = get_symbol(cp, &cp, &local))) {
            cp++;                      /*JH: eat first char of illegal label, else endless loop on implied .WORD */
            tp = ex_err(NULL, cp);     /* Not a valid label. */
            return tp;
        }

        sym = lookup_sym(label, &symbol_st);
        if (sym == NULL) {
            /* A symbol from the "PST", which means an instruction
               code. */
            sym = lookup_sym(label, &system_st);
        }

        if (sym != NULL) {
            tp = new_ex_tree();
            tp->cp = cp;
            tp->type = EX_SYM;
            tp->data.symbol = sym;

            free(label);
            return tp;
        }

        /* The symbol was not found. Create an "undefined symbol"
           reference. */
        sym = memcheck(malloc(sizeof(SYMBOL)));
        sym->label = label;
        sym->flags = SYMBOLFLAG_UNDEFINED | local;
        sym->stmtno = stmtno;
        sym->next = NULL;
        sym->section = &absolute_section;
        sym->value = 0;

        tp = new_ex_tree();
        tp->cp = cp;
        tp->type = EX_UNDEFINED_SYM;
        tp->data.symbol = sym;

        return tp;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq %rbx, 0x8(%rsp)
incq %rbx
movzbl -0x1(%rbx), %eax
cmpl $0x20, %eax
je 0x9223
cmpl $0x9, %eax
je 0x9223
leaq -0x1(%rbx), %r14
movq %r14, 0x8(%rsp)
cmpl $0x2b, %eax
je 0x921e
cmpl $0x5e, %eax
je 0x9289
cmpl $0x2d, %eax
je 0x92d0
cmpl $0x25, %eax
jne 0x9414
leaq 0x8(%rsp), %rsi
movq %rbx, (%rsi)
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2290
movq %rax, %rbx
testl $0xfffffff8, %ebx       # imm = 0xFFFFFFF8
je 0x9324
movq 0x8(%rsp), %rsi
xorl %edi, %edi
jmp 0x9585
callq 0x22f0
movq (%rax), %rax
movzbl (%rbx), %r15d
movl (%rax,%r15,4), %eax
cmpl $0x6e, %eax
jg 0x92f3
addl $-0x62, %eax
cmpl $0x4, %eax
ja 0x9401
leaq 0x734b(%rip), %rcx      # 0x105fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xbedf(%rip), %r14      # 0x151a0
movl (%r14), %ebp
movl $0x2, (%r14)
jmp 0x93b3
callq 0x6ed2
movq %rax, %r14
movl $0x6, (%rax)
movq %rbx, %rdi
callq 0x9211
movq %rax, 0x10(%r14)
movq 0x8(%rax), %rax
jmp 0x961e
cmpl $0x6f, %eax
je 0x93a2
cmpl $0x72, %eax
je 0x93c6
cmpl $0x78, %eax
jne 0x9401
leaq 0xbe8b(%rip), %r14      # 0x151a0
movl (%r14), %ebp
movl $0x10, (%r14)
jmp 0x93b3
callq 0x6ed2
movq %rax, %r14
movl $0x2, (%rax)
andl $0x7, %ebx
leaq 0x12344(%rip), %rax     # 0x1b680
movq (%rax,%rbx,8), %rax
movq %rax, 0x10(%r14)
movq 0x8(%rsp), %rax
jmp 0x961e
leaq 0xbe4b(%rip), %r14      # 0x151a0
movl (%r14), %ebp
movl $0xa, (%r14)
jmp 0x93b3
incq %rbx
leaq 0x18(%rsp), %rsi
leaq 0x14(%rsp), %rcx
movq %rbx, %rdi
movl $0x1, %edx
callq 0x9001
testl %eax, %eax
je 0x95f0
movl 0x14(%rsp), %edi
jmp 0x9611
callq 0x6ed2
movq %rax, %r14
movl $0x5, (%rax)
incq %rbx
jmp 0x92de
leaq 0xbdf7(%rip), %r14      # 0x151a0
movl (%r14), %ebp
movl $0x8, (%r14)
incq %rbx
movq %rbx, %rdi
callq 0x9211
movl %ebp, (%r14)
jmp 0x9625
incq %rbx
movq %rbx, 0x8(%rsp)
leaq 0x14(%rsp), %rsi
leaq 0x24(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %rbx, %rdi
callq 0x8846
movq 0x8(%rsp), %rdi
testl %eax, %eax
je 0x9605
movslq 0x14(%rsp), %rax
addq %rax, %rdi
xorl %esi, %esi
jmp 0x960a
callq 0x2300
movq (%rax), %rax
testb $0x4, (%rax,%r15,2)
jne 0x9556
movzbl -0x1(%rbx), %r15d
cmpl $0x22, %r15d
je 0x946c
cmpl $0x27, %r15d
je 0x9457
cmpl $0x3c, %r15d
jne 0x9489
movq %rbx, %rdi
movl $0x3e, %esi
xorl %edx, %edx
callq 0x9144
movq %rax, %r14
movq 0x8(%rax), %rsi
movzbl (%rsi), %eax
cmpl $0x9, %eax
je 0x9452
cmpl $0x20, %eax
jne 0x9533
incq %rsi
jmp 0x9441
movq %rbx, 0x8(%rsp)
movzbl (%rbx), %edi
callq 0x7642
movq %rax, %r14
incq %rbx
jmp 0x9480
movq %rbx, 0x8(%rsp)
movzwl (%rbx), %edi
callq 0x7642
movq %rax, %r14
addq $0x2, %rbx
movq %rbx, 0x8(%rax)
jmp 0x9622
callq 0x2300
movq %rax, %rbx
movq (%rax), %rax
testb $0x8, 0x1(%rax,%r15,2)
je 0x94c1
leaq 0x14(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8af9
testq %rax, %rax
je 0x9594
movq %rax, %rdi
callq 0x2050
movq 0x8(%rsp), %r14
leaq 0x8(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x8af9
testq %rax, %rax
je 0x9544
movq %rax, %rbx
leaq 0xe1ae(%rip), %rsi      # 0x17690
movq %rax, %rdi
callq 0x9e32
testq %rax, %rax
jne 0x9507
leaq 0x10192(%rip), %rsi     # 0x19688
movq %rbx, %rdi
callq 0x9e32
testq %rax, %rax
je 0x9630
movq %rax, %r15
callq 0x6ed2
movq %rax, %r14
movq 0x8(%rsp), %rax
movq %rax, 0x8(%r14)
movl $0x2, (%r14)
movq %r15, 0x10(%r14)
movq %rbx, %rdi
callq 0x2050
jmp 0x9622
cmpl $0x3e, %eax
jne 0x9582
incq %rsi
movq %rsi, 0x8(%r14)
jmp 0x9622
movq 0x8(%rsp), %rsi
incq %rsi
movq %rsi, 0x8(%rsp)
jmp 0x95f9
leaq 0x1(%rbx), %rdi
movsbl %r15b, %esi
xorl %edx, %edx
callq 0x9144
movq %rax, %r14
movq 0x8(%rax), %rsi
movzbl (%rsi), %eax
cmpl $0x20, %eax
je 0x9579
cmpl $0x9, %eax
jne 0x957e
incq %rsi
jmp 0x956c
cmpb (%rbx), %al
je 0x9538
movq %r14, %rdi
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x768f
leaq 0xbc05(%rip), %rax      # 0x151a0
movl (%rax), %edx
movq 0x8(%rsp), %rdi
movq (%rbx), %rcx
leaq -0x1(%rdi), %rax
movzbl 0x1(%rax), %esi
incq %rax
testb $0x8, 0x1(%rcx,%rsi,2)
jne 0x95a9
leaq 0x18(%rsp), %rbx
movq %rax, (%rbx)
cmpb $0x2e, %sil
movl $0xa, %eax
cmovel %eax, %edx
movq %rbx, %rsi
callq 0x2290
movq (%rbx), %rcx
xorl %ebx, %ebx
cmpb $0x2e, (%rcx)
sete %bl
addq %rcx, %rbx
movl %eax, %edi
callq 0x7642
movq %rax, %r14
jmp 0x9480
movq 0x8(%rsp), %rsi
addq $0x2, %rsi
xorl %edi, %edi
callq 0x768f
movq %rax, %r14
jmp 0x9622
leaq 0x18(%rsp), %rsi
callq 0xe2a0
movl %eax, %edi
callq 0x7642
movq %rax, %r14
movq 0x18(%rsp), %rax
movq %rax, 0x8(%r14)
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x2230
movq %rax, %rdi
callq 0xe094
movq %rax, %r15
movq %rbx, (%rax)
movl 0x18(%rsp), %eax
orl $0x10, %eax
movl %eax, 0x10(%r15)
leaq 0xc50a(%rip), %rax      # 0x15b64
movl (%rax), %eax
movl %eax, 0xc(%r15)
movq $0x0, 0x20(%r15)
leaq 0xbbc1(%rip), %rax      # 0x15230
movq %rax, 0x18(%r15)
movl $0x0, 0x8(%r15)
callq 0x6ed2
movq %rax, %r14
movq 0x8(%rsp), %rax
movq %rax, 0x8(%r14)
movl $0x3, (%r14)
movq %r15, 0x10(%r14)
jmp 0x9622