home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / RiscOS / APP / DEVS / FORTH / WIMPFO.ZIP / !WimpForth / interpif < prev    next >
Text File  |  1995-12-30  |  2KB  |  60 lines

  1. ( Interpretive IF ELSE THEN control structures )
  2. ( 14nov1994japs )
  3.  
  4. cr .( Loading Interpretive Conditionals...)
  5.  
  6. only forth also hidden definitions
  7.  
  8. : definite-word ( definitely get a word from the input stream )
  9.         ( delim -- addr )
  10.         begin   dup word dup c@ 0=
  11.         while   drop refill 0=
  12.                 abort" Input stream exhausted!"
  13.         repeat  nip ;
  14.  
  15. : def-defined ( get a word, try to find it in the dictionary )
  16.         ( -< chars >- -- addr \ 0 | -- xt \ 1 | -- xt \ -1 )
  17.         bl definite-word ?uppercase (find) ;
  18.  
  19. only forth definitions also hidden
  20.  
  21. : [then] ( mark the end of the interpretive control structure )
  22.         ( -- )
  23.         ; immediate
  24.  
  25. : [else] ( the alternative selection )
  26.         ( -- )
  27.         begin def-defined drop ['] [then] = until ; immediate
  28.  
  29. : [if]  ( begin the interpretive control structure )
  30.         ( flag -- )
  31.         0= if begin def-defined drop dup ['] [else] = swap ['] [then]
  32.         = or until then ; immediate
  33.  
  34. : #then ( mark the end of the interpretive control structure )
  35.         ( -- )
  36.         ; immediate
  37.  
  38. : #endif ( mark the end of the interpretive control structure )
  39.         ( -- )
  40.         ; immediate
  41.  
  42. : #else ( the alternative selection )
  43.         ( -- )
  44.         begin   def-defined drop
  45.                 dup  ['] #then  =
  46.                 swap ['] #endif = or
  47.         until   ; immediate
  48.  
  49. : #if   ( begin the interpretive control structure )
  50.         ( flag -- )
  51.         0= if   begin   def-defined drop
  52.                         dup  ['] #else  =
  53.                         over ['] #then  = or
  54.                         swap ['] #endif = or
  55.                 until
  56.            then ; immediate
  57.  
  58. only forth also definitions
  59.  
  60.