REM PC.COMPILE.SYNTAX
*PRE-COMPILER
*
*
*BASIC
*N
*     PRECISION 6
*
************************************************************************
************************************************************************
***                                                                  ***
*** PICK PARSING PRE-COMPILER SYSTEM                                 ***
***                                                                  ***
*** COPYRIGHT 1988 MODULAR SOFTWARE                                  ***
***                P.O. BOX 204                                      ***
***                ATLANTA, GA  30291                                ***
***                (404) 964 - 7171                                  ***
***                                                                  ***
*** THIS PROGRAM IS PROPRIETARY TO MODULAR SOFTWARE AND MAY NOT BE   ***
*** USED, COPIED, EXAMINED, OR DISCLOSED WITHOUT A VALID LICENSE     ***
*** FROM MODULAR SOFTWARE.                                           ***
***                                                                  ***
************************************************************************
************************************************************************
*
*
* Routine to compile the PRE.COMP file into the format required by the
* PRE.COMPILE program
*
      $INCLUDE PC.COMMON
*
      EQUATE SEP.CH TO CHAR(240)
*
*$*   TCLREAD S
      CALL PC.SENTENCE(S)
*
      SYNTAX.FILE = S<2>
      OBJ.FILE = S<3>
*
      OPEN SYNTAX.FILE TO SRC.FD ELSE STOP 201,SYNTAX.FILE
      OPEN OBJ.FILE TO OBJ.FD ELSE STOP 201,OBJ.FILE
      IF SYNTAX.FILE = '' THEN SYNTAX.FILE = 'PC.BP'
*
      KW.L = ''
      KW.L.F = ''
*
      EXECUTE 'QSELECT ' : SYNTAX.FILE : ' SYNTAX.LIST'
*
      CLEARFILE OBJ.FD
*
      TREE.CNT = 0
*
      COUNTER = 1
      EOF = NO
      LOOP
         READNEXT ID ELSE EOF = YES
      UNTIL EOF DO
         PRINT CR : COUNTER 'R#3' : ' ' : ID 'L#50' :
         READ DATA FROM SRC.FD , ID THEN
*
            S = DATA<4>
            CALL PC.PARSE(S,OBJ)
*
            NODE.ID = '*' : DATA<1>
            C = 1
            LOOP
               READ NODE FROM OBJ.FD , NODE.ID ELSE NODE = ''
               ATTR = 0
               V.FLG = 0
               OO = OBJ<1,1,C>
               TP = OBJ<1,2,C>
               BEGIN CASE
                  CASE TP >= 0; * FIXED STRING
                     ATTR = 2
                  CASE TP = -1; * VARIABLE STRING
                     C = C + 1
                     OO = OBJ<1,1,C>
                     TP = OBJ<1,2,C>
                     BEGIN CASE
                        CASE OO = ''
                           ATTR = 5
                        CASE TP >= 0
                           ATTR = 4
                        CASE TP = -1
                           STOP 'PC','Multi % if definitions'
                        CASE TP = -2
                           ATTR = 4
                           V.FLG = YES
                        CASE YES
                           STOP 'PC','Undefined TP = ':TP
                     END CASE
                  CASE TP = -4; * VARIABLE STRING
                     C = C + 1
                     OO = OBJ<1,1,C>
                     TP = OBJ<1,2,C>
                     BEGIN CASE
                        CASE OO = ''
                           ATTR = 6
                        CASE TP >= 0
                           ATTR = 3
                        CASE TP = -4
                           STOP 'PC','Multi % if definitions'
                        CASE TP = -1
                           STOP 'PC','{V} followed by a {%}'
                        CASE TP = -2
                           ATTR = 3
                           V.FLG = YES
                        CASE YES
                           STOP 'PC','Undefined TP = ':TP
                     END CASE
                  CASE TP = -2
                     ATTR = 2
                     V.FLG = YES
                  CASE YES
                     STOP 'PC','Undefined TP = ':TP
               END CASE
               C = C + 1
*
               BEGIN CASE
                  CASE ATTR = 2
                     T = FIELD(OO,'\',1)
                     LOCATE T IN NODE<2,1,1> SETTING LOC THEN
                        NODE.ID = NODE<2,2,LOC>
                     END ELSE
                        TREE.CNT = TREE.CNT + 1
                        I1 = DCOUNT(OO,'\')
                        FOR I = 1 TO I1
                           O = FIELD(OO,'\',I)
                           LOCATE O IN NODE<2,1,1> BY 'AL' SETTING LOC ELSE
                              NODE = INSERT(NODE,2,1,LOC,O)
                              NODE = INSERT(NODE,2,2,LOC,TREE.CNT)
                              NODE = INSERT(NODE,2,3,LOC,V.FLG)
                           END
                        NEXT I
                        WRITE NODE ON OBJ.FD , NODE.ID
                        NODE.ID = TREE.CNT
                     END
                  CASE ATTR = 3
                     T = FIELD(OO,'\',1)
                     LOCATE T IN NODE<3,1,1> SETTING LOC THEN
                        NODE.ID = NODE<3,2,LOC>
                     END ELSE
                        TREE.CNT = TREE.CNT + 1
                        I1 = DCOUNT(OO,'\')
                        FOR I = 1 TO I1
                           O = FIELD(OO,'\',I)
                           LOCATE O IN NODE<3,1,1> BY 'AL' SETTING LOC ELSE
                              NODE = INSERT(NODE,3,1,LOC,O)
                              NODE = INSERT(NODE,3,2,LOC,TREE.CNT)
                              NODE = INSERT(NODE,3,3,LOC,V.FLG)
                           END
                        NEXT I
                        WRITE NODE ON OBJ.FD , NODE.ID
                        NODE.ID = TREE.CNT
                     END
                  CASE ATTR = 4
                     T = FIELD(OO,'\',1)
                     LOCATE T IN NODE<4,1,1> SETTING LOC THEN
                        NODE.ID = NODE<4,2,LOC>
                     END ELSE
                        TREE.CNT = TREE.CNT + 1
                        I1 = DCOUNT(OO,'\')
                        FOR I = 1 TO I1
                           O = FIELD(OO,'\',I)
                           LOCATE O IN NODE<4,1,1> BY 'AL' SETTING LOC ELSE
                              NODE = INSERT(NODE,4,1,LOC,O)
                              NODE = INSERT(NODE,4,2,LOC,TREE.CNT)
                              NODE = INSERT(NODE,4,3,LOC,V.FLG)
                           END
                        NEXT I
                        WRITE NODE ON OBJ.FD , NODE.ID
                        NODE.ID = TREE.CNT
                     END
                  CASE ATTR = 5
                     NODE<5> = ID
                     WRITE NODE ON OBJ.FD , NODE.ID
                  CASE ATTR = 6
                     NODE<6> = ID
                     WRITE NODE ON OBJ.FD , NODE.ID
                  CASE YES
                     STOP 'PC','Undefined ATTR = ' : ATTR
               END CASE
*
            WHILE OBJ<1,1,C> <> '' DO REPEAT
*
            IF ATTR AND ATTR <> 5 THEN
               READ NODE FROM OBJ.FD , NODE.ID ELSE NODE = ''
               NODE<6> = ID
               WRITE NODE ON OBJ.FD , NODE.ID
            END
*
            LOCATE DATA<1> IN KW.L.F<1> BY 'AL' SETTING L ELSE
               KW.L.F = INSERT(KW.L.F,L,0,0,DATA<1>)
               KW.L = INSERT(KW.L,L,0,0,'')
            END
            LOCATE DATA<2> IN KW.L<1> BY 'AL' SETTING L2 ELSE
               KW.L = INSERT(KW.L,L,L2,0,DATA<2>)
            END
*
            S = ''
            CONT.FLG = NO
            FOR I = 5 TO DCOUNT(DATA,AM)
               T = DATA<I>
               IF TRIM(T)[1,1] # '*' THEN
                  TT = INDEX(T,';*',1)
                  IF TT THEN
                     T = T[1,TT-1]
                  END
                  IF S <> '' AND NOT(CONT.FLG) THEN S = S : SEP.CH
                  CONT.FLG = NO
                  T = T[INDEX(T,TRIM(T)[1,1],1),32000]
                  C = TRIM(T)[LEN(TRIM(T)),1]
                  T = T[1,INDEX(T,C,COUNT(T,C))]
                  IF T[LEN(T),1] = '\' THEN
                     T = T[1,LEN(T)-1]
                     C = TRIM(T)[LEN(TRIM(T)),1]
                     T = T[1,INDEX(T,C,COUNT(T,C))]
                     CONT.FLG = YES
                  END
                  S = S : T
               END
            NEXT I
            CALL PC.PARSE(S,OBJ)
*
            OO = OBJ
            OBJ = ''
            TP = -1
            I1 = DCOUNT(OO<1,1>,SVM)
            FOR I = 1 TO I1
               IF TP < 0 THEN
                  TP = OO<1,2,I>
                  IF TP >= 0 THEN TP = 0
                  OBJ<1,1,-1> = OO<1,1,I>
                  OBJ<1,2,-1> = TP
               END ELSE
                  TP = OO<1,2,I>
                  IF TP >= 0 THEN
                     OBJ<1,1> = OBJ<1,1> : OO<1,1,I>
                  END ELSE
                     OBJ<1,1,-1> = OO<1,1,I>
                     OBJ<1,2,-1> = TP
                  END
               END
            NEXT I
            OBJ = DATA<1> : AM : OBJ
            WRITE OBJ ON OBJ.FD , ID
*
         END
         COUNTER = COUNTER + 1
      REPEAT
*
      KW.L.S = ''
      I1 = DCOUNT(KW.L,AM)
      FOR I = 1 TO I1
         WRITE KW.L<I> ON OBJ.FD , 'KW*' : KW.L.F<I>
         J1 = DCOUNT(KW.L<I>,VM)
         FOR J = 1 TO J1
            LOCATE KW.L<I,J> IN KW.L.S<1> BY 'AL' SETTING LOC ELSE
               KW.L.S = INSERT(KW.L.S,LOC,0,0,KW.L<I,J>)
            END
         NEXT J
      NEXT I
*
      WRITE KW.L.S ON OBJ.FD , 'KW*'
*
      READ C.STR FROM SRC.FD , '*COMMON' THEN
         O = ''
         I1 = DCOUNT(C.STR,AM)
         FOR I = 1 TO I1
            IF TRIM(C.STR<I>)[1,1] <> '*' THEN
               T = C.STR<I>
               T = T[INDEX(T,TRIM(T)[1,1],1),32000]
               CH = TRIM(T)[LEN(TRIM(T)),1]
               T = T[1,INDEX(T,CH,COUNT(T,CH))]
               O = O : SEP.CH : T
            END
         NEXT I
         WRITE O[2,32000] ON OBJ.FD , '*COMMON'
      END
*
      READ C.STR FROM SRC.FD , '*INIT' THEN
         O = ''
         I1 = DCOUNT(C.STR,AM)
         FOR I = 1 TO I1
            IF TRIM(C.STR<I>)[1,1] <> '*' THEN
               T = C.STR<I>
               T = T[INDEX(T,TRIM(T)[1,1],1),32000]
               CH = TRIM(T)[LEN(TRIM(T)),1]
               T = T[1,INDEX(T,CH,COUNT(T,CH))]
               O = O : SEP.CH : T
            END
         NEXT I
         WRITE O[2,32000] ON OBJ.FD , '*INIT'
      END
*
      PRINT
*
      CW = '(C) Copyright 1985-1989 Modular Software.  All rights reserved.'
   END
