home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / eval.seq < prev    next >
Text File  |  1988-09-22  |  2KB  |  53 lines

  1. \ INTERP.SEQ    Interpret a string                      by Martin Tracy
  2.  
  3. comment:
  4.  
  5.   Originally suggested to me by Martin Tracy, but all the names have
  6. been changed to protect the guilty !!!
  7.  
  8.   Allows the definition of macros that will be interpreted at the run
  9. time of the macro. The first character of the first word following
  10. the macro name being defined is the delimiter for the macro as follows:
  11.  
  12.                 macro test " .( this is a test)"
  13.  
  14.                 macro <if  " < if "
  15.  
  16.                 macro test \ .( this is a test)\
  17.  
  18.   The delimiter must naturally not occur within the macro.
  19.  
  20.   Another form provided is MACRO:, it is used as follows:
  21.  
  22.                 macro: =if  = if ;
  23.  
  24.   In this example, MACRO: is terminated by the ";". the first occurance
  25. of ";" in a string will terminate MACRO:, so ";" may NOT be used within
  26. a MACRO: even as part of a word.
  27.  
  28.   All macros are created as immediate words, and as such they can be used
  29. within a colon definition.
  30.  
  31. comment;
  32.  
  33. : eval          ( a1 n1 --- )
  34.                 dup
  35.                 save!> span     save!> #tib
  36.                 save!> 'tib   0 save!> >in
  37.                 run
  38.                 restore> >in    restore> 'tib
  39.                 restore> #tib   restore> span ;
  40.  
  41. : macro         ( name --- )    \ start a macro definitions
  42.                 (:) compile (") here x,
  43.                 bl word 1+ c@           \ determine the explicit delimiter
  44.                 word c@ 1+ allot
  45.                 compile eval state on [compile] ; immediate ;
  46.  
  47. : macro:        ( name --- )
  48.                 (:) compile (") here x,
  49.                 ascii ; word c@ 1+ allot        \ delimiter is a ";"
  50.                 compile eval state on [compile] ; immediate ;
  51.  
  52.  
  53.