Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Conklin E.K.Forth programmer's handbook.2000.pdf
Скачиваний:
321
Добавлен:
23.08.2013
Размер:
2.04 Mб
Скачать

Forth Programmer’s Handbook

4.1.6 Text Interpreter Directives

It is useful to control the logical flow when compiling an application. You may wish, for example, to load a certain source code file only if a flag indicates the need for that file. A number of Forth words provide this kind of control. Although these words are almost always used outside of definitions, they are all IMMEDIATE (i.e., they will execute when encountered in compiling state) and so may be used in definitions, if needed.

Here are two examples:

 

 

<flag> [IF]

INCLUDE <file1>

[THEN]

 

 

[DEFINED] <word in file1> [IF]

INCLUDE <file2>

 

 

[ELSE] INCLUDE <file3> [THEN]

 

 

 

 

 

 

Glossary

 

 

 

[DEFINED] <name>

( — flag )

common usage

 

 

Search the dictionary for name. If name is found, return true; otherwise, return

 

 

false. “bracket-defined”

 

[UNDEFINED] <name>

( — flag )

common usage

 

 

Search the dictionary for name. If the word is found, return false; otherwise,

 

 

return true. “bracket-undefined”

 

[IF]

( flag — )

Tools Ext

Begin an interpretive branch. If the flag is true, do nothing (i.e., continue interpretation). If the flag is false, parse and discard words from the parse area (including nested occurrences of [IF] [THEN] clauses) until either the word [ELSE] or the word [THEN] has been parsed and discarded. If the parse area becomes exhausted, it is refilled as with REFILL. Because [IF] discards [ELSE] (if it is present) when flag is false, interpretation will continue after [ELSE], thus interpreting the contents of the [ELSE] clause. “bracket-if”

[ELSE] ( — ) Tools Ext

Parse and discard words from the parse area (including nested occurrences of [IF] [THEN] clauses) until the word [THEN] has been parsed and discarded. If the parse area becomes exhausted, it is refilled as with REFILL.

The Forth Interpreter and Compiler 131

Соседние файлы в предмете Электротехника