Added function for concatenation and kleene star

master
Aadhavan Srinivasan 2 months ago
parent c9fdf5aa6c
commit b327143fa2

@ -48,7 +48,29 @@ func verifyLastStatesHelper(state *State, visited map[*State]bool) {
}
}
// verifyLastStates penables the 'isLast' flag for the leaf nodes (last states)
// verifyLastStates enables the 'isLast' flag for the leaf nodes (last states)
func verifyLastStates(start []*State) {
verifyLastStatesHelper(start[0], make(map[*State]bool))
}
func concatenate(s1 *State, s2 *State) *State {
for i := range s1.output {
s1.output[i].transitions[s2.content] = append(s1.output[i].transitions[s2.content], s2)
}
s1.output = s2.output
return s1
}
func kleene(s1 State) *State {
toReturn := &State{}
toReturn.transitions = make(map[int][]*State)
toReturn.content = EPSILON
toReturn.isEmpty = true
toReturn.isKleene = true
toReturn.output = append(toReturn.output, toReturn)
for i := range s1.output {
s1.output[i].transitions[toReturn.content] = append(s1.output[i].transitions[toReturn.content], toReturn)
}
toReturn.transitions[s1.content] = append(toReturn.transitions[s1.content], &s1)
return toReturn
}

Loading…
Cancel
Save