home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
tutor
/
l1p130
< prev
next >
Wrap
Text File
|
1990-05-16
|
5KB
|
92 lines
╔═══════════════════════════════════════════════════════╗
║ Lesson 1 Part 13.0 F-PC 3.5 Tutorial by Jack Brown ║
╚═══════════════════════════════════════════════════════╝
┌─────────────────────────────┐
│ Our Own Outer Interpreter │
└─────────────────────────────┘
The lesson 1 part 12.0 we presented the outer interpreter called MYQUIT
which presented a picture of the parameter stack as the command line
prompt instead of the usual " ok ". You should make sure that you have
the outer interpreter MYQUIT in a file MYQUIT.SEQ so that you can load
it whenever you need to experiment with the parameter stack.
The stack picture presented by MYQUIT is generated by F-PC's non
destructive stack display command called .S In Forth the period
" . " means print. Using a period or dot by itself will print the top
stack number ( the top stack number is the last number to be added to
the stack) In the parameter stack picture provide by .S ( print stack )
the number to the extreme right is the top stack number. The number in
the square brackets [3] specifies how many numbers are on the parameter
stack.
┌──────────────────────────┐
│ Sample Run with MYQUIT │
└──────────────────────────┘
FLOAD MYQUIT
MYQUIT
Stack Empty. > 11 22 <enter> <--- put two numbers on stack
[2] 11 22 > 33 <enter> <--- put 33 on the stack too
[3] 11 22 33 > . <enter> 33 <--- print top number.
[2] 11 22 > DEPTH <enter> <--- fetch stack depth to top
[3] 11 22 2 > . <enter> 2 <--- print stack depth
[2] 11 22 > + <enter> <--- add top two stack numbers
[1] 33 > . <enter> 33 <--- print the sum
Stack Empty. > 55 22 <enter> <--- put two numbers on stack
[2] 55 22 > - <enter> <--- find the difference
[1] 33 > . <enter> 33 <--- print the difference
Stack Empty. > 7 8 <enter> <--- put two numbers on stack
[2] 7 8 > * <enter> <--- find the product
[1] 56 > . <enter> 56 <--- print the product
Stack Empty. > 23 43 <enter> <--- put two numbers on stack
[2] 23 43 > MIN <enter> <--- leave smaller on stack
[1] 23 > . <enter> 23 <--- print the smaller number
Stack Empty. > 23 45 <enter> <--- put two numbers on stack
[2] 23 45 > MAX <enter> <--- leave the larger number
[1] 45 > . <enter> 45 <--- print the larger number
Stack Empty. > 66 3 <enter> <--- put two numbers on the stack
[2] 66 3 > / <enter> <--- find the quotient
[1] 22 > . <enter> 22 <--- display the quotient
Stack Empty. > <--- finished.
Do you know how to stop MYQUIT? There are two ways. 1) Type QUIT to
start the old outer interpreter. 2) Make an error, as the error recovery
routine will start the old version of QUIT. You can make an error by
trying to execute a word that doesn't exist. That should be no problem!
As an exercise try some of the above operators without MYQUIT running.
Even without MYQUIT in operation you can display the parameter stack
whenever you like by using the nondestructive stack print operator .S
In the above discussion we have been using the word print for . where it
might have been better to use the word display since the number goes on
the display screen and not the printer. The reason we refer to " . " as
the print operator is because it is a Forth tradition left over from the
days when the human was connected to the computer via a teletype
machine. In those days print really meant print!
┌───────────────────────────────┐
│ Comments in Forth Programs. │
└───────────────────────────────┘
There are two ways to place comments in a Forth Program. The first is
to place the comment in round brackets that some people call
parentheses. ( This is a comment ) You must include both a starting
and closing round bracket. The other common Forth commenting character
is the back slash " \ ". Placing a backslash in you program means
that anything on the line following the back slash will be ignored
\ This is a comment to the end of the line. No end mark required.
╓───────────────╖
║ Problem 1.7 ║
╙───────────────╜
Experiment with the stack operators above. Write me a Forth
program or Forth word that uses one or more of the operators + ,
- , * , / , MAX , MIN , and . It is pretty hard to get this problem
wrong! Just about anything that does something useful will do.
┌────────────────────────────────────┐
│ Please move to Lesson 1 Part 14.0 │
└────────────────────────────────────┘