home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / comment.seq < prev    next >
Text File  |  1989-07-03  |  4KB  |  108 lines

  1. \ COMMENT.SEQ   Allow multiple line comments in files.  by Tom Zimmer
  2.  
  3. ' <run> value crunsave
  4.  
  5. : ?exec         ( --- )
  6.                 state @ abort" Can not be used while Compiling!" ;
  7.  
  8. : ?loading      ( --- )
  9.                 loading @ 0=
  10.                 if      crunsave is run
  11.                         true abort" Use ONLY while loading"
  12.                 then    ;
  13.  
  14. variable comment$
  15.  
  16. : <comment:>    ( --- )
  17.                 loading @ 0=
  18.                 if      crunsave is run
  19.                         true abort" COMMENT: missing a COMMENT; while loading"
  20.                 then
  21.                 bl word                                 \ get a word
  22.                 1+ comment$ @ count caps-comp 0=        \ terminating string?
  23.                 if      crunsave is run                \ then back to <RUN>
  24.                         crunsave execute
  25.                 then    [compile] \ ;
  26.  
  27. : comment:      ( --- )         \ ignore all lines between COMMENT: & COMMENT;
  28.                 ?loading
  29.                 [compile] \
  30.                 " comment;" ">$ comment$ !
  31.                 @> run !> crunsave
  32.                 ['] <comment:> is run ;
  33.  
  34. : /*            ( --- )         \ skip all lines between /* and */
  35.                 ?loading
  36.                 [compile] \
  37.                 " */" ">$ comment$ !
  38.                 @> run !> crunsave
  39.                 ['] <comment:> is run ;
  40.  
  41. : <.comment:>   ( --- )
  42.                 loading @ 0=
  43.                 if      crunsave is run
  44.                         true abort" .COMMENT: missing a COMMENT; while loading"
  45.                 then
  46.                 bl word 1+ " comment;" caps-comp 0=
  47.                 if      crunsave is run
  48.                 else    key? 0=
  49.                         if      cr tib #tib @ 78 min type
  50.                         then
  51.                 then    [compile] \ ;
  52.  
  53. : .comment:     ( --- )         \ ignore all lines between.
  54.                 ?loading
  55.                 [compile] \
  56.                 @> run !> crunsave
  57.                 ['] <.comment:> is run ;
  58.  
  59. comment:        <- this marks the start line of a multi line comment.
  60.  
  61.         this is a comment line somewhere in the middle.
  62.  
  63.          /-------- this marks the end line of a multi line comment.
  64. comment;
  65.  
  66. : <#if>         ( --- )         \ ignore lines unless #else, or #endif
  67.                 loading @ 0=
  68.                 if      crunsave is run
  69.                         true abort" #IF missing a #THEN while loading"
  70.                 then
  71.                 begin   bl word dup c@ 0= >r 1+
  72.                         dup " #endif" caps-comp 0= over
  73.                             " #then"  caps-comp 0= or swap
  74.                             " #else"  caps-comp 0= or dup
  75.                         if      crunsave is run
  76.                                 >r crunsave execute r>
  77.                         then    r> or
  78.                 until   ;
  79.  
  80. : #else         ( --- )
  81.                 ?loading                        \ you must be loading
  82.                 ?exec                           \ but NOT compiling
  83.                 @> run !> crunsave              \ Save previous value of RUN.
  84.                 ['] <#if> is run                \ Ignore following lines
  85.                 <#if> ;        immediate        \   and rest of this line.
  86.  
  87. : #if           ( f1 --- )      \ ignore lines following if false
  88.                 ?loading
  89.                 ?exec
  90.                 0=
  91.                 if      @> run !> crunsave      \ Save previous value of RUN.
  92.                         ['] <#if> is run        \ Ignore following lines
  93.                         <#if>                   \   and rest of this line.
  94.                 then    ;       immediate
  95.  
  96. : #endif        ?loading ; immediate    \ just a noop for the #if TRUE case.
  97. : #then         ?loading ; immediate
  98.  
  99. \s      ************* NOT LOADING BEYOND THIS LINE ***********
  100.  
  101.         \ Here is an example of how the interpreted compiler directives
  102.         \ work
  103.  
  104. cr cr .( press a T for true ) key bl or 116 =   \ wait for a key
  105.  
  106. #if .( TRUE)  #else  .( FALSE)  #then .(  always )
  107.  
  108.