implement reverse() method
Closed this issue · 1 comments
bradengroom commented
This method should return the reversal of an automaton.
The new automaton should be created by having all final states epsilon jump into a new single initial state. The old final states should no longer be final. The old initial state should no longer be initial but will be made final. Now all of the transitions should be reversed so that the end state is the start and vice versa.
bradengroom commented
def reverse(): Automaton = {
val newStart = new State()
val newTransitions = this.transitions.map(transition => ((transition._2, transition._1._2), transition._1._1)) ++ this.finalStates.map(state => ((newStart, '\0'), state))
new Automaton(newStart, Set(this.startState), newTransitions)
}