Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-03 - 43,50306/ercor.imc
There are 2 other files named ercor.imc in the archive. Click here to see a list.
TWOSEG;
#THIS IS THE IMP PARSER ERROR CORRECTOR, ERCOR.
 CALL ERCOR(OP,NP,S) WHERE OP IS THE FREE STORAGE POINTER TO THE NP
   PREVIOUS PARSES, AND S IS THE LAST SYMBOL READ.  RETURNS THE FREE
   STORAGE POINTER OF AN ARRAY CONTAINING SYMBOLS TO BE INSERTED IN THE
   INPUT STREAM, TERMINATED WITH A 0.
 METHOD IS SIMPLY TO SEARCH FOR A PATH THROUGH SYNTAX GRAPH TO AN S NODE
   WHICH IS ALSO A PLAUSIBLE PATH GIVEN THE CURRENT GOALS.  ALL SUCH PATHS
   CONTAINING LE TPATH TERMINAL SYMBOLS ARE FOUND, AND THE ONE WITH
   THE FEWEST TERMINAL SYMBOLS IS CHOSEN.  IN THE EVENT OF A TIE, THE PATH
   WHICH HAS AT SOME POINT THE SHORTEST LIST OF CURRENT GOALS IS THE WINNER.
 THE CURRENT GOAL LIST IS KEPT IN CGL IN 2-WORD PACKETS (NODE,GOAL).  THE
   STACK ST HOLDS ONE-WORD ENTRIES (NODE OR TYPE LS 33), WHERE THE TYPE IS
   AS FOLLOWS:
              0-3  TYPE OF GRAPH NODE.
              4    INFORMATION FROM GOAL WHICH WAS REACHED.  HOLDS NODE NR.     
                     WHICH CALLED FOR THE GOAL.  WORD ABOVE ON STACK HOLDS
                     NT NR OF GOAL OR BEST WIDTH LS 18.  WORD ABOVE THAT
                     MUST BE TYPE 2 NODE.
              5    NODE ON CHAIN OF TERMINAL ENTRY POINTS TO GRAPH.
 TPATH IS THE LENGTH OF BEST PATH (NR. TERM. SYMBOLS) SO FAR.
 TCUR IS THE LENGTH OF THE CURRENT PATH.
 TERMS IS THE ARRAY CONTAINING THE TERMINAL SYMBOLS.  A NEW ONE IS MADE FOR
   EACH ERROR (SINCE PARSER MAY STILL BE EATING OUT OF THE LAST ONE).
 BWIDTH IS THE MINIMUM GOAL LIST LENGTH ON THE BEST PARSE SO FAR.
 WIDTH IS THE MIMINUM GOAL LIST LENGTH FOR THE CURRENT PATH.

ISNAME(S) - RETURNS 1 IF SYMBOL WITH DIRECTORY INDEX S MAY BE USED AS A SYMBOL
 IN SYNTAX EXTENSIONS, RETURNS 2 IF IT MAY BE USED AS AN IDENTIFIER, RETURNS 0
 OTHERWISE.  (THE MARKS ;:%< ARE NOT SYMBOLS; IDENTIFIERS ARE ALPHANUMERIC.)

AMBIG(P,NP,PN,O,TR) - CHECKS THE ARRAY OF PARSES TO DETERMINE IF THERE ARE ANY
   AMBIGUITIES, AND DECIDES BETWEEN THEM IF THERE ARE.  #

SUBR ERCOR(OP,NP,SS) IS (
 ST=0=>ST_FALLOT('ER/ST',20);
 INIT=0=>(FRELOT(CGL,'ER/CG',20,0); MAXPATH_3;
          PCT_DIR('%'); NAM_DIR('NAM#'); ZER_DIR('0'));
 (INIT_INIT+1)>50=>ERROR(0,'** TOO MANY SYNTAX ERRORS **');
 FINAM IS COMMON; TR_FINAM[5] AND 100B;
 TR=>PRINT /,STG 0,'** ERROR CORRECTOR ENTERED.',/;
 TERMS_-1;
 S_SS;
 NCHARS_0;
NEXTERM:
 PNAME(S); PRINT STG 1,' ';
 MP_1;
 NMP:  BWIDTH_TCUR_PN_IP_0;
 TPATH_MP+1;
 TR=>(PNAME(S); PRINT STG 0,' IS NEW TERMINAL.',/);
NEXTPARSE:
 (PN_PN+1)>NP=>(TERMS>0=>GO TO X;
                (NCHARS_NCHARS+1)>5=>(TIPIT:
                     PRINT /;
                     ERROR(0,'** ERROR CORRECTOR GIVES UP. **'));
                (MP_MP+1) LE MAXPATH=>GO TO NMP;
                S=PCT=>ERROR(0,'** ERROR CORRECTOR GIVES UP AT % **');
                LEX(S); GO TO NEXTERM);
 TR=>PRINT STG 0,'PARSE #',IGR 0,PN,/;
 NST_NCGL_0;
 #MAKE GOAL/NODE LIST FROM PARSE#
 NODE_FREE(OP+IP+1);
 J_FREE(OP+IP) AND 777777B;
 (FADD(CGL,NCGL,FREE(OP+K) RS 18);
  I_FREE(OP+K) AND 777777B; FADD(CGL,NCGL,I);
  TR=>(PRINT STG 0,'  GOAL '; PNAME(GVAL(FREE(OP+K) RS 18));
       PRINT STG 0,' AT NODE #',IGR 0,FREE(OP+K) RS 18,/)) FOR K IN IP+2,1,IP+J;
 CGOAL_I;
 IP_IP+J+1; WIDTH_NCGL;
NEXTNODE: NODE=0=>(TR=>PRINT /; GO TO BACKUP);
 #WALK THE NEXT NODE#
 TY_GTYPE(NODE); VAL_GVAL(NODE);
 TR=>(PRINT STG 0,'NODE #',IGR 0, NODE,STG 0,', TYPE ',IGR 0,TY,STG 0,', ';
      TY =3=>(PRINT '[',IGR 0, VAL,STG 1,']')
               ELSE (PNAME( VAL));
      PRINT STG 0,', ',IGR 0,TCUR,STG 0,' TERMS. SO FAR, STACK ',IGR 0,NST,/);
 GO TO (TYPE0,TYPE1,TYPE2,TYPE3,NEXTNODE,TYPE5) TY;
 TYPE5: TY_3;
 PUSHIT: TYPE3: FADD(ST,NST,NODE OR TY LS 33);
 SCRFWD: NODE_SCR(NODE);
         TR=>PRINT STG 0,'ON TO SCR, ';
         GO TO NEXTNODE;
 TYPE1: VAL=S=>(#FOUND THE TERMINAL SYMBOL#
                FTS: TPATH=TCUR=>WIDTH GE BWIDTH=>GO TO TOOMANY;
                NTERMS_0;
                TERMS<0=>FRELOT(TERMS,'TSYMS',20,0);
                TR=>PRINT STG 0,'** VALID PATH FOUND WITH ',IGR 0,TCUR,
                  STG 0,' TERMINALS, BRANCHING MIN.',IGR 0, WIDTH/2,/;
                NST=>(
                  (J_FREE(ST+I);
                   TR=>PRINT STG 8,' ',OCT 12,J,IGR 6,J AND 777777B,/;
                   (J RS 33)=1=>((J_GVAL(J AND 777777B))=NAM=>J_ZER;
                                 FADD(TERMS,NTERMS,J)))  FOR I TO NST-1);
                FADD(TERMS,NTERMS,S);
                FADD(TERMS,NTERMS,0);
                BWIDTH_WIDTH; TPATH_TCUR;
                GO TO ALTFWD);
        ISNAME(S)=2 => VAL=NAM => GO TO FTS;
        (TCUR_TCUR+1)<TPATH=>GO TO PUSHIT;
        TCUR=TPATH=>WIDTH<BWIDTH=>GO TO PUSHIT;
        TCUR_TCUR-1;
        TOOMANY: TR=>PRINT STG 0,'TOO MANY TERMINALS;';
 ALTFWD: NODE_GNEXT(ALT(NODE),CGOAL);
         TR=>PRINT STG 0,'TRY ALTERNATE ';
         GO TO NEXTNODE;
 TYPE2: GMADE(NODE,CGOAL)=>(NCGL LE 4=>GO TO PUSHIT;
                            FADD(ST,NST,NODE OR 2 LS 33);
                            FADD(ST,NST,CGOAL OR WIDTH LS 18);
                            J_FREE(CGL+NCGL-2);
                            FADD(ST,NST,J OR 4 LS 33);
                            (NCGL_NCGL-2)<WIDTH=>WIDTH_NCGL;
                            CGOAL_FREE(CGL+NCGL-1);
                            NODE_SCR(FREE(CGL+NCGL));
                            TR=>PRINT STG 0,'MADE GOAL, POP TO ';
                            GO TO NEXTNODE);
        GO TO PUSHIT;
 TYPE0: FADD(CGL,NCGL,NODE);
        FADD(CGL,NCGL,(CGOAL_DPROP('NODE',VAL)));
        FADD(ST,NST,NODE);
        TR=>(PRINT STG 0,'NEW GOAL ';PNAME(VAL); PRINT STG 0,'=',IGR 0,
               CGOAL,STG 0,' AT LVL ',IGR 0,NCGL,/);
        NODE_GENTRY(0); GCONN(NODE,CGOAL)=>GO TO NEXTNODE;
        GO TO ALTFWD;

 BACKUP: NST=0=>GO TO NEXTPARSE;
         J_FSUB(ST,NST);
         TY_J RS 33; NODE_J AND 777777B;
         TR=>PRINT 'BACKING UP PAST NODE #',IGR 0,NODE,STG 0,
                ', TYPE ',IGR 0,TY,STG 0,', GOAL #',IGR 0,CGOAL,STG 0,
                ' LVL ',IGR 0,NCGL,/;
         GO TO (BK0,BK1,BK2,BK3,BK4) TY;
 BK0: NCGL_NCGL-2;
      CGOAL_FREE(CGL+NCGL-1);
      GO TO ALTFWD;
 BK1: TCUR_TCUR-1;
 BK3: BK2: GO TO ALTFWD;
 #HERE IS THE MEATY BACKUP - THROUGH A GOAL-REACHED TYPE 2 NODE#
 BK4: FADD(CGL,NCGL,NODE);
      J_FSUB(ST,NST);
      FADD(CGL,NCGL,(CGOAL_J AND 777777B));
      WIDTH_J RS 18;
      J_FREE(ST+NST-1);
      NODE_J AND 777777B; GO TO SCRFWD;
 X: TERMS);

SUBR FSUB (Q,QQ) IS (
 (QQ_QQ-1)<0=>ERROR(0,'** STACK UNDERFLOW IN FSUB **');
 FREE(Q+QQ));

SUBR ISNAME(S) IS (
 ISNIT=0 => (SEM_DIR(';'); COL_DIR(':');
             PCT_DIR('%'); LBR_DIR('<'); ISNIT_1);
 NM=R''''=>RETURN 2;
 NM_DNAME(S,0); NM LS 7 => RETURN 2;
 (NM_NM RS 29) GE 060B => NM LE 071B => RETURN 2;
 (NM_NM AND 137B) GE 101B => NM LE 132B => RETURN 2;
 NZ_1; S=SEM=>NZ_0; S=COL=>NZ_0; S=PCT=>NZ_0; S=LBR=>NZ_0; NZ);

SUBR AMBIG(P,NP,PN,O,TR) IS (
 # COMPARES ALL PAIRS I,J OF PARSES, I<J.  I, J ARE INDICES, NI, NJ ARE NUMBER.#
 A1: I_FORG+P; NI_0; IL_-1;
 A4: NI_NI+1;
     I_I+IL+1;
 A2: NI=PN=>GO TO AX;
     IL_[I] AND 777777B;
     J_I; NJ_NI; JL_IL;
 A3: (NJ_NJ+1)>PN=>GO TO A4;
     J_J+JL+1;
     JL_[J] AND 777777B;
     IL NE JL=>GO TO A3;
     ([I+K] NE [J+K] => GO TO A3) FOR K IN 1,1,IL;
 TR=>PRINT STG 0,'AMBIGUITY FOUND - IDENTICAL PARSES # ',
           IGR 3,NI,STG 0,',',IGR 0,NJ,STG 0,/;
 IO_[I] RS 18; JO_[J] RS 18;
 IT_JT_SAME_0;
 A5: IO=>JO=>(IO_FREE(O+IO); JO_FREE(O+JO);
              (IO RS 18) NE (JO RS 18)=>SAME_1;
              IO<0=>IT_IT+1; JO<0=>JT_JT+1;
              IO_IO AND 777777B; JO_JO AND 777777B;
              GO TO A5);
 (IO OR JO OR SAME)=0=>(TR=>PRINT 'OUTPUTS IDENTICAL'; GO TO OFFJ);
 LONGER_IO-JO;
 A6: IO=>(IO_FREE(O+IO); IO<0=>IT_IT+1; IO_IO AND 777777B; GO TO A6);
 A7: JO=>(JO_FREE(O+JO); JO<0=>JT_JT+1; JO_JO AND 777777B; GO TO A7);
 IT NE JT=>(TR=>PRINT 'MORE TERMINALS'; IT>JT=>GO TO OFFI; GO TO OFFJ);
 LONGER=0=>(ERROR(1,'SYNTACTIC AMBIGUITY.');
	FINAM IS COMMON; FINAM[5]_FINAM[5] OR 40000B; # TURN ON LIST #
	(IO_[I] RS 18)=>(
		PRINT STG 0,' * IDENTIFIERS IN AMBIGUOUS SEGMENT (IN REVERSE ORDER): ',/,' ';
		WHILE IO DO ((IO_FREE(O+IO))<0=>(PNAME(-(IO ARS 18));
					PRINT STG 0,' ');
			IO_IO<R>);
		PRINT /);
	GO TO OFFJ);
 TR=>PRINT 'LONGER'; LONGER>0=>GO TO OFFI;
 OFFJ: I_J; NI_NJ; IL_JL;
 OFFI: TR=>PRINT ', #',IGR 0,NI,STG 0,' DISCARDED.',/;
 # MOVE UP FROM I+IL+1 TO I #
 J_I+(IL_IL+1); JL_FORG+P+NP-1;
 J LE JL =>(8R_I+J LS 18;
            BLT_(2514B LS 24)+JL-IL;
            EXECUTE BLT);
 NP_NP-IL;
 (PN_PN-1)>1=>GO TO A1;
 AX: 0)%%