3. Het GATE programma
Hulpwoordjes
forth definitions decimal
\ Vervanger voor EXIT THEN
: } postpone exit postpone then ; immediate
vocabulary fsa fsa also definitions
here abs constant syntax \ Herkenningsgetal
: ?syntax ( x -- ) syntax <> abort" syntax error " ;
: 0-gate cr .s true abort" Undefined gate " ;
\ Bepaal body-adres van gate ccc
: gatea ( ccc -- body ) ' >body dup cell+ @ ?syntax ;
: ifornoif ( pos/neg -- )
0< if postpone } syntax } postpone ; swap ! ;
En nu de GATE-woorden
forth definitions
\ Declareer gate ccc
: gate ( ccc -- ) create ['] 0-gate , syntax ,
does> begin @ execute ?dup 0= until ;
\ Definieer de 'rules' voor gate ccc
: == ( ccc -- gatea xt syntax )
gatea :noname syntax ;
: -if- ( syntax -- -syntax )
?syntax postpone if syntax negate ; immediate
: goto ( gatea xt -+syntax ccc -- ) dup abs ?syntax
gatea postpone literal ifornoif ; immediate
: ready ( gatea xt -+syntax -- ) dup abs ?syntax
postpone false ifornoif ; immediate
previous forth
\ --- einde ---
Opmerking: deze tekst is van 2003 toen DEFER nog geen standaardwoord was. (AN, 2015)