         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program Name : JUMP
    2  
    3  !*   Title      :  X  The IMP Control Transfer Statements.
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Testing of the  ->,  %SWITCH and %LABEL Statements.
    7  
    8  %Begin
    9  
   10      %string(255) param    { Used to get input from CLI}
   11  
   12      %Integer  J
   13      %Integer  K
   14   
   15      %Integer  Error
   16      %Integer  Up
   17      %Integer  Down
   18  
   19  
   20      %Switch  SW (100 : 355)    { Non-zero base switch with lot of switches.
   21  
   22      %Label   Alpha
   23      %Label   Beta
   24      %Label   Gamma
   25      %Label   Delta
   26      %Label   Out
   27      %Label   Cont
   28  
   29  
   30  %owninteger failures=0
   31  
   32  %routine pass
   33    printstring("Pass")
   34    New Line
   35  %end
   36  %routine fail
   37    printstring("FAIL")
   38    New Line
   39    failures = failures+1
   40  %end
   41  
   42  
   43  
   44     ! Code to find out where the output is to be sent
   45     ! -----------------------------------------------
   46     ! Where the output goes to depends on the parameter after the
   47     ! name used to run the program.
   48     !                       Parameter   |   Result
   49     !                       ------------|-------------
   50     !                     No parameter  |  No output
   51     !                          "s"      |  The screen
   52     !                          "j"      |  "journal"
   53     !                     anything else |  file name entered
   54  
   55     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
   56     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
   57  
   58     param=cliparam
   59     %if param = "" %then select output (2) %c
   60+    %else %if param="s" %or param="S" %then select output(1) %c
   61+    %else %if param="j" %or param="J" %then  %c
   62+       open output(2,"journal") %and select output (2) %c
   63+    %else open output(2,param) %and select output (2)
   64     
   65  
   66  
   67     New Lines(2)
   68     Print String ("Control Transfer Statements");   New Line
   69     Print String ("===========================");   New Lines (3)
   70  
   71  
   72      Print String ("Test the -> Statement and %Switch");   New Line
   73      Print String ("---------------------------------");   New Line
   74  
   75      Up = 0
   76      Down = 0
   77  
   78      -> Delta
   79  
   80      Alpha:  Up   = Up   + 1;  -> Gamma
   81      Beta:   Down = Down + 1;  -> Out
   82      Gamma:  Up   = Up   + 1;  -> Beta
   83      Delta:  Down = Down + 1;  -> Alpha
   84      Out:
   85           %If Up = Down = 2 %then pass %else fail
   86  !            Forward and Backward simple jumps.
   87  
   88  
   89  
   90      Up    = 100
   91      Error = 0
   92  
   93      %For J = 990, 10, 3540 %cycle 
   94  
   95          -> SW (J // 10 + 1)   { Introduces an integer expression in the switch
   96   
   97     
   98          SW(140):   Error = Error + 1 %unless Up = 140
   99                     -> Cont
  100  
  101          SW(255):   Error = Error + 1 %unless Up = 255
  102                     -> Cont
  103  
  104          SW(105):   Error = Error + 1 %unless Up = 105
  105                     -> Cont
  106  
  107          SW(304):   Error = Error + 1 %unless Up = 304
  108                     -> Cont
  109  
  110          SW(182):   Error = Error + 1 %unless Up = 182
  111                     -> Cont
  112  
  113          SW(354):   Error = Error + 1 %unless Up = 354
  114                     -> Cont
  115  
  116          SW(111):   Error = Error + 1 %unless Up = 111
  117                     -> Cont
  118  
  119          SW(193):   Error = Error + 1 %unless Up = 193
  120                     -> Cont
  121  
  122          SW(121):   Error = Error + 1 %unless Up = 121
  123                     -> Cont
  124  
  125          SW(201):   Error = Error + 1 %unless Up = 201
  126                     -> Cont
  127  
  128          SW(296):   Error = Error + 1 %unless Up = 296
  129                     -> Cont
  130  
  131          SW(160):   Error = Error + 1 %unless Up = 160
  132                     -> Cont
  133  
  134          SW(122):   Error = Error + 1 %unless Up = 122
  135                     -> Cont
  136  
  137          SW(101):   Error = Error + 1 %unless Up = 101
  138                     -> Cont
  139  
  140          SW(202):   Error = Error + 1 %unless Up = 202
  141                     -> Cont
  142  
  143          SW(301):   Error = Error + 1 %unless Up = 301
  144                     -> Cont
  145  
  146          SW(355):   Error = Error + 1 %unless Up = 355
  147                     -> Cont
  148  
  149          SW(200):   Error = Error + 1 %unless Up = 200
  150                     -> Cont
  151  
  152          SW(324):   Error = Error + 1 %unless Up = 324
  153                     -> Cont
  154  
  155          SW(*):     -> Cont
  156  
  157          SW(109):   Error = Error + 1 %unless Up = 109
  158                     -> Cont
  159  
  160          SW(256):   Error = Error + 1 %unless Up = 256
  161                     -> Cont
  162  
  163          SW(145):   Error = Error + 1 %unless Up = 145
  164                     -> Cont
  165  
  166          SW(165):   Error = Error + 1 %unless Up = 165
  167  
  168  
  169          Cont:      Up = Up + 1
  170          
  171      %Repeat
  172      %If Error = 0 %and Up = 356 %then pass %else fail
  173  !       %Switch operation.
  174  
  175  
  176        
  177  select output(1)
  178  write(failures,1);  printstring(" failure(s)");  newline
  179   
  180  %End %of %Program
?K unused

  105 Statements compiled
