\ website: http://home.hccnet.nl/anij/index.html
\ ----- GATE example with INTERPRED -----
\ Albert Nijhof - dec 2003, maa 2015
\ Type KWIT to start the program.
\ You can leave the program by typing an error.
\ To keep things simple double numbers are not supported.
: snumber ( a n -- x ) \ string -> single number
over c@ [char] - =
over 1 > and >r \ negative?
r@ if 1 /string then
0 0 2swap >number
nip or abort" What's this? "
r> if negate then ;
: ?stack depth 0< if -4 throw then ;
gate interpred
gate compiling
gate executing
== interpred
state @ -if- goto compiling
goto executing
== executing
bl word dup c@ 0= -if- drop ?stack ." ok!" ready
find -if- execute goto interpred
count snumber
goto executing
== compiling
bl word dup c@ 0= -if- drop ?stack ." ok?" ready
find s>d -if- drop compile, goto compiling
( xt imm? ) -if- execute goto interpred
count snumber postpone literal
goto compiling
: kwit begin interpred refill 0= until ;
\ ----- end -----