home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
tutor
/
l1p120
< prev
next >
Wrap
Text File
|
1990-05-16
|
4KB
|
77 lines
╔════════════════════════════════════════════════════════╗
║ Lesson 1 Part 12.0 F-PC 3.5 Tutorial by Jack Brown ║
╚════════════════════════════════════════════════════════╝
┌────────────────────────────────────────┐
│ Creating Your Own Outer Interpreters │
└────────────────────────────────────────┘
Well we have a little bad news for you. Although the outer interpreters
we have been looking at seem to work fine they are a little over
simplified. They will probably break quite easily especially if you try
to enter definitions while they are running! By studying the real QUIT
with VIEW and making slight modifications. Try the following version of
QUIT called MYQUIT. It might be a good idea to enter this into a file
called MYQUIT.SEQ so that it is easier to experiment with. We are not
going to explain some of the strange things included in this definition
right now. We just took the F-PC version of QUIT and made a few
changes. Check this out for yourself!
\ This is my new version of the outer interpreter QUIT
: MYQUIT ( -- )
SP0 @ 'TIB ! [COMPILE] [
BEGIN
BEGIN
RP0 @ RP!
QUERY RUN STATUS
STATE @ NOT
UNTIL
.S ." > "
AGAIN ;
FLOAD MYQUIT.SEQ <enter> <--- Load MYQUIT
MYQUIT <enter> <--- Run MYQUIT
Stack Empty. > <enter>
Stack Empty. > 1 2 3 <enter> <--- Put some numbers on the stack!
[3] 1 2 3 > DROP <--- drop 3 from stack
[2] 1 2 > SWAP <--- swap top 2 numbers on stack.
[2] 2 1 > DUP <--- duplicate top number
[3] 2 1 1 > 4 + <--- add 4 to top number
[3] 2 1 5 > ROT <--- rotate top three items!
[3] 1 5 2 >
OK! Get out your copy of Starting Forth and play with the stack! Note:
If you make an error the old QUIT will start running again and you will
have to type MYQUIT to start your fancy new version again.
It should be clear by now that the outer interpreter is what the human
interacts with while conversing with the Forth environment. Where as it
is the inner interpreter(s) that execute your Forth programs or words
that you construct using the : ; pair. Once the outer interpreter
determines what word you want executed it passes control to the inner
interpreter(s) which step through the list of addresses (compiled code)
created when you made the definition. So....
Outer Interpreter...... interacts with human.
Inner Interpreter(s)... executes compiled word definitions.
┌───────────────────────┐
│ Forth Number Stacks. │
└───────────────────────┘
Forth has two number stacks. One is called the parameter stack and
the other is called the return stack. Like the interpreters... the
parameter stack is the one that the human (and his programs) interact
with about 90% of the time. The return stack is used for the most part
by the Forth system ( specifically the inner interpreters) and humans who
are trying to be clever. Those parameters that we have been feeding to
words like EMIT and LIST have actually been going on the parameter
stack. The parameter stack is also where numbers are placed before we
do any arithmetic.
┌─────────────────────────────────────┐
│ Please move to Lesson 1 Part 13.0 │
└─────────────────────────────────────┘