\ 2012-04-06 fsm5.fs include tempbuffer.fs : 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 here , 2 allot \ p->state , \ store width in flash ] \ switch compiler on to \ consume state table does> ( char col# -- ? ) \ -- char col# pfa dup >r \ -- char col# pfa \ r: pfa 1+ @i \ -- char col# width r@ @i @ * \ -- char C W*state + \ -- char C+W*state 2* \ we have 2 xts per field now. r@ + \ -- char p->action 1+ \ pfa[0] is p->state, move 1 up 1+ \ pfa[1] is width, move 1 up dup >r \ -- char p->action \ r: pfa p->action \ call action ( xt consumes char! ) @i execute \ -- ( ? ) \ update state r> 1+ \ -- ( ? ) p->update @i execute \ -- ( ? ) r> @i ! \ -- ( ? ) ; 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 ['] 1+ @i ! \ 0 mystate ! begin key dup emit dup $0D <> \ exit on CR while dup cat->col# repeat drop \ CR cr show cr ;