//    CAE0


GET "SYNHDR"

LET NEWVEC(N) = VALOF
    $( TREEP := TREEP - N - 1
       IF TREEP<=TREEVEC DO
                $( REPORTMAX := 0
                   CAEREPORT(98)  $)
        RESULTIS TREEP  $)

AND LIST1(X) = VALOF
    $( LET P = NEWVEC(0)
       P!0 := X
       RESULTIS P  $)

AND LIST2(X, Y) = VALOF
     $( LET P = NEWVEC(1)
        P!0, P!1 := X, Y
        RESULTIS P   $)

AND LIST3(X, Y, Z) = VALOF
     $( LET P = NEWVEC(2)
        P!0, P!1, P!2 := X, Y, Z
        RESULTIS P     $)

AND LIST4(X, Y, Z, T) = VALOF
     $( LET P = NEWVEC(3)
        P!0, P!1, P!2, P!3 := X, Y, Z, T
        RESULTIS P   $)

AND LIST5(X, Y, Z, T, U) = VALOF
     $( LET P = NEWVEC(4)
        P!0, P!1, P!2, P!3, P!4 := X, Y, Z, T, U
        RESULTIS P   $)

AND LIST6(X, Y, Z, T, U, V) = VALOF
     $( LET P = NEWVEC(5)
        P!0, P!1, P!2, P!3, P!4, P!5 := X, Y, Z, T, U, V
        RESULTIS P  $)

AND CAEREPORT(N, A) BE
     $( REPORTCOUNT := REPORTCOUNT + 1
        WRITEF("*NSYNTAX ERROR NEAR LINE %N:  ", LINECOUNT)
        CAEMESSAGE(N, A)
        WRCHBUF()
        IF REPORTCOUNT GR REPORTMAX DO
                    $( WRITES('*NCOMPILATION ABORTED*N')
                       STOP(8)   $)
        NLPENDING := FALSE

        UNTIL SYMB=S.LSECT LOGOR SYMB=S.RSECT LOGOR
              SYMB=S.LET LOGOR SYMB=S.AND LOGOR
              SYMB=S.END LOGOR NLPENDING DO NEXTSYMB()
        LONGJUMP(REC.P, REC.L)   $)

AND RPROG() = VALOF
$( LET OP, A = SYMB, 0
   NEXTSYMB()
   UNLESS SYMB=S.STRING DO CAEREPORT(97)
   A := RBEXP()
   RESULTIS LIST3(OP, A,
         SYMB=S.NEEDS -> RPROG(), RDBLOCKBODY())
$)

AND FORMTREE() =  VALOF
    $(1 CHCOUNT := 0
        FOR I = 0 TO 63 DO CHBUF!I := 0

     $( LET V = VEC 10   // FOR 'GET' STREAMS
        GETV, GETP, GETT := V, 0, 10

     $( LET V = VEC 100
        WORDV := V

     $( LET V = VEC 256
        CHARV, CHARP := V, 0

     $( LET V = VEC 100
        NAMETABLE, NAMETABLESIZE := V, 100
        FOR I = 0 TO 100 DO NAMETABLE!I := 0

        REC.P, REC.L := LEVEL(), L

        LINECOUNT, PRLINE := 1, 0
        RCH()

        IF CH=ENDSTREAMCH RESULTIS 0
        DECLSYSWORDS()

     L: NEXTSYMB()

        IF OPTION!1 DO   //   PP DEBUGGING OPTION
             $( WRITEF("%N %S*N", SYMB, WORDV)
                IF SYMB=S.END RESULTIS 0
                GOTO L  $)

     $( LET A = SYMB=S.SECTION LOGOR SYMB=S.NEEDS -> RPROG(), RDBLOCKBODY()
        UNLESS SYMB=S.END DO $( CAEREPORT(99); GOTO L  $)

        RESULTIS A        $)1



AND CAEMESSAGE(N, A) BE $(
  LET S=VALOF
    SWITCHON N INTO
         $( DEFAULT:  WRITEN(N); RETURN

            CASE 91: RESULTIS "'8'  '(' OR ')' EXPECTED"
            CASE 94: RESULTIS "ILLEGAL CHARACTER"
            CASE 95: RESULTIS "STRING TOO LONG"
            CASE 96: RESULTIS "NO INPUT %S"
            CASE 97: RESULTIS "STRING OR NUMBER EXPECTED"
            CASE 98: RESULTIS "PROGRAM TOO LARGE"
            CASE 99: RESULTIS "INCORRECT TERMINATION"

            CASE 8:CASE 40:CASE 43:
                     RESULTIS "NAME EXPECTED"
            CASE 6: RESULTIS "'$(' EXPECTED"
            CASE 7: RESULTIS "'$)' EXPECTED"
            CASE 9: RESULTIS "UNTAGGED '$)' MISMATCH"
            CASE 32: RESULTIS "ERROR IN EXPRESSION"
            CASE 33: RESULTIS "ERROR IN NUMBER"
            CASE 34: RESULTIS "BAD STRING"
            CASE 15:CASE 19:CASE 41: RESULTIS "')' MISSING"
            CASE 30: RESULTIS "',' MISSING"
            CASE 42: RESULTIS "'=' OR 'BE' EXPECTED"
            CASE 44: RESULTIS "'=' OR '(' EXPECTED"
            CASE 50: RESULTIS "ERROR IN LABEL"
            CASE 51: RESULTIS "ERROR IN COMMAND"
            CASE 54: RESULTIS "'OR' EXPECTED"
            CASE 57: RESULTIS "'=' EXPECTED"
            CASE 58: RESULTIS "'TO' EXPECTED"
            CASE 60: RESULTIS "'INTO' EXPECTED"
            CASE 61:CASE 62: RESULTIS "':' EXPECTED"
            CASE 63: RESULTIS "'**/' MISSING"
                       $)

         WRITEF(S, A)  $)


.