www.jupiter-ace.co.uk

Previous Page > Listings Index > Ace CASE.


Ace CASE listing from Personal Computing World March 1984
Personal Computing World March 1984 page 181


Ace case



The CASE structure is unfortunately omitted from Jupiter Ace Forth.This is an attempt to remedy that omission.

The 2 byte operand field of OF holds the number of bytes to be skipped to the corresponding ENDOF, if the, case isfalse.

The 2 byte operand field of ENDOF contains the number of bytes to be skipped to ENDCASE afterthe words between OF and ENDOF have been executed.

The numbers 7, 8,9 together with ?PAIRS are used to ensure that the CASE statement is always properly structured, in the form:
CASE	(n- -)
  x OF ... ENDOF
  y OF ... ENDOF
  z OF ... ENDOF
  OTHERWISE ...
ENDCASE
OTHERWISE may not be omitted from the CASE statement.

Words containing the CASE structure may be EDITed and REDEFINEd, and they may also be added to an existing directory.

The six words occupy 301 bytes as written, without comments.
: ?PAIRS
  = 0=
  IF
   ." ERROR 5"
   CR ABORT 
  THEN
;
0 COMPILER CASE
   0 9
  RUNS>
   DROP
;
2 COMPILER OF
  9 ?PAIRS
  HERE 0 ,
  7
RUNS>
  >R OVER = R> SWAP
  IF
   DROP DROP
  ELSE
   @ R> + >R
  THEN 
;

2 COMPILER ENDOF
  7 ?PAIRS
  HERE SWAP 0 ,
  OVER OVER — SWAP !
  9
RUNS>
  @ R> + >R
;

0 COMPILER OTHERWISE
   9 ?PAIRS 8
  RUNS
   DROP DROP
;

0 COMPILER ENDCASE
  8 ?PAIRS
  BEGIN
   ?DUP
  WHILE
    HERE OVER -
    2SWAP !
  REPEAT
RUNS>
  DROP
;
Example use:
: SILLY	( n—)
  CASE
   1 OF CR ." NUMBER
   ONE!" CR ENDOF
   6 OF CR ." NUMBER
   SIX!" CR ENDOF
   40 OF CR ." NUMBER
   FORTY!" CR ENDOF
   OTHERWISE CR ." NOT
   1,NOT6,NOT40!" CR
ENDCASE
." The end of a pointless word." CR
;

Stephen Renals