210a
<< <> >>

210

The programming language Forth
home
About manipulating the input stream.

MANY TIMES

Forth at work

When a user types a line of text and presses [rtn], Forth approaches this line as follows:

It searches the first non-space (which is where a word starts), then it searches the next space after that (where the word stops). The system variable >IN functions as a pointer. Forth administrates carefully in >IN where on the line it is looking.

After the word is parsed, it is looked up in the dictionary and executed. When Forth can't find the word, it announces an error and ignores the rest of the unparsed input text.

When no error develops, Forth endlessly repeats this procedure: determine the next word, again and again using >IN, and executing the word -- until the end of line is detected.

Because Forth has no syntax, it is not necessary to decide beforehand if the line is correct. Typing errors will automatically be detected, because Forth can't find misspelled words anyway. Programming errors are of course still a problem, but they have nothing to do with syntax.
) >IN @ . [rtn] ?
 1234567... positions
The contents of >IN are fetched by @. Forth has already read the line including @ and the trailing space.
)       >IN @ . [rtn] ?
 1234567890123... positions

)       >IN @ . >IN @ . [rtn] ?
 123456789012345678901... positions
Forth assumes that users won't type words that change >IN behind its back, but we all know how Forth programmers are ...
>>