two-way finite state automaton