Make kleene() throw an error if the state is not quantifiable

master
Aadhavan Srinivasan 4 days ago
parent 8b6d35c106
commit ecab7cc522

@ -1,6 +1,7 @@
package main
import (
"fmt"
"slices"
)
@ -268,7 +269,11 @@ func concatenate(s1 *State, s2 *State) *State {
return s1
}
func kleene(s1 State) *State {
func kleene(s1 State) (*State, error) {
if s1.isEmpty && s1.assert != NONE {
return nil, fmt.Errorf("previous token is not quantifiable")
}
toReturn := &State{}
toReturn.transitions = make(map[int][]*State)
toReturn.content = newContents(EPSILON)
@ -283,7 +288,7 @@ func kleene(s1 State) *State {
for _, c := range s1.content {
toReturn.transitions[c], _ = unique_append(toReturn.transitions[c], &s1)
}
return toReturn
return toReturn, nil
}
func alternate(s1 *State, s2 *State) *State {

Loading…
Cancel
Save