Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/interprt.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 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]

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].