//    TRN5


GET "TRNHDR"

LET EVALCONST(X) = VALOF
    $(1 IF X=0 DO $( TRANSREPORT(117, CURRENTBRANCH)
                     RESULTIS 0  $)

        SWITCHON H1!X INTO
     $( DEFAULT: TRANSREPORT(118, X)
                 RESULTIS 0

        CASE S.NAME:
         $( LET T = CELLWITHNAME(X)
            IF DVEC!(T+1)=S.NUMBER RESULTIS DVEC!(T+2)
            TRANSREPORT(119, X)
            RESULTIS 0  $)

        CASE S.NUMBER: RESULTIS H2!X
        CASE S.TRUE: RESULTIS TRUE
        CASE S.FALSE: RESULTIS FALSE

        CASE S.NEG: RESULTIS - EVALCONST(H2!X)
        CASE S.NOT: RESULTIS ~ EVALCONST(H2!X)
        CASE S.ABS: RESULTIS ABS EVALCONST(H2!X)

        CASE S.MULT: RESULTIS EVALCONST(H2!X) * EVALCONST(H3!X)
        CASE S.DIV:  RESULTIS EVALCONST(H2!X) / EVALCONST(H3!X)
        CASE S.PLUS: RESULTIS EVALCONST(H2!X) + EVALCONST(H3!X)
        CASE S.MINUS:RESULTIS EVALCONST(H2!X) - EVALCONST(H3!X)
        CASE S.REM:  RESULTIS EVALCONST(H2!X) REM EVALCONST(H3!X)
        CASE S.LSHIFT:RESULTIS EVALCONST(H2!X) << EVALCONST(H3!X)
        CASE S.RSHIFT:RESULTIS EVALCONST(H2!X) >> EVALCONST(H3!X)
        CASE S.LOGOR:RESULTIS EVALCONST(H2!X) | EVALCONST(H3!X)
        CASE S.LOGAND:RESULTIS EVALCONST(H2!X) & EVALCONST(H3!X)
        CASE S.EQV:  RESULTIS EVALCONST(H2!X) EQV EVALCONST(H3!X)
        CASE S.NEQV: RESULTIS EVALCONST(H2!X) NEQV EVALCONST(H3!X)
                    $)1


AND ASSIGN(X, Y) BE
    $(1 IF X=0 LOGOR Y=0 DO
            $( TRANSREPORT(110, CURRENTBRANCH)
               RETURN  $)

        SWITCHON H1!X INTO
     $( CASE S.COMMA:
            UNLESS H1!Y=S.COMMA DO
                       $( TRANSREPORT(112, CURRENTBRANCH)
                          RETURN   $)
            ASSIGN(H2!X, H2!Y)
            ASSIGN(H3!X, H3!Y)
            RETURN

        CASE S.NAME:
            LOAD(Y)
            TRANSNAME(X, S.SP, S.SG, S.SL, 0)
            SSP := SSP - 1
            RETURN

        CASE S.BYTEAP:
            LOAD(Y)
            LOAD(H2!X)
            LOAD(H3!X)
            OUT1(S.PUTBYTE)
            SSP := SSP - 3
            ENDCASE

        CASE S.RV: CASE S.VECAP: CASE S.COND:
            LOAD(Y)
            LOADLV(X)
            OUT1(S.STIND)
            SSP := SSP - 2
            RETURN

        DEFAULT: TRANSREPORT(109, CURRENTBRANCH)   $)1


AND TRANSNAME(X, P, G, L, N) BE
    $(1 LET T = CELLWITHNAME(X)
        LET K, A = DVEC!(T+1), DVEC!(T+2)

        IF T=0 DO $( TRANSREPORT(115, X)
                     OUT2(G, 2)
                     RETURN  $)

        SWITCHON K INTO
        $( CASE S.LOCAL: IF T<DVECP DO TRANSREPORT(116, X)
                         OUT2(P, A); RETURN

           CASE S.GLOBAL: OUT2(G, A); RETURN

           CASE S.LABEL: OUT2P(L, A); RETURN

           CASE S.NUMBER: IF N=0 DO $( TRANSREPORT(113, X)
                                       N := P  $)
                          OUT2(N, A)  $)1

.