\ 2012-04-06 fsm4.fs include tempbuffer.fs variable mystate : digit? [char] 0 [char] 9 within ; : dpoint? [char] . = ; : minus? [char] - = ; : wide ; : cat->col# ( n -- n' ) 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# pfs 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 2* \ we have 2 xt per field now. + \ update state first dup @i execute mystate ! \ call action ( xt consumes char! ) 1- @i execute ; 0 constant >0 1 constant >1 2 constant >2 4 wide fsm: ( char action# -- ) \ 0 1 2 3 \ other 0-9 - . \ state drop >0 append >1 append >1 append >2 \ 0 drop >1 append >1 drop >1 append >2 \ 1 drop >2 append >2 drop >2 drop >2 \ 2 ; : getafix reset 0 mystate ! begin key dup emit dup $0D <> \ exit on CR while dup cat->col# repeat drop \ CR cr show cr ;