\ 4tH library - INTERPRET - Copyright 2003,2009 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License
\ Load ROW when needed
[UNDEFINED] row [IF]
[NEEDS lib/row.4th]
[THEN]
\ Note: remove [UNDEFINED] interpret [IF] .. [THEN]
\ when compiling under ANS-Forth!!
[UNDEFINED] interpret [IF]
\ Define ABORT routine, simply print offending word
defer NotFound
:noname type [char] ? emit space ; is NotFound
\ Define dictionary
(error) value dictionary
\ Default don't ignore numbers
[UNDEFINED] ignorenumbers [IF]
false constant ignorenumbers immediate
[THEN]
\ this routine interprets a string
: interpret ( --)
begin ( --)
bl parse-word dup ( a n f)
while
dictionary 2 string-key row ( a n x f)
if ( a n x)
nip nip cell+ @c execute ( --)
else ( a n)
ignorenumbers [IF]
drop NotFound ( --)
[THEN]
ignorenumbers [NOT] [IF]
drop 2dup number error? ( a n n2 f)
if drop NotFound else -rot 2drop then
[THEN] ( --)
then
repeat ( --)
drop drop ( --)
;
[THEN]
|