Added function for concatenation and kleene star

This commit is contained in:
2024-10-27 11:19:06 -04:00
parent c9fdf5aa6c
commit b327143fa2

24
nfa.go
View File

@@ -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
}