Finite state machine synthesis for pattern processing and recognition