Added alternate function, removed relevant code from main; also started working on escape characters

This commit is contained in:
2024-10-27 15:30:33 -04:00
parent cda0dfb0cc
commit ae219f763a
2 changed files with 31 additions and 16 deletions

18
nfa.go
View File

@@ -74,3 +74,21 @@ func kleene(s1 State) *State {
toReturn.transitions[s1.content] = unique_append(toReturn.transitions[s1.content], &s1)
return toReturn
}
func alternate(s1 *State, s2 *State) *State {
toReturn := &State{}
toReturn.transitions = make(map[int][]*State)
toReturn.output = append(toReturn.output, s1.output...)
toReturn.output = append(toReturn.output, s2.output...)
// Unique append is used here (and elsewhere) to ensure that,
// for any given transition, a state can only be mentioned once.
// For example, given the transition 'a', the state 's1' can only be mentioned once.
// This would lead to multiple instances of the same set of match indices, since both
// 's1' states would be considered to match.
toReturn.transitions[s1.content] = unique_append(toReturn.transitions[s1.content], s1)
toReturn.transitions[s2.content] = unique_append(toReturn.transitions[s2.content], s2)
toReturn.content = EPSILON
toReturn.isEmpty = true
return toReturn
}