Theory of Automata, Languages and Computation