home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / m2t-2.zip / ANSWERS / CH07E2.MOD < prev    next >
Text File  |  1989-01-18  |  2KB  |  85 lines

  1.                             (* Chapter 7 - Programming exercise 2 *)
  2.                                          (* Chapter 7 - Program 2 *)
  3. MODULE CH07E2;              (* More program construction examples *)
  4.  
  5. FROM InOut IMPORT WriteString, WriteLn;
  6.  
  7. CONST MainC = 27;
  8. TYPE  MainT = ARRAY[3..7] OF CARDINAL;
  9. VAR   MainV : MainT;
  10.  
  11.      PROCEDURE Proc1;
  12.      CONST Proc1C = 33;
  13.      TYPE  Proc1T = ARRAY[-23..-15] OF CHAR;
  14.      VAR   Proc1V : MainT;
  15.            Proc11 : Proc1T;
  16.            ErrorVariable : Proc2T; (* Illegal type reference *)
  17.      BEGIN
  18.        WriteString("Procedure 1");
  19.        Proc2T[4,-2] := TRUE;       (* Illegal variable reference *)
  20.        WriteLn;
  21.      END Proc1;
  22.  
  23.      PROCEDURE Proc2;
  24.      CONST Proc2C = 22;
  25.      TYPE  Proc2T = ARRAY[3..5],[-4..0] OF BOOLEAN;
  26.      VAR   Proc2V : MainT;
  27.            Proc21 : Proc2T;
  28.           PROCEDURE Proc3;
  29.           CONST Proc3C = -234;
  30.           TYPE  Proc3T = ARRAY[12..13] OF MainT;
  31.           VAR   Proc3V : MainT;
  32.                 Proc31 : Proc2T;
  33.                 Proc32 : Proc3T;
  34.           BEGIN
  35.             WriteString("Procedure 3");
  36.             WriteLn;
  37.           END Proc3;
  38.  
  39.           PROCEDURE Proc4;
  40.           CONST Proc4C = 111;
  41.           TYPE  Proc4T = CARDINAL;
  42.           VAR   Proc4V : MainT;
  43.                 Proc41 : Proc2T;
  44.                 Proc42 : Proc4T;
  45.                PROCEDURE Proc5;
  46.                CONST Proc5C = "A";
  47.                TYPE  Proc5T = ARRAY[22..222] OF CHAR;
  48.                VAR   Proc5V : MainT;
  49.                      Proc51 : Proc2T;
  50.                      Proc52 : Proc4T;
  51.                      Proc53 : Proc5T;
  52.                BEGIN
  53.                  WriteString("Procedure 5");
  54.                  WriteLn;
  55.                END Proc5;
  56.           BEGIN
  57.             WriteString("Procedure 4");
  58.             WriteLn;
  59.             Proc5;
  60.             Proc3;
  61.           END Proc4;
  62.      BEGIN
  63.        WriteString("Procedure 2");
  64.        WriteLn;
  65.        Proc3;
  66.        Proc4;
  67.      END Proc2;
  68.  
  69. BEGIN
  70.   WriteString("Main Program");
  71.   WriteLn;
  72.   Proc2;
  73.   Proc1;
  74. END CH07E2.
  75.  
  76.  
  77.  
  78.  
  79. (* Result of execution
  80.  
  81. (Compile errors, will not compile or run)
  82.  
  83. *)
  84.  
  85.