Added alternate function, removed relevant code from main; also started working on escape characters
This commit is contained in:
18
nfa.go
18
nfa.go
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user