// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movq %rbx, 0x8(%rsp)
incq %rbx
movzbl -0x1(%rbx), %eax
cmpl $0x20, %eax
je 0x9356
cmpl $0x9, %eax
je 0x9356
leaq -0x1(%rbx), %rcx
movq %rcx, 0x8(%rsp)
cmpl $0x2b, %eax
je 0x9351
cmpl $0x5e, %eax
je 0x93c9
cmpl $0x2d, %eax
je 0x9410
cmpl $0x25, %eax
jne 0x9438
leaq 0x8(%rsp), %rsi
movq %rbx, (%rsi)
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2290
movq %rax, %r14
testl $0xfffffff8, %r14d      # imm = 0xFFFFFFF8
je 0x946e
movq 0x8(%rsp), %rsi
xorl %edi, %edi
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x77b3
callq 0x22f0
movq (%rax), %rax
movzbl (%rbx), %r14d
movl (%rax,%r14,4), %eax
cmpl $0x6e, %eax
jg 0x943d
addl $-0x62, %eax
cmpl $0x4, %eax
ja 0x955b
leaq 0x721b(%rip), %rcx      # 0x1060c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xbd9f(%rip), %r14      # 0x151a0
movl (%r14), %ebp
movl $0x2, (%r14)
jmp 0x9511
callq 0x6fd7
movq %rax, %rbx
movl $0x6, (%rax)
movq 0x8(%rsp), %rdi
incq %rdi
callq 0x9342
movq %rax, 0x10(%rbx)
movq 0x8(%rax), %rax
jmp 0x9678
jmp 0x95e6
cmpl $0x6f, %eax
je 0x9500
cmpl $0x72, %eax
je 0x9527
cmpl $0x78, %eax
jne 0x955b
leaq 0xbd41(%rip), %r14      # 0x151a0
movl (%r14), %ebp
movl $0x10, (%r14)
jmp 0x9511
callq 0x6fd7
movq %rax, %rbx
movl $0x2, (%rax)
andl $0x7, %r14d
leaq 0x121f9(%rip), %rax     # 0x1b680
movq (%rax,%r14,8), %rax
movq %rax, 0x10(%rbx)
movq 0x8(%rsp), %rax
jmp 0x9678
leaq 0xbd00(%rip), %r14      # 0x151a0
movl (%r14), %ebp
movl $0xa, (%r14)
jmp 0x9511
incq %rbx
leaq 0x10(%rsp), %rsi
leaq 0x18(%rsp), %rcx
movq %rbx, %rdi
movl $0x1, %edx
callq 0x9132
testl %eax, %eax
je 0x95af
movl 0x18(%rsp), %edi
jmp 0x95cb
callq 0x6fd7
movq %rax, %rbx
movl $0x5, (%rax)
movq 0x8(%rsp), %rdi
addq $0x2, %rdi
callq 0x9342
movq %rax, 0x10(%rbx)
movq 0x8(%rax), %rax
jmp 0x95d8
leaq 0xbc99(%rip), %r14      # 0x151a0
movl (%r14), %ebp
movl $0x8, (%r14)
incq %rbx
movq %rbx, %rdi
callq 0x9342
movq %rax, %rbx
movl %ebp, (%r14)
jmp 0x95dc
incq %rbx
movq %rbx, 0x8(%rsp)
leaq 0x18(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
callq 0x89a1
movq 0x8(%rsp), %rdi
testl %eax, %eax
je 0x95bf
movslq 0x18(%rsp), %rax
addq %rax, %rdi
xorl %esi, %esi
jmp 0x95c4
callq 0x2300
movq (%rax), %rax
testb $0x4, (%rax,%r14,2)
jne 0x956e
movb $0x1, %al
jmp 0x95de
incq %rbx
movsbl %r14b, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x9275
movq %rax, %rbx
movq 0x8(%rax), %rsi
movzbl (%rsi), %eax
cmpl $0x20, %eax
je 0x9593
cmpl $0x9, %eax
jne 0x9598
incq %rsi
jmp 0x9586
movq 0x8(%rsp), %rcx
cmpb 0x1(%rcx), %al
jne 0x983c
incq %rsi
movq %rsi, 0x8(%rbx)
jmp 0x95dc
movq 0x8(%rsp), %rsi
addq $0x2, %rsi
xorl %edi, %edi
jmp 0x983f
leaq 0x10(%rsp), %rsi
callq 0xe550
movl %eax, %edi
callq 0x7766
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
xorl %eax, %eax
testb %al, %al
je 0x967c
movq 0x8(%rsp), %r14
movzbl (%r14), %r12d
cmpl $0x22, %r12d
je 0x9659
cmpl $0x27, %r12d
je 0x9634
cmpl $0x3c, %r12d
jne 0x968c
incq %r14
movq %r14, %rdi
movl $0x3e, %esi
xorl %edx, %edx
callq 0x9275
movq %rax, %rbx
movq 0x8(%rax), %rsi
movzbl (%rsi), %eax
cmpl $0x9, %eax
je 0x962f
cmpl $0x20, %eax
jne 0x96c4
incq %rsi
jmp 0x961e
leaq 0x1(%r14), %rax
movq %rax, 0x8(%rsp)
movzbl 0x1(%r14), %edi
callq 0x7766
movq %rax, %rbx
movq 0x8(%rsp), %rax
incq %rax
movq %rax, 0x8(%rsp)
jmp 0x9678
leaq 0x1(%r14), %rax
movq %rax, 0x8(%rsp)
movzwl 0x1(%r14), %edi
callq 0x7766
movq %rax, %rbx
movq 0x8(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x8(%rbx)
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x2300
movq %rax, %r15
movq (%rax), %rax
testb $0x8, 0x1(%rax,%r12,2)
je 0x9745
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x8c1a
movq %rax, %r14
testq %rax, %rax
je 0x96da
movq %r14, %rdi
callq 0x2050
jmp 0x973c
cmpl $0x3e, %eax
jne 0x96d2
incq %rsi
movq %rsi, 0x8(%rbx)
jmp 0x967c
movq %rbx, %rdi
jmp 0x97c4
leaq 0xbabf(%rip), %rax      # 0x151a0
movl (%rax), %edx
movq 0x8(%rsp), %rdi
movq (%r15), %rcx
leaq -0x1(%rdi), %rax
movzbl 0x1(%rax), %esi
incq %rax
testb $0x8, 0x1(%rcx,%rsi,2)
jne 0x96ef
leaq 0x10(%rsp), %rbx
movq %rax, (%rbx)
cmpb $0x2e, %sil
movl $0xa, %eax
cmovel %eax, %edx
movq %rbx, %rsi
callq 0x2290
movq (%rbx), %rcx
cmpb $0x2e, (%rcx)
jne 0x9729
incq %rcx
movq %rcx, 0x10(%rsp)
movl %eax, %edi
callq 0x7766
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
testq %r14, %r14
je 0x967c
leaq 0x8(%rsp), %rsi
movq (%rsi), %rdi
leaq 0x10(%rsp), %rdx
callq 0x8c1a
testq %rax, %rax
je 0x97b5
movq %rax, %r14
leaq 0xdf2a(%rip), %rsi      # 0x17690
movq %rax, %rdi
callq 0x9ff5
movq %rax, %r15
testq %rax, %rax
jne 0x9788
leaq 0xff0b(%rip), %rsi      # 0x19688
movq %r14, %rdi
callq 0x9ff5
movq %rax, %r15
testq %r15, %r15
je 0x97d1
callq 0x6fd7
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rbx)
movl $0x2, (%rbx)
movq %r15, 0x10(%rbx)
movq %r14, %rdi
callq 0x2050
jmp 0x967c
movq 0x8(%rsp), %rsi
incq %rsi
movq %rsi, 0x8(%rsp)
xorl %edi, %edi
callq 0x77b3
movq %rax, %rbx
jmp 0x967c
movl $0x28, %edi
callq 0x2230
movq %rax, %rdi
callq 0xe34f
movq %rax, %r15
movq %r14, (%rax)
movl 0x10(%rsp), %eax
orl $0x10, %eax
movl %eax, 0x10(%r15)
leaq 0xc369(%rip), %rax      # 0x15b64
movl (%rax), %eax
movl %eax, 0xc(%r15)
movq $0x0, 0x20(%r15)
leaq 0xba20(%rip), %rax      # 0x15230
movq %rax, 0x18(%r15)
movl $0x0, 0x8(%r15)
callq 0x6fd7
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rbx)
movl $0x3, (%rbx)
movq %r15, 0x10(%rbx)
jmp 0x967c
movq %rbx, %rdi
callq 0x77b3
movq %rax, %rbx
jmp 0x95dc