\ 2012-04-06 fsm3.fs include tempbuffer.fs variable mystate : digit? [char] 0 [char] 9 within ; : dpoint? [char] . = ; : minus? [char] - = ; : wide ; : cat->col# ( n -- n' ) \ other? 0 dup digit? 1 and over minus? 2 and + swap dpoint? 3 and + ; : fsm: ( width -- ) create , \ store width in flash ] \ switch compiler on to \ consume state table does> ( char col# -- ) \ -- char col# pfa swap over \ -- char pfa col# pfa @i \ -- char pfa C width mystate @ * \ -- char pfa C W*state + \ -- char pfa C+W*state 1+ \ pfa[0] is width, move 1 up \ cells \ no, we are in flash + \ -- char pfa[C+W*state] @i \ -- char xt execute \ -- ( xt consumes char! ) ; : (>1) append 1 mystate ! ; : (>2) append 2 mystate ! ; 4 wide fsm: ( action# -- ) \ 0 1 2 3 \ column# \ other 0-9 - . \ state drop (>1) (>1) (>2) \ 0 drop (>1) drop (>2) \ 1 drop (>2) drop drop \ 2 ; : getafix reset 0 mystate ! begin key dup emit dup $0D <> \ exit on CR while dup cat->col# repeat drop \ CR cr show cr ;