home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
forth
/
compiler
/
fpc
/
tutor
/
l1p110
< prev
next >
Wrap
Text File
|
1990-05-16
|
4KB
|
86 lines
╔════════════════════════════════════════════════════════╗
║ Lesson 1 Part 11.0 F-PC 3.5 Tutorial by Jack Brown ║
╚════════════════════════════════════════════════════════╝
Hello again! Just can't stay away from the Tutorial Conference. You
may have heard that Forth is a stack based language and wonder why we
haven't said any thing about stacks yet. We believe that most of the
introductions to Forth that over emphasize the stack in the initial
stages. There is a lot of things we can learn before we focus on the
stack. Besides we are going to let Forth teach you all about its stack
By now you should feel comfortable working in the F-PC environment and
should be writing and compiling short programs of your own using the
EDitor.
┌───────────────────────┐
│ The Outer Interpreter │
└───────────────────────┘
You are about to see some very powerful ideas. The Forth development
environment has what is called an "Outer Interpreter" and an "Inner
Interpreter" (to me more correct we should really say that it has a lot
of little inner interpreters).
The "outer interpreter" is that part of Forth environment that you
interact with while you sit at the keyboard with the " ok " prompt on
the screen. The "outer interpreter" is an infinite loop that executes
over and over again and might look something like this:
outer interpreter:
step 1 Get a line of text from human.
step 2 Follow instruction in line of text entered by human
step 3 Display the " ok " prompt so human knows I'm done.
step 4 Go to step 1
Actually the "outer interpreter" is just a Forth word that is defined
using the : ; pair. The name of Forths outer interpreter is QUIT .
you can VIEW QUIT if you like to see what the actual source code looks
like. But first I'll give you a simplified version of QUIT
: QUIT
BEGIN CR QUERY \ This is step 1
INTERPRET \ This is step 2
." ok" \ This is step 3
AGAIN ; \ This is step 4
Here is what actually happens if you do this!
ok <--- the ok prompt
: QUIT BEGIN CR QUERY INTERPRET ." ok" AGAIN ; <enter>
QUIT isn't unique ok <--- because there already is a QUIT
QUIT <enter> <--- execute the new outer interpreter
ok <--- hit return to get ok prompt from
ok <--- new outer interpreter.
Well we know you are skeptical, bet you don't believe that you just
wrote and executed your very own outer interpreter! But look very
closely. Do you notice anything different? Try using HELP does it
still work. Does VIEW still work? Does the EDitor still work?
What has changed?
Well let's change the outer interpreter a little. I never liked that
" ok " prompt! Also let's give our new outer interpreter a different
name so that the skeptics will be convinced that there is no slight of
hand. Try the following outer interpreter called MQUIT .
ok
: MQUIT BEGIN CR ." FPC>" QUERY INTERPRET AGAIN ; <enter> ok
MQUIT <enter>
FPC> <enter> <--- New outer interpreter is running!!!
┌─────────────────────────┐
│ The Inner Interpreter │
└─────────────────────────┘
We will say more about the "Inner Interpreter(s)" later but for now
let's just say that is the lower level mechanism that executes one of
our compiled colon defintions. We will investigate many executable
structures in our study of Forth ( constants and variables still to
come) and each has its own inner interpreter.
┌────────────────────────────────────┐
│ Please move to Lesson 1 Part 12.0 │
└────────────────────────────────────┘