         Edinburgh IMP77 Compiler - Version 8.4

    1  %begin
    2  
    3    %const %byte  TRUE  = 0
    4    %const %byte  FALSE = 1
    5  
    6    %byte %fn tolower(%byte c)
    7      %if 'A' <= c %and c <= 'Z' %then %result = c + 16_20
    8      %result = c
    9    %end
   10  
   11    %byte i, a, ishex, size, num, n
   12    %byte %array s(0:2)
   13  
   14    size = 3; s(0)='$'; s(1) = '8'; s(2) = 'C'
   15    
   16    ishex = FALSE
   17    i = 0;
   18    
   19    %if s(0) = '$' %then %start
   20      ishex = TRUE
   21      i = 1
   22    %finish
   23      
   24    num = 0
   25      
   26    %while i < size %cycle
   27      n = s(i); i = i+1
   28      %if '0' <= n %and n <= '9' %then %start
   29        n = n - '0';
   30      %finish %else %start
   31        %if ishex = TRUE %then %start
   32          n = tolower(n)
   33          %if 'a' <= n %and n <= 'f' %then n = n - ('a' - 10) %else %stop
   34        %finish
   35      %finish
   36      %if ishex = TRUE %then num = num * 16 + n %else num = num * 10 + n
   37    %repeat
   38    
   39    a = num
   40    print string("a=")
   41    write(a, 0)
   42    newline
   43  
   44  %end %of %program

   38 Statements compiled
