         Edinburgh IMP77 Compiler - Version 8.4

    1  !* Program Name : IF
    2  
    3  !*   Title      :  IX   The Imp  Conditional Statements
    4  !*   Version    :  II
    5  !*   Date       :  24 August 1985
    6  !*   Description:  Tests the %IF and %UNLESS Statements.
    7  
    8  %Begin
    9  
   10      %string(255) param    { Used to get input from CLI}
   11  
   12      %Integer  J
   13      %Integer  K
   14      %Integer  M
   15      %Integer  Acc
   16  
   17  %owninteger failures=0
   18  
   19  %routine pass
   20    printstring("Pass")
   21    New Line
   22  %end
   23  %routine fail
   24    printstring("FAIL")
   25    New Line
   26    failures = failures+1
   27  %end
   28  
   29  
   30  
   31     ! Code to find out where the output is to be sent
   32     ! -----------------------------------------------
   33     ! Where the output goes to depends on the parameter after the
   34     ! name used to run the program.
   35     !                       Parameter   |   Result
   36     !                       ------------|-------------
   37     !                     No parameter  |  No output
   38     !                          "s"      |  The screen
   39     !                          "j"      |  "journal"
   40     !                     anything else |  file name entered
   41  
   42     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
   43     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
   44  
   45     param=cliparam
   46     %if param = "" %then select output (2) %c
   47+    %else %if param="s" %or param="S" %then select output(1) %c
   48+    %else %if param="j" %or param="J" %then  %c
   49+       open output(2,"journal") %and select output (2) %c
   50+    %else open output(2,param) %and select output (2)
   51     
   52  
   53  
   54     New Lines(2)
   55     Print String ("Conditional Statements");   New Line
   56     Print String ("======================");   New Lines (3)
   57  
   58  
   59  
   60  
   61      Print String ("Test the Full %IF Conditional");   New Line
   62      Print String ("-----------------------------");   New Line
   63  
   64      
   65      M = 0
   66      Acc = 0
   67      %For J = 1, 1, 10 %cycle
   68         %If J = 1 %then %Start
   69            Acc = Acc + 1
   70            K = 1
   71         %Finish %else %If J = 2 %then %Start
   72            Acc = Acc + 2
   73            K = 2
   74         %Finish %else %If J = 3 %then %Start
   75            Acc = Acc + 3
   76            K = 3
   77         %Finish %else %If J = 4 %then %Start
   78            Acc = Acc + 4
   79            K = 4
   80         %Finish %else %If J = 5 %then %Start
   81            Acc = Acc + 5
   82            K = 5
   83         %Finish %else %If J = 6 %then %Start
   84            Acc = Acc + 6
   85            K = 6
   86         %Finish %else %If J = 7 %then %Start
   87            Acc = Acc + 7
   88            K = 7
   89         %Finish %else %If J = 8 %then %Start
   90            Acc = Acc + 8
   91            K = 8
   92         %Finish %else %If J = 9 %then %Start
   93            Acc = Acc + 9
   94            K = 9
   95         %Finish %else %Start
   96            Acc = Acc + 10
   97            K = 10
   98         %Finish 
   99         %Unless K = J %then M = M + 1
  100      %Repeat
  101  
  102      %Unless M = 0 %and Acc = 45 %then pass %else fail
  103  !   Long-winded conditional.
  104  
  105  
  106      Acc = 0
  107      %Unless Acc = 0 %then %Start
  108          M = 1
  109      %Finish %else %Start
  110          M = 2
  111      %Finish
  112  
  113      %If M = 2 %then pass %else fail
  114  !   The long %UNLESS variant with TRUE condition.
  115  
  116  
  117  
  118      Acc = 1
  119      %Unless Acc = 0 %then %Start
  120          M = 1
  121      %Finish %else %Start
  122          M = 2
  123      %Finish
  124  
  125      %If M = 1 %then pass %else fail
  126  !   The long %UNLESS variant with FALSE condition.
  127  
  128    
  129  
  130  
  131  
  132  
  133      !*  Test the shortend variants of %IF and %UNLESS
  134  
  135      Acc = 0
  136      M   = 0
  137      Acc = 1 %if Acc = 0
  138      M   = 1 %if M = 1
  139  
  140      %If M = 0 %and Acc = 1 %then pass %else fail
  141  
  142  
  143      Acc = 0
  144      M   = 0
  145      Acc = 1 %unless Acc = 0
  146      M   = 2 %unless M   = 1
  147  
  148      %If M = 2 %and Acc = 0 %then pass %else fail
  149  
  150  
  151  
  152  select output(1)
  153  write(failures,1);  printstring(" failure(s)");  newline
  154  
  155  %End %of %Program

   93 Statements compiled
