Google
 

Trailing-Edge - PDP-10 Archives - DEC-20-OT20A-D-MC9 - 2-exercise-libary/test4.alg
There are no other files named test4.alg in the archive.
BEGIN

  ! ALGOL-60 TEST PROGRAM:

    WRITTEN BY:

      R. M. DE MORGAN
      SOFTWARE ENGINEERING (EUROPE)
      DIGITAL EQUIPMENT CO. LTD.
      FOUNTAIN HOUSE
      THE BUTTS CENTRE
      READING RG1 7QN
      ENGLAND.

    COPYRIGHT 1973 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.

    SECTIONS
    --------

    1. DECLARATIONS
    2. CONSTANTS
    3. SIMPLE EXPRESSIONS
    4. COMPLICATED EXPRESSIONS
    5. ARRAY SUBSCRIPTING
    6. OWN VARIABLES
    7. FOR STATEMENTS
    8. LABELS AND SWITCHES
    9. PROCEDURES
   10. STRINGS
   11. INPUT/OUTPUT

    --------;
  ! GLOBAL DECLARATIONS;

  INTEGER I,J,K,L,M,N,SECTNO,SECTMAX; REAL X,Y,Z,P,Q,R;
  LONG REAL F,G,H; BOOLEAN A,B,C;
  STRING S,T,U,V;
  INTEGER ARRAY SECT[1:12], AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA[1:1,1:1,1:1,1:1,1:1];
  SWITCH SW := S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11;

  ! GLOBAL PROCEDURES;

  PROCEDURE PHASE;
  BEGIN
    OWN BOOLEAN B;
    IF (B := NOT B) THEN
    BEGIN
      WRITE("PHASE"); PRINT(SECT[SECTNO],1); WRITE(":[T]BEGIN[T][B]");
    END ELSE
    BEGIN
      WRITE("END[N]");
    END
  END;

  PROCEDURE SECTION;
    GOTO IF (N := SECT[(SECTNO := SECTNO+1)])#0 THEN SW[N] ELSE OUT;

  PROCEDURE ERROR(N); VALUE N; REAL N;
  BEGIN
    SELECT.OUTPUT(-1);
    WRITE("******ERROR"); PRINT(N,2,1);
    WRITE("******[2C]");
    PHASE;
    SECTION
  END;
! SECTION SELECTION;

  SECTMAX := 11;

LIST0:
  WRITE("[C]TYPE IN NOS. OF SECTIONS TO BE EXECUTED, TERMINATED BY A ZERO[C](TYPING JUST A ZERO CAUSES ALL SECTIONS TO BE EXECUTED):[2C]");
  FOR SECTNO := 1 UNTIL SECTMAX DO SECT[SECTNO] := SECTNO;
  SECT[SECTMAX+1] := SECTNO := 0;

LIST1:
  READ(N);
  IF N#0 THEN
  BEGIN
    IF N<0 OR N>SECTMAX OR SECTNO=SECTMAX THEN
    BEGIN
      WRITE("[C]INCORRECT SECTION LIST[C]");
      GOTO LIST0
    END;
    SECT[(SECTNO := SECTNO+1)] := N;
    GOTO LIST1
  END;
  NEWLINE;
  IF SECTNO#0 THEN SECT[SECTNO+1] := 0;
  SECTNO := 0;
  SECTION;
S1:
  BEGIN

    ! SECTION 1: DECLARATIONS;

    INTEGER FOO,BAR; REAL I; LONG REAL J,H;
    BOOLEAN C,B,A;
    STRING U,W;
    ARRAY AA[1:1,1:2,1:3];
    PHASE;
    FOO := 1; K := 2;
    BEGIN
      LONG REAL ARRAY Q[FOO:K];
      IF DIM(Q)#1 OR LB(Q,1)#1 OR UB(Q,1)#2 THEN ERROR(1.1)
    END;
    PHASE
  END;
  SECTION;
S2:
  BEGIN

  ! SECTION 2: CONSTANTS;

    PHASE;
    S := NEWSTRING(230,7);
    OUTPUT(16,S);
    SELECT.OUTPUT(16);
    I := 1; J := +2; K := -273;
    PRINT(I); PRINT(J); PRINT(K); NEWLINE;
    X := 1.0; Y := -3.9&7; Z := 99.3@4;
    PRINT(X); PRINT(Y); PRINT(Z); NEWLINE;
    F := 4.2&&3; H := 7@@3;
    PRINT(F,17); PRINT(H,17); NEWLINE;
    A := TRUE; B := FALSE; C := %103;
    PRINT.OCTAL(A); PRINT.OCTAL(B); PRINT.OCTAL(C); NEWLINE;
    T := "FERRET";
    WRITE(T); NEWLINE;
    T := "THE MOON IS MADE OF GREEN CHEESE";
    WRITE(T); NEWLINE;
    U := "[[[2S];;]]""";
    WRITE(U);
    RELEASE(16);
    IF S#"           1           2        -273
 1.0000000    -3.9000000&  7 9.9300000&  5
 4.20000000000000000&&  3 7.00000000000000000&&  3
%777777777777%000000000000%000000000103
FERRET
THE MOON IS MADE OF GREEN CHEESE
[  ;;]""" THEN ERROR(2.1);
    DELETE(S);
    PHASE
  END;
  SECTION;
S3:
  BEGIN

    ! SECTION 3: SIMPLE EXPRESSIONS;

    INTEGER II,JJ,KK; REAL XX,YY,ZZ;
    LONG REAL FF,GG,HH; BOOLEAN AA,BB,CC;
    PHASE;
    I := 1; J := 2; K := 4; II := I+3;
    IF II#4 THEN ERROR(3.1);
    JJ := I + II*4 - 4; IF JJ#13 THEN ERROR(3.2);
    KK := (JJ-2) DIV 3 + II REM 3;
    IF KK#4 THEN ERROR(3.3);
    KK := KK + II*JJ*(I+J-K) DIV 26;
    IF KK#2 THEN ERROR(3.4);
    KK := 10 DIV 2 + 15 REM JJ;
    IF KK#7 THEN ERROR(3.5);
    X := 2.5; Y := 3.2; Z := 4.0;
    XX := X*Y+Z; IF XX#12.0 THEN ERROR(3.6);
    YY := (Y/Z + Y)/Z - X*Y;
    IF YY#-7.0 THEN ERROR(3.7);
    PHASE
  END;
  SECTION;
S4:
  BEGIN

    ! SECTION 4: COMPLICATED EXPRESSIONS;

    INTEGER II,JJ,KK; REAL XX,YY,ZZ;
    LONG REAL FF,GG,HH; BOOLEAN AA,BB,CC;
    PHASE;
    I := 9; J := 4; K := -16;
    II := I+3+J-4+K+16;
    IF II#12 THEN ERROR(4.1);
    JJ := ((II DIV 3 REM 3)*6 + II - 10)*II + II^(II-10) - II REM  26;
    IF JJ#228 THEN ERROR(4.2);
    X := 2.5; Y := 3.2; Z := 4.0;
    XX := (X*Y + X *Z)/Z + X;
    IF XX#7.0 THEN ERROR(4.3);
    YY := 12.0 - (X*Z/10.0 - 2.0)*(X+Z)*2.0;
    IF YY#25.0 THEN ERROR(4.4);
    F := 1.0&&0; G := 4.0&&0; H := 0.5&&0;
    FF := (F+G)/H;
    IF FF#1&&1 THEN ERROR(4.5);
    GG := F*G + G*H - 1&&0/H;
    IF GG#4.0&&0 THEN ERROR(4.6);
    A := TRUE; B := FALSE; C := %707070;
    AA := A OR B AND C;
    IF NOT AA THEN ERROR(4.7);
    PHASE
  END;
  SECTION;
S5:
  BEGIN

    ! SECTION 5: ARRAY SUBSCRIPTING;

    INTEGER II,JJ,KK; REAL XX,YY,ZZ;
    LONG REAL FF,GG,HH; BOOLEAN AA,BB,CC;
    INTEGER ARRAY A[1:10], B[1:5,6:7];
    LONG REAL ARRAY P[1:50,2:2];
    PHASE;
    FOR I := 1 UNTIL 10 DO A[I] := I;
    FOR I := 1 UNTIL 10 DO IF A[I] DIV I#1 OR A[I] REM I#0
      THEN ERROR(5.1);
    FOR I := 1 UNTIL 5 DO
      FOR II := 6 UNTIL 7 DO B[I,II] := I*II;
    FOR I := 13 STEP -1 UNTIL 12 DO
      FOR II := I+5 STEP -1 UNTIL I+1 DO
	IF B[II-I,I-6]#(II-I)*(I-6) THEN ERROR(5.2);
    PHASE
  END;
  SECTION;
S6:
  BEGIN

    ! SECTION 6: OWN VARIABLES;

    OWN INTEGER II; OWN REAL XX; OWN BOOLEAN BB;
    PHASE;
    IF II#0 OR XX#0 OR BB THEN ERROR(6.1);
    FOR II := 1 UNTIL 10 DO
    BEGIN
      OWN INTEGER ARRAY JJ[1:II, 1:II];
      FOR J := 1 UNTIL II-1 DO
	FOR K := 1 UNTIL II-1 DO
	  IF JJ[J,K]#J+K THEN ERROR(6.2);
      FOR J := 1 UNTIL II DO JJ[J,II] := JJ[II,J] := J+II
    END;
    PHASE
  END;
  SECTION;
S7:
  BEGIN

    ! SECTION 7: FOR STATEMENTS;

    INTEGER J,K;
    REAL Z;
    LONG REAL LR3,LR4;
    PROCEDURE PARFOR(I1,I2,R1,R2,R3,LR1,LR2);
      INTEGER I1,I2; REAL R1,R2,R3; LONG REAL LR1,LR2;
    BEGIN
      INTEGER II; REAL RR; LONG REAL LL;
      I := I1-1;
      FOR II := I1 UNTIL 100 DO
      BEGIN
	I := I+1;
	IF II#I THEN ERROR(7.1)
      END;
      I := I1+1;
      FOR II := I1 STEP -1 UNTIL I2 DO
      BEGIN
	I := I-1;
	IF II#I THEN ERROR(7.2)
      END;
      X := R2;
      FOR R1 := R2 STEP R3 UNTIL R2+100 DO
      BEGIN
	IF R1#X THEN ERROR(7.3);
	X := X+R3
      END;
      F := LR2;
      FOR LR1 := LR2 STEP LR3 UNTIL LR4 DO
      BEGIN
	IF LR1#F THEN ERROR(7.4);
	F := F+LR3
      END
    END;
    PHASE;
    J := 3; K := -100;
    Z := 2.0; LR4 := 1.0&&0;
    PARFOR(J,K,Z,1.0,Z,LR3,LR4);
    PHASE
  END;
  SECTION;
S8:
  BEGIN

    ! SECTION 8: LABELS AND SWITCHES;

    PHASE;
      FOR M := 1 UNTIL 1000 DO
      BEGIN
	INTEGER N;
	FORWARD L;
	PROCEDURE P(L); LABEL L;
	BEGIN
	  PROCEDURE Q(L); LABEL L; GOTO L;
	J:IF (N := N-1) > 0 THEN P(J) ELSE Q(L)
	END;
	N := 10;
	P(L);
      L:
      END;

      FOR M := 1 UNTIL 1000 DO
      BEGIN
	INTEGER N;
	FORWARD L1,L2;
	SWITCH S := L1,L2;
	PROCEDURE P(L); LABEL L;
	BEGIN
	  GOTO L;
	  N := N+1; GOTO L
	END;
	PROCEDURE Q(S); SWITCH S; P(S[N]);
	N := -1;
      L1:
	N := N+1;
	Q(S);
      L2:
      END;
    PHASE
  END;
  SECTION;
S9:
  BEGIN

    ! SECTION 9: PROCEDURES;

    INTEGER PROCEDURE GPPS(K,N,V,Z); INTEGER K,N,V,Z;
    BEGIN
      FOR K := 1 UNTIL N DO V := Z;
      GPPS := 1
    END;
    PROCEDURE S; M := I;
    PROCEDURE P(Q); PROCEDURE Q;
    BEGIN
      INTEGER K;
      PROCEDURE R; I := I+K;
      IF (K := J := J+1) = 1 THEN P(R);
      Q
    END;

    PHASE;
    M := 100;