\ tools-ext 05.1.22 NAB

module tools-ext

defer (if)
variable ifdepth

public:
: [IF] ( flag --)  0 ifdepth !  (if) ; immediate
defer [ELSE]  immediate
: [THEN] ( -- ) ; immediate

private:
: ([if]) ( flag -- )
  if  exit  then
  1 ifdepth +!
  begin
    begin
    bl skip bl word  dup c@ while
      dup 1+ c@ [char] [ =
      if  find  else  0  then
      if  dup  ['] [if] = if  0 recurse  then
        dup  ['] [else] =  ifdepth @ 1 =  and
        swap  ['] [then] =  or
        if  -1 ifdepth +!  exit  then
      else  drop  then
    repeat drop
  refill 0= until ;

: ([else]) ( -- ) 1 ifdepth !  0 ([if]) ;

' ([if]) is (if) 
' ([else]) is [ELSE]

end-module
