         Edinburgh IMP77 Compiler - Version 8.4

    1  %control 0
    2  %externalroutine printstring(%string(255) text)
    3     %integer p, l
    4     p = 0;  l = length(text)
    5     %while p # l %cycle
    6        p = p+1;  printsymbol(charno(text, p))
    7     %repeat
    8  %end
    9  %externalroutine read string(%string(255)%name s)
   10     %integer sym, qu
   11     s = ""
   12     %cycle
   13        readsymbol(sym)
   14     %repeat %until sym # nl %and sym # ' '
   15     %signal 3,2,sym %unless sym='"' %or sym = ''''
   16     qu = sym
   17     %cycle
   18        readsymbol(sym)
   19        %if sym = qu %start
   20           %exit %if nextsymbol # qu
   21           readsymbol(sym)
   22           %finish
   23        s=s.tostring(sym)
   24     %repeat
   25  %end
   26  
   27  %externalstring(1)%fn nextitem
   28    %result=tostring(nextsymbol)
   29  %end
   30  
   31  %externalroutine skipitem
   32     %integer s
   33     readsymbol(s)
   34  %end
   35  
   36  %externalroutine readitem(%string(1)%name s)
   37  %integer k
   38   readsymbol(K); s=tostring(k)
   39  %end
   40  
   41  %externalstring(63)%fn itos(%integer n, p)
   42     %string(255) answer
   43     %byteintegerarray a(0:64)
   44     %integer sign, sym, pt, val
   45     val = p
   46     %if p > 0 %then p = p+1 %else p = -p
   47     p = 63 %if p > 63
   48     sign = ' '
   49     sign = 0 %if val <= 0
   50     pt = 0
   51     %if n < 0 %start
   52        sign = '-'
   53        %if n = 16_80000000 %start
   54           string(addr(a(pt))) = "8463847412"
   55           pt = pt + 10
   56           -> set
   57           %finish
   58        n = -n
   59        %finish
   60     %cycle
   61        sym = n-n//10*10
   62        pt = pt+1
   63        a(pt) = sym+'0'
   64        n = n//10
   65     %repeat %until n = 0
   66    set:
   67     %if sign # 0 %start
   68        pt = pt+1;  a(pt) = sign
   69     %finish
   70     %while pt < p %cycle
   71        pt = pt+1;  a(pt) = ' '
   72     %repeat
   73     answer = ""
   74     %cycle
   75        answer = answer.tostring(a(pt))
   76        pt = pt-1
   77     %repeat %until pt = 0
   78     %result = answer
   79  %end
   80  %externalroutine write(%integer n, p)
   81     space %and p = p-1 %while p > 62
   82     printstring(itos(n, p))
   83  %end
   84  %externalroutine poctal(%integer n)
   85     %integer j
   86     %for j = 30, -3, 0 %cycle
   87        printsymbol(n>>j&7+'0')
   88     %repeat
   89  %end
   90  
   91  %externalroutine read(%integer address, parm)
   92     %integer type, sign, sym, limit, digit
   93     %longreal value, exp, base
   94     %string(255) s
   95     base = 10.0
   96     type = parm>>24
   97     %if type # 16_10 %and type#64 %and type # 16_23 %andc
   98+                                       type # 16_24 %start
   99        %signal  5,5,type %unless type = 16_11 %or type = 16_12
  100     %finish
  101     %if type = 64 %start; ! string
  102        limit = parm&16_00ffffff -1;    ! max length
  103        s="";  digit = 0
  104        %cycle
  105           readsymbol(sym)
  106        %repeat %until sym#' ' %and sym # nl
  107        %cycle
  108           s = s.tostring(sym)
  109           digit=digit+1
  110           sym = nextsymbol
  111           %exit %if sym = ' ' %or sym = nl
  112           skipsymbol
  113        %repeat
  114        %signal 1,3 %if digit > limit
  115        string(address) = s
  116        %return
  117        %finish
  118  
  119     sign = 1
  120     %cycle
  121        sym = nextsymbol
  122        %if sym = '-' %start
  123           %signal 3,1,sym %if sign < 0
  124           sign = -1
  125           skipsymbol;  sym = nextsymbol
  126           %exit
  127        %finish
  128        %exit %if sym # ' ' %and sym # nl
  129        skipsymbol
  130     %repeat
  131  more:
  132     value = 0
  133     limit = int(base)
  134     digit = -1; sym = sym - 32 %if 'a'<= sym <= 'z'
  135     digit = sym-'0' %if '0' <= sym <= '9'
  136     digit = sym -'A'+10 %if 'A'<=sym<='Z'
  137     %signal 3,1,sym %unless 0 <= digit < limit %or
  138+                               (sym = '.' %and type&16_20 # 0)
  139     %while 0 <= digit < limit %cycle
  140        skipsymbol
  141        value = value*base+digit
  142        sym = nextsymbol
  143        digit = -1; sym=sym-32 %if 'a'<=sym<='z'
  144        digit = sym-'0' %if '0'<=sym<='9'
  145        digit = sym-'A'+10 %if 'A'<=sym<='Z'
  146     %repeat
  147     %if sym = '_' %start
  148        base = value
  149        skipsymbol
  150        sym = nextsymbol
  151        ->more
  152     %finish
  153     %if sym = '.' %and limit = 10  %and type&16_20 # 0 %start
  154        skipsymbol
  155        exp = 0.1
  156        %cycle
  157           sym = nextsymbol
  158           %exit %unless '0' <= sym <= '9'
  159           value = value+(sym-'0')*exp
  160           exp = exp*0.1
  161           skipsymbol
  162        %repeat
  163     %finish
  164     %if sym = '@' %and limit = 10 %and type&16_20 # 0 %start
  165        skipsymbol
  166        read(addr(sym), 16_10<<24)
  167        value = value*10.0^sym
  168     %finish
  169     value = -value %if sign < 0
  170     %if type&16_10 # 0 %start;       !integral
  171        sym = int(value)
  172        %if type = 16_10 %start
  173           integer(address) = sym
  174        %else %if type = 16_12
  175           byteinteger(address) = sym
  176        %else
  177           shortinteger(address) = sym
  178        %finish
  179     %else %if type = 16_23
  180        real(address) = value
  181     %else
  182        longreal(address) = value
  183     %finish
  184  %end
  185  
  186  %externalroutine  phex(%integer n)
  187     %integer j,k
  188     %for j = 1, 1, 8 %cycle
  189        k = (n>>28)&15;  n = n<<4
  190        %if k > 9 %then k = k-10+'A' %else k = k+'0'
  191        printsymbol(k)
  192     %repeat
  193  %end
  194  
  195  %begin
  196  %end
  197  
  198  %endoffile

  195 Statements compiled
