Google
 

Trailing-Edge - PDP-10 Archives - decus_20tap2_198111 - decus/20-0068/rsyn.imc
There are 2 other files named rsyn.imc in the archive. Click here to see a list.
TWOSEG;
#THIS IS FILE RSYN.I10, THE BOOTSTRAP READER FOR INITIAL IMP SYNTAX.

THE FOLLOWING IS AN APOLOGY FOR A CLUMSY JOB OF CODING, DISGUISED AS AN
  EXPLANATION.  THE SYNTAX AND SEMANTICS FOR SYNTAX WAS THE FIRST SYNTAX
  I CODED, AND THE JOB OF DOING THE SEMANTICS FOR THE SEMANTIC PART OF
  SYNTAX STATEMENTS WAS BROKEN UP IN A HIGHLY ILLOGICAL WAY, BASED ON
  THE FACT THAT THE INDEX OF THE SEMANTICS HAD TO BE KNOWN BEFORE THE
  SEMANTICS WAS SEEN SO THAT IT COULD BE ENTERED AS THE PRODUCTION
  NUMBER IN THE SYNTAX GRAPH.  THIS REQUIREMENT MEANT THAT SETSEM(0,NNA LS 18)
  HAD TO BE CALLED BEFORE THE SEMANTICS WAS EVEN PARSED, TO GET THAT NUMBER.
  SO ROUTINES TO GENERATE SEMANTICS EXPECT THAT CALL TO HAVE BEEN MADE BEFORE
  THEY START ON THE SEMANTICS.  THUS EVERY ROUTINE TO PROCESS AN INSTANCE
  OF SEMANTICS (EXCEPT SEMANTICS()) CALLS SETSEM(0,NNA LS 18) BECAUSE IT
  MAY BE FOLLOWED BY ANOTHER INSTANCE OF SEMANTICS WHICH EXPECTS THAT CALL
  TO HAVE BEEN MADE.  THIS LEADS TO THE EXISTENCE OF THE FOLLOWING:

     SEMN = THE INDEX OF THE FIRST SEMANTICS TO COME FROM THIS PRODUCTION.
            IT IS THE PRODUCTION NUMBER IN THE SYNTAX GRAPH AND ITS ENTRY
            IN SEMS HOLDS THE NUMBER OF ARGUMENTS FOR THE PRODUCTION (NNA
            IN RSYN).  THIS SEMANTICS MAY BE A DUMMY AND NOT HAVE ANY REAL
            SEMANTICS ATTACHED TO IT (IF THE FIRST SEMANTICS GENERATED CAN'T
            STAND HAVING THAT MANY ARGUMENTS, FOR INSTANCE).
     SEMK = THE INDEX OF THE SEMANTICS CURRENTLY BEING GENERATED.
     PRODN= THE PRODUCTION NUMBER UNDER WHICH THE CURRENT SEMANTICS IS TO
            BE ENTERED IN THE CODE GENERATION TREE BY ENTREE.  PRODN=SEMN
            EXCEPT WHEN DEFINING A "CASE OF" SEMANTICS, WHERE PRODN IS SET
            TO SOME UNIQUE SEMS INDEX TO IDENTIFY THE CASE.      #

SUBR RSYN(TR) IS (
 GO TO RSYNLO;
 RSYNLO IS COMMON;
REMOTE ( RSYNLO: # THIS SPACE IN LOW SEGMENT WILL BE USED FOR
			PRINT BUFFERS IN PMOD. #
 LOC(QUIT)-LOC(RSYNLO)<280=>RSERR(-1);
 STP_STINIT(0);
 FRELOT(RST,'RSYN',23,0); NRST_NSPARS_0;
 FRELOT(NA,'RSYN2',12,0);
 SEMI_DIR(';'); LBR_DIR('<'); RBR_DIR('>'); PCT_DIR('%');
 EQS_DIR('=');  COMMA_DIR(','); QUO_DIR('"');
 LPAR_DIR('('); RPAR_DIR(')'); COLON_DIR(':');
 SEMK_SETSEM(0,0);
 NAM_DIR('NAM'); NAMM_DIR('NAM#');
 SYM_DIR('SYM'); SYMM_DIR('SYM#');
 DPROPS('SEM',DIR('CASE'),LOC(CASE));
 DSEM('DEFCASE',DEFCASE);
 DSEM('QUOSEM',QUOSEM);
 DSEM('EQUOSE',EQUOSE);
 DSEM('SEMBIT',SEMBIT);
 DSEM('SYTRM',SYTRM);
 DSEM('SYNTS',SYNTS);
 DSEM('SEMANTICS',SEMANTICS);
 DSEM('SYNTAX',SYNTAX);
 DSEM('SEMR',SEMR);
 DSEM('SEMP',SEMP);
 DSEM('SYNT',SYNT);
 DSEM('ENSTACK',ENSTACK);
 DSEM('VALU',VALU);
 DSEM('REPVAL',REPVAL);
 NEXT: NL_NP_0;
 STINIT(0);
 CL_LEX(J);
 J NE LBR => RSERR(1);
 SYNT(STX(J),0);
 CL_LEX(J); J NE RBR => RSERR(2);
 CL_LEX(J); J NE COLON => RSERR(3);
 CL_LEX(J); J NE COLON => RSERR(4);
 CL_LEX(J); J NE EQS => RSERR(5);
 NSYMB:
 CL_LEX(J);
 GNSYMB: J=LBR=>(CL_LEX(J); K_SETSTK(2,1 OR J LS 18,0,0);
                 CL_LEX(J); J NE COMMA => RSERR(6);
                 SYNT(K,STX(J));
                 CL_LEX(J); J=RBR=>GO TO NSYMB; RSERR(7));
 J=SEMI=>(SYNTAX(0); GO TO NEXT);
 J=PCT=>(SYNTAX(0); GO TO QUIT);
 J NE COLON => (
    CL_LEX(JJ); JJ=QUO=>(J NE NAM=>(J NE SYM=>GO TO L11);
                      SYNTS(-J);
                      GO TO NSYMB);
    L11: SYTRM(SETSTK(1,1 OR J LS 18,0,0));
    J_JJ; GO TO GNSYMB);
#HAVE THE SYNTAX - DO THE SEMANTICS. #
 SYNTAX(1);
 CL_LEX(J); J NE COLON=>RSERR(8);
 CL_LEX(J); J NE EQS=>RSERR(9);
 CL_LEX(J); JJ_SETSTK(1,1 OR J LS 18,0,0);
 CL_LEX(J); J NE LPAR=>RSERR(10);
 CL_LEX(J); J=RPAR=>(SEMR(JJ,0); GO TO L10);
 SEMR(JJ,1);
 L14: SEMP(SETSTK(1,1 OR J LS 18,0,0),0);
      CL_LEX(J); J=COMMA=>(CL_LEX(J); GO TO L14);
 J NE RPAR=>RSERR(11);
 SEMP(0,1);
 L10: CL_LEX(J); J NE SEMI=>(J NE PCT=>RSERR(12));
 SEMANTICS(0);
 J=SEMI=>GO TO NEXT;
 QUIT: CL_LEX(J); J NE PCT=>RSERR(13);
 RETURN 0);
 0);

SUBR RSERR(N) IS (
 PLINE1(CL);
 MSG('?ERROR IN INITIAL SYNTAX');
 CALLI(12B,0));
SUBR STX(J) IS (CL_LEX(J); SETSTK(1,1 OR J LS 18,0,0));
SUBR ADDCHAR(S,C) IS (
 CC_C;
 FOO IS 11 LONG; NF_0;
 L6: FOO[NF]_CC OR (CCC_DNAME(S,NF)) RS 7;
     (CC_CCC AND 377B)=>((NF_NF+1)>9=>
                           ERROR(1,'IN ADDCHAR - NAME > 50 CHARACTERS **');
                         CC_CC LS 28; GO TO L6);
 FOO[NF+1]_0;
 DIR(FOO));
SUBR SYTRM(A) IS SYNT(SYTERM(A),-1);
SUBR SYTERM(S) IS ( #IF S IS A SINGLE QUOTED CHARACTER, REMOVES QUOTE. #
 R_FREE(S); Q_R RS 18;
 Q_DNAME(Q<R>,0);
 (Q AND 774017777777B)=234000000000B=>(Q_DIR(Q LS 7);
                                       FREES(S,(R AND 777777B) OR Q LS 18));
 S);
SUBR SYNT(A,B) IS (
 # SEMANTIC ROUTINE TO ADD A SYNTAX ELEMENT TO DEFINITION BEING BUILT. #
 SNIT=0=>(FRELOT(SN,'SYNTX',25,0);
          SNIT_1;
          SNITT_0);
 (Q_B)>0=>(Q_FREE(SYTERM(B)); Q_Q RS 18);
 R_FREE(A); R_R RS 18;
 B<0=>GO TO L17;  # SKIP ALL THIS IF TERMINAL SYMBOL #
 SNITT=0=>(#INITIALIZE FOR ONE PRODUCTION#
           NSN_SEMN_SMIT_0; NNA_-1;
           SNITT_1);
 R_ADDCHAR(R,'#');
 NNA GE 0=>FADD(NA,NNA,Q) ELSE NNA_0;
 L17: FADD(SN,NSN,R);
 A);
SUBR SYNTS(N) IS (
 FADD(SN,NSN,DIR(21400B OR DNAME(-N,0)));
 FADD(NA,NNA,-1);
 0);
SUBR SEMANTICS() IS (
#SETSEM(1,0); #
 # JUST IN CASE WE HAVE VAL/"STUFF", CALL SEMFX1 WHICH PATCHES IT #
 SEMFX1(SEMK,NA,NNA);
 # ENTER PRODUCTION IN CODE TREE #
 NNA=>(FREES(RST+I,-FREE(NA+I)) FOR I TO NNA-1);
 FREES(RST+NNA,SEMN);
 FREES(RST+NNA+1,0);
 ENTREE(RST,SEMN,SEMK,PRODN);
 SEMK_SETSEM(0,NNA LS 18);
 0);
SUBR FORMARG(I) IS ( # TESTS IF I IS DIR INDEX OF A FORMAL ARG OF SYNTAX #
 VAL_0;
 NNA=>((J_FREE(NA+K); J=I=>VAL_1) FOR K FROM NNA-1);
 VAL);
SUBR SYNARG(I) IS # RETURNS NAME OF I-TH FORMAL ARG. OF SYNTAX # FREE(NA+I);
SUBR DEFCASE(N) IS (
 CAS=>ERROR(1,'NESTED CASE DEFINITIONS ILLEGAL **');
 CAS_FREE(N); CAS_CAS RS 18;
 SEMK=SEMN=>SEMK_SETSEM(0,NNA LS 18);
 PRODN_SEMK;
 DPROP('SEM',CAS)=>
     ERROR(1,'CASE DEFINED TWICE OR SAME NAME AS SEMANTIC ROUTINE **');
 DPROPS('SEM',CAS,PRODN);
 0);
SUBR CASE(A,F) IS (
 F=>(CAS_0; PRODN_SEMN; SEMK_SETSEM(0,NNA LS 18));
 S_ENSTACK(0);
 L27: GETLIST(S)=>(K_GETARG(S);
                   TY=2=>ERROR(1,'CANT USE NONTERMINALS IN CASE ARG LIST');
                   SETSEM(10B,K);
                   GO TO L27);
# SETSEM(1,0);#
 J_FREE(A);
 DOCASE(J RS 18,SEMK,SEMN);
 ENTRCA(SEMN);
 SEMK_SETSEM(0,NNA LS 18);
 A);
SUBR QUOSEM(A) IS (
 # ENTER CONDITIONAL PRODUCTION IN CODE TREE, THEN REINITIALIZE SOME
   THINGS FOR NEXT PRODUCTION TO FOLLOW IN SAME SEMANTICS. #
#SETSEM(1,0); #
 SEMFIX(SEMK,ENTREE(FREE(A+1),SEMN,SEMK,PRODN));
 SEMK_SETSEM(0,NNA LS 18);
 FALLOT(FREE(A+1),0);
 A);
SUBR EQUOSE(A) IS (
 # ENTER SEMANTICS FOR QUOTED SEMANTICS IN SEMS. #
 # FIRST CHECK FOR LOCAL VARIABLES - THEY GET FUNNY NEG. ENTRIES :
      -(VAR. NR. LS 18 OR DIR INDEX) FIRST TIME; AFTER, LEAVE OFF DIR. INDEX #
 T_ENSTACK(0); I_0;
 L19: GETLIST(T)=>(I_I+1;
   N_FREE(T); N_-(N RS 18);
   J_FREE(A+1); NN_0;
   L20: K_FREE(J); K=>(K=N=>(NN=0=>(NN_1; FREES(J,-(-N OR I LS 18)))
                              ELSE FREES(J,-(I LS 18)));
                       J_J+1; GO TO L20);
   GO TO L19);
 J_FREE(A+1); J_J-1;
 L18: J_J+1; K_FREE(J);
 K=>(K<0=>NNA=>((JJ_FREE(NA+I);
                 JJ=K=>(SETSEM(7,I); GO TO L18);
                 JJ=-K=>(SETSEM(6,I); FREES(NA+I,K); GO TO L18))
                                                        FOR I TO NNA-1);
     SETSEM(5,007777777777B AND -K);
     GO TO L18);
 NNA=>((JJ_FREE(NA+I);
        JJ<0=>FREES(NA+I,-JJ)) FOR I TO NNA-1);
 FALLOT(FREE(A+1),0);
 A);
SUBR SEMP(A,B) IS (
 B=>(NRST_NRST-1;
     J_FREE(RST+NRST);
     SETSEM(3,(J AND 777777B) OR NSARGS LS 18);
     NSARGS_1+J RS 18;
     GO TO SEMPX);
 NSARGS_NSARGS+1;
 Q_GETARG(SYTERM(A));
 SETSEM(TY,Q);
 SEMPX: 0);
SUBR GETARG(A) IS ( # MAKE SEMS ENTRY FOR IDENTIFIER, CONSTANT OR ARGUMENT. #
 Q_FREE(A); Q_Q RS 18;
 TY_4;
 J_CONVC(Q);
 J=>(Q_007777777777B AND -CONST; CONST IS COMMON; GO TO L13);
 NNA=>((J_FREE(NA+R);
        J=Q=>(Q_R; TY_2; GO TO L13)) FOR R TO NNA-1);
 L13: Q);
SUBR SEMR(A,B) IS (
 A=0=>(SETSEM(B,0); NSARGS_NSARGS-1; GO TO SEMRX);
 Q_FREE(A);
 Q_DPROP('SEM',Q RS 18);
 Q=0=>(J_FREE(A); PNAME(J RS 18); PRINT STG 0,' ';
       ERROR(1,'UNDEFINED SEMANTIC ROUTINE'));
 B=>(FADD(RST,NRST,Q OR NSARGS LS 18); NSARGS_0) ELSE(SETSEM(3,Q);
                                                      NSARGS_NSARGS+1);
 SEMRX: A);
SUBR SYNTAX(N) IS (N=2=>(SEMK=SEMN=>SEMK_SETSEM(0,NNA LS 18);
                         GO TO SYNXX);
                   SEMN_0;
                   (N OR NNA-1)=>(SEMN_PRODN_SEMK;
                                  RESETSEM(NNA,SEMK);
                                  N=0=>SEMANTICS(0));
                   PRODN_SEMN_GRAPH(SN,NSN-1,SEMN);
                   GMATR(0);
                   SNITT_0;
                   SYNXX: 0);
SUBR SEMBIT(A) IS (
 # SETS PRIORITY BITS FOR A PRODUCTION #
 J_FREE(A); CONVC(J RS 18);
 SEMOR(CONST LS 27,SEMN);
 0);

SUBR REPVAL(S,A) IS (
 J_FREE(S); J_DPROP('SEM',J RS 18);
 K_FREE(A+1);
 L44: I_FREE(K);
      I>0=>CKSVAL(I AND 777777B,J)=>FREES(K,J OR I LS 18);
      K_K+1;
      I=>GO TO L44;
 A);
SUBR VALU(N,S) IS (
 K_FREE(S); K_K RS 18;
 JJ_J_DPROP('SEM',K);
 JJ=0=>(J_SEMK+2; DPROPS('SEM',K,J));
 K_FREE(N); K_K RS 18;
 CONVC(K)=0=>ERROR(1,'VALUE NOT A CONSTANT **');
 SETSEM(12B,7777777777B AND J OR CONST LS 18); CONST IS COMMON;
 JJ=0=>SETSEM(0,NNA LS 18);
 0)%%