home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / tutor / l1p120 < prev    next >
Text File  |  1990-05-16  |  4KB  |  77 lines

  1.      ╔════════════════════════════════════════════════════════╗
  2.      ║   Lesson 1 Part 12.0  F-PC 3.5 Tutorial by Jack Brown  ║
  3.      ╚════════════════════════════════════════════════════════╝
  4.  
  5.             ┌────────────────────────────────────────┐
  6.             │  Creating Your Own Outer Interpreters  │
  7.             └────────────────────────────────────────┘
  8.  
  9. Well we have a little bad news for you.  Although the outer interpreters
  10. we have been looking at seem to work fine they are a little over
  11. simplified.  They will probably break quite easily especially if you try
  12. to enter definitions while they are running!  By studying the real QUIT
  13. with VIEW and making slight modifications.  Try the following version of
  14. QUIT called MYQUIT.  It might be a good idea to enter this into a file
  15. called MYQUIT.SEQ so that it is easier to experiment with.  We are not
  16. going to explain some of the strange things included in this definition
  17. right now.  We just took the F-PC version of QUIT and made a few
  18. changes.  Check this out for yourself!
  19.  
  20. \ This is my new version of the outer interpreter QUIT
  21. : MYQUIT          ( -- )
  22.                 SP0 @ 'TIB !    [COMPILE] [
  23.                 BEGIN
  24.                      BEGIN
  25.                      RP0 @ RP!
  26.                      QUERY  RUN  STATUS
  27.                      STATE @ NOT
  28.                      UNTIL
  29.                 .S ." > "
  30.                 AGAIN  ;
  31.  
  32. FLOAD MYQUIT.SEQ <enter>        <--- Load MYQUIT
  33.  
  34. MYQUIT <enter>                  <--- Run  MYQUIT
  35.  Stack Empty. >  <enter>
  36.  Stack Empty. > 1 2 3  <enter>  <--- Put some numbers on the stack!
  37.  [3]      1       2       3 > DROP   <--- drop 3 from stack
  38.  [2]      1       2 > SWAP           <--- swap top 2 numbers on stack.
  39.  [2]      2       1 > DUP            <--- duplicate top number
  40.  [3]      2       1       1 > 4 +    <--- add 4 to top number
  41.  [3]      2       1       5 > ROT    <--- rotate top three items!
  42.  [3]      1       5       2 >
  43.  
  44. OK!  Get out your copy of Starting Forth and play with the stack! Note:
  45. If you make an error the old QUIT will start running again and you will
  46. have to type MYQUIT to start your fancy new version again.
  47.  
  48. It should be clear by now that the outer interpreter is what the human
  49. interacts with while conversing with the Forth environment. Where as it
  50. is the inner interpreter(s) that execute your Forth programs or words
  51. that you construct using the : ; pair.  Once the outer interpreter
  52. determines what word you want executed it passes control to the inner
  53. interpreter(s) which step through the list of addresses (compiled code)
  54. created when you made the definition.  So....
  55.  
  56. Outer Interpreter...... interacts with human.
  57.  
  58. Inner Interpreter(s)... executes compiled word definitions.
  59.  
  60.                ┌───────────────────────┐
  61.                │  Forth Number Stacks. │
  62.                └───────────────────────┘
  63.  
  64. Forth has two number stacks.  One is called the parameter stack and
  65. the other is called the return stack.  Like the interpreters... the
  66. parameter stack is the one that the human (and his programs) interact
  67. with about 90% of the time.  The return stack is used for the most part
  68. by the Forth system ( specifically the inner interpreters) and humans who
  69. are trying to be clever.  Those parameters that we have been feeding to
  70. words like EMIT and LIST have actually been going on the parameter
  71. stack.  The parameter stack is also where numbers are placed before we
  72. do any arithmetic.
  73.  
  74. ┌─────────────────────────────────────┐
  75. │  Please move to Lesson 1 Part 13.0  │
  76. └─────────────────────────────────────┘
  77.