Previous: Interpret/Compile states, Up: The Text Interpreter


5.13.4 Interpreter Directives

These words are usually used in interpret state; typically to control which parts of a source file are processed by the text interpreter. There are only a few ANS Forth Standard words, but Gforth supplements these with a rich set of immediate control structure words to compensate for the fact that the non-immediate versions can only be used in compile state (see Control Structures). Typical usages:

     FALSE Constant HAVE-ASSEMBLER
     .
     .
     HAVE-ASSEMBLER [IF]
     : ASSEMBLER-FEATURE
       ...
     ;
     [ENDIF]
     .
     .
     : SEE
       ... \ general-purpose SEE code
       [ HAVE-ASSEMBLER [IF] ]
       ... \ assembler-specific SEE code
       [ [ENDIF] ]
     ;

[IF]       flag –         tools-ext       “bracket-if”

If flag is TRUE do nothing (and therefore execute subsequent words as normal). If flag is FALSE, parse and discard words from the parse area (refilling it if necessary using REFILL) including nested instances of [IF].. [ELSE].. [THEN] and [IF].. [THEN] until the balancing [ELSE] or [THEN] has been parsed and discarded. Immediate word.

[ELSE]              tools-ext       “bracket-else”

Parse and discard words from the parse area (refilling it if necessary using REFILL) including nested instances of [IF].. [ELSE].. [THEN] and [IF].. [THEN] until the balancing [THEN] has been parsed and discarded. [ELSE] only gets executed if the balancing [IF] was TRUE; if it was FALSE, [IF] would have parsed and discarded the [ELSE], leaving the subsequent words to be executed as normal. Immediate word.

[THEN]              tools-ext       “bracket-then”

Do nothing; used as a marker for other words to parse and discard up to. Immediate word.

[ENDIF]              gforth       “bracket-end-if”

Do nothing; synonym for [THEN]

[IFDEF]       "<spaces>name" –         gforth       “bracket-if-def”

If name is found in the current search-order, behave like [IF] with a TRUE flag, otherwise behave like [IF] with a FALSE flag. Immediate word.

[IFUNDEF]       "<spaces>name" –         gforth       “bracket-if-un-def”

If name is not found in the current search-order, behave like [IF] with a TRUE flag, otherwise behave like [IF] with a FALSE flag. Immediate word.

[?DO]       n-limit n-index –         gforth       “bracket-question-do”

[DO]       n-limit n-index –         gforth       “bracket-do”

[FOR]       n –         gforth       “bracket-for”

[LOOP]              gforth       “bracket-loop”

[+LOOP]       n –         gforth       “bracket-question-plus-loop”

[NEXT]       n –         gforth       “bracket-next”

[BEGIN]              gforth       “bracket-begin”

[UNTIL]       flag –         gforth       “bracket-until”

[AGAIN]              gforth       “bracket-again”

[WHILE]       flag –         gforth       “bracket-while”

[REPEAT]              gforth       “bracket-repeat”