As
a summary of what has been learned so far, we will look at how the FORTH
interpreter works.
After loading, the control is given to the word COLD (cold start). COLD clears
block buffers, sets virtual memory and terminal data, some USER variables
are called so called. fill parameters with standard initial values. Then
call ABORT. ABORT's text speaks for itself:
: ABORT
SP! (The primitive pit emptying)
DECIMAL
? STACK
CR .CPU (fill out the processor type)
"FORTH fig- 1.1g."
FORTH
DEFINITIOS
QUIT
;
The textinterpreter is mobilized by QUIT. QUIT after initializing the corresponding variables reads rows from the terminal in cycle and passes them to the word INTERPRET. Scanning is done by QUERY. QUERY calls EXPECT, configuring to place the line read from the keyboard into the command buffer; In addition, it sets IN to 0:
: QUERY
TIB @
80
EXPECT
0 IN!
;
(the title to which EXPECT will be scanned)
(text)
(maximum text length for EXPECT)
In addition to QUERY and INTERPRET, the RP! primitives; it restores the virus to its initial, empty state.
: QUIT
0 BLK!
[COMPILE] [
BEGIN PR
CR
QUERY
INTERPRET
STATE @
(read from the terminal)
(enter the execution state
)
(new line)
(command line scanning)
(command line execution)0 = IF "ok" ENDIF (if not in the middle of the fdefinition) ; (there is a row, the reason may be)
The
textinterpreter is roughly the same as the word INTERPRET.
1NTERPRET processes the influence
I speak of (spoken by BLK and IN system variables).
Of course, WORD makes wording,
which is included in the INTERPRET text in -FIND.
If -FIND successfully searches for the dictionary, the interpreter must decide
whether or not to execute or translate the dictionary word.
This decision (if the possible
values of the STATE are cleverly chosen) can be compressed into a single
comparison: the length of the word field of the word is compared to the STATE
values.
If you are interested in "bits": STATE, if not 0 (ie not executing state),
is hexadecimal C0, binary 1100 0000. In the length of the word field of the
words, the first bit is always 1. Thus, in executing state, the STATE value
is always smaller will be like longitude byte.
In the translation state, the
value of the STATE will be less than the length of the immediate words length
(the second bits of the longitude bit, the precedence bit 1).
So the word should be executed
if the STATE value is less than the length of the word.
If the word is not found in the dictionary, NUMBER will handle it, so try
to convert it. If it does not go, the NUMBER will be flown with 0 ERROR (going
back to QUIT). After a successful
conversion, you only have to decide whether it is a one-word or double-count
value (whether it was a decimal point), so LITERAL or DLITERAL gets the job.
Both do nothing if they are
in translation.
INTERPRET checks the word "STACK" to see if we have not used more items than
we used to stack or did not stack the stack (because it is finite).
In both cases, STACK causes
an error message and goes back to QUIT.
: INTERPRET
BEGIN
-FIND
IF
STATE @ <
IF
CFA,
ELSE
(the tag
is false)
(the word is FALSE if STATE 0,) (or the word is immediate)
( translate )
(put the start address to HERE)
(execution)CFA EXECUTE ENDIF
? STACK
ALWAYS
HERE NUMBER
DPL @ 1+
IF
(there is no element with this name)
(conversion)
(here we get when the conversion is
successful ) (NUMER has failed)
(DPL is not -1, it was a decimal point)[COMPILE] DLITERAL ELSE
DROP(one-word value) [COMPILE] LITERAL ENDIF
? STACK
ENDIF
AGAIN
;
What happens if the text to be interpreted brings you from the command buffer to translate a shadow? The LOAD text will give you the answer:
: LOAD
BLK @> R
IN @> R
0 IN!
B / SCR *
BLK!
INTERPRET
R> IN!
R> BLK!
;
(the queue number)
(note where we left)
(the text containing the LOAD
)
(begin with the beginning of the block)
(the first block of the screen)
So a LOAD calls another INTERPRET, that is, a new BEGIN ... AGAIN cycle (this time the word blocks starts from the blocks of blocks). Whichever (external, internal, or even more) BEGIN ... AGAIN cycle is concerned, one must once complete the interpretation of all the nodes and command lines. The term word is null (its name is used in dictionary lists and documentation x), which is called a single binary zero byte. Therefore, it is good that EXPECT (that is QUIT called QUERY) will cause binary zero or zero after the scanned text; therefore (although not so far) is also binary at the end of the block buffers. Binary 0 (in addition to always delimiting the WORD) is a dictionary word.
Null is a term not only for interpretation but also for this book. Good luck and good work for FORTH!
file: /Techref/language/forth/z80fig-forth1_1g_files/text_interpreter.htm, 19KB, , updated: 2018/11/8 19:22, local time: 2024/11/28 02:51,
3.145.109.144:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://sxlist.com/techref/language/forth/z80fig-forth1_1g_files/text_interpreter.htm"> FORTH text_interpreter</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.