LL1PRC: PROC; /**************************************************************** * LL(1) GRAMMAR ANALYZER - COMMON PROCEDURES * *PURPOSE: * * THIS PROGRAM CONTAINS THE COMMON PROCEDURES USES BY * * MOST OF THE OTHER PHASES. * *INPUT: * *OUTPUT: * *OUTLINE: * *REMARKS: * ****************************************************************/ /**************************************************************** * * * * * * * * * * * COMMON DATA DEFINITIONS * * * * * * * * * * ****************************************************************/ /* * * * COMMON REPLACEMENTS * * * */ %REPLACE TRUE BY '1'B; %REPLACE FALSE BY '0'B; %INCLUDE 'LL1CMN.DCL'; /* GET COMMON AREAS. */ /**************************************************************** * * * * * * * * * * * COMMON PROCUDURES * * * * * * * * * * * * * ****************************************************************/ /********************* CHR_TO_NUM ******************************/ CHRNUM: PROC (L) RETURNS(BIN(15)) EXTERNAL; /* THIS ROUTINE IS RESPONSIBLE FOR CONVERTING A CHARACTER */ /* TO A BINARY NUMBER. */ DCL J BIN(15); /* LOOP INDEX */ DCL K BIT(16); /* INTERMEDIATE BIT VALUE */ DCL L CHAR; /* INTERMEDIATE CHAR VALUE */ DCL M BIT(8); M=UNSPEC(L); K='0000'B4; SUBSTR(K,9,8)=M; UNSPEC(J)=K; /* RETURN TO CALLER WITH CHARACTER. */ RETURN(J); END CHRNUM; /********************* CLOSURE ******************************/ CLOSUR: PROC(ARRAY_PTR) EXTERNAL; /*THIS ROUTINE IS RESPONSIBLE FOR CALCULATING THE REFLEXIVE */ /*TRANSITIVE CLOSURE OF THE ARRAY SPECIFIED. */ DCL I FIXED; /* INDICES */ DCL J FIXED; DCL K FIXED; DCL LIMIT FIXED; DCL ARRAY_PTR PTR; /* PUT IN THE IDENTITY MATRIX. */ LIMIT=LENGTH(NTRM)+LENGTH(TRM); DO I=1 TO LIMIT; CALL SETBIT(I,I,ARRAY_PTR); END; /* COMPUTE THE REFLEXIVE TRANSITIVE CLOSURE. */ DO I=1 TO LIMIT; DO J=1 TO LIMIT; IF TSTBIT(J,I,ARRAY_PTR) THEN DO K=1 TO LIMIT; IF TSTBIT(J,K,ARRAY_PTR) | TSTBIT(I,K,ARRAY_PTR) THEN CALL SETBIT(J,K,ARRAY_PTR); END; END; END; /* RETURN TO CALLER. */ END CLOSUR; /********************* IS_NTRM ******************************/ ISNTRM: PROC (X) RETURNS(BIT(1)) EXTERNAL; /* THIS ROUTINE INDICATES IF A VOCABULARY ELEMENT IS */ /* A NON-TERMINAL. */ DCL X CHAR; /* INPUT INDEX */ DCL I FIXED; /* INTERNAL INDEX */ IF LENGTH(NTRM)=0 THEN RETURN(FALSE); DO I=1 TO LENGTH(NTRM); IF X=SUBSTR(NTRM,I,1) THEN RETURN(TRUE); END; RETURN(FALSE); END ISNTRM; /********************* IS_NLNTRM ******************************/ ISNLNT: PROC (X) RETURNS(BIT(1)) EXTERNAL; /* THIS ROUTINE INDICATES IF A VOCABULARY ELEMENT IS */ /* A NULLABLE NON-TERMINAL. */ DCL X CHAR; /* INPUT INDEX */ DCL I FIXED; /* INTERNAL INDEX */ IF LENGTH(NLNTRM)=0 THEN RETURN(FALSE); IF ISNTRM(X)=FALSE THEN /*NOT A NON-TERMINAL*/ RETURN(FALSE); DO I=1 TO LENGTH(NLNTRM); IF X=SUBSTR(NLNTRM,I,1) THEN RETURN(TRUE); END; RETURN(FALSE); END ISNLNT; /********************* IS_TRM ******************************/ ISTRM: PROC (X) RETURNS(BIT(1)) EXTERNAL; /* THIS ROUTINE INDICATES IF A VOCABULARY ELEMENT IS TERMINAL. */ DCL X CHAR; /* INPUT INDEX */ DCL I FIXED; /* INTERNAL INDEX */ IF LENGTH(TRM)=0 THEN RETURN(FALSE); DO I=1 TO LENGTH(TRM); IF X=SUBSTR(TRM,I,1) THEN RETURN(TRUE); END; RETURN(FALSE); END ISTRM; /********************* MULTREL ******************************/ MULREL: PROC EXTERNAL; /*THIS ROUTINE IS RESPONSIBLE FOR MULTIPLYING TWO RELATION- */ /*SHIPS TOGETHER. */ DCL I FIXED; /* INDICES */ DCL J FIXED; DCL K FIXED; DCL LIMIT FIXED; DCL ARRAY_PTR PTR; DCL ARRAY3(256,32) BIT(8) BASED(ARRAY_PTR); /* DO INITIALIZATION. */ LIMIT=LENGTH(NTRM)+LENGTH(TRM); /*GET ARRAY SIZE.*/ ALLOCATE ARRAY3 SET(ARRAY_PTR); CALL ZEROAR(ARRAY_PTR); /* MULTIPLY ARRAY1 BY ARRAY2. */ DO J=1 TO LIMIT; DO I=1 TO LIMIT; IF TSTBIT(I,J,ADDR(ARRAY1)) THEN DO K=1 TO LIMIT; IF TSTBIT(J,K,ADDR(ARRAY2)) THEN CALL SETBIT(I,K,ARRAY_PTR); END; END; END; /* PUT THE PRODUCT BACK IN ARRAY1. */ DO I=1 TO LIMIT; DO J=1 TO 32; ARRAY1(I,J)=ARRAY3(I,J); END; END; FREE ARRAY3; /* RETURN TO CALLER. */ END MULREL; /********************* NUM_TO_CHR ******************************/ NUMCHR: PROC (J) RETURNS(CHAR) EXTERNAL; /* THIS ROUTINE IS RESPONSIBLE FOR CONVERTING A BINARY*/ /* NUMBER TO A CHARACTER.*/ DCL J BIN(15); /* LOOP INDEX */ DCL K BIT(16); /* INTERMEDIATE BIT VALUE */ DCL L CHAR; /* INTERMEDIATE CHAR VALUE */ UNSPEC(K)=J; UNSPEC(L)=SUBSTR(K,8,8); /* RETURN TO CALLER WITH CHARACTER. */ RETURN(L); END NUMCHR; /********************* PRINT_ARRAY ******************************/ PRTARY: PROC(HEADING,PHS,HORNUM,VERNUM,ARRAY_PTR) EXTERNAL; /*THIS ROUTINE IS RESPONSIBLE FOR PRINTING THE RELATION */ /*DEFINED BY ARRAY1. */ DCL I BIN(15); /* INDEXES */ DCL J BIN(15); DCL COL_FROM FIXED; DCL COL_TO FIXED; DCL LIN_FROM FIXED; DCL LIN_TO FIXED; DCL HEADING CHAR(40) VARYING; DCL PHS BIT(1); /* PRINT HORIZONTAL SYMBOL FLAG */ DCL HORNUM FIXED; /* NUMBER OF HORIZONTAL LINES */ DCL VERNUM FIXED; /* NUMBER OF VERTICAL LINES */ DCL ARRAY_PTR PTR; /* PRINT HEADING. */ PRINT_HDNG: PROC(COL_FROM,COL_TO); DCL I FIXED; DCL J FIXED; DCL COL_FROM FIXED; DCL COL_TO FIXED; DCL LINE_OUT CHAR(130) VARYING; /* PRINT STANDARD HEADER. */ PUT FILE(LSTFIL) PAGE; PUT FILE(LSTFIL) SKIP(3) EDIT(HEADING,'PAGE',PAGENO(LSTFIL)-1) (X(15),A(37),X(10),A(4),F(4)); PUT FILE(LSTFIL) SKIP(1); /* PRINT LINES OF SYMBOL NUMBERS FOR HORIZONTAL. */ I=100; DO WHILE(I>0); LINE_OUT=''; DO J=COL_FROM TO COL_TO; IF J