Loosened restrictions for concatenation - It's okay if one of the

elements is missing
master
Aadhavan Srinivasan 1 week ago
parent 5c2869ff81
commit 08e01a1c81

@ -828,9 +828,16 @@ func thompson(re []postfixNode) (Reg, error) {
switch c.nodetype { switch c.nodetype {
case CONCATENATE: case CONCATENATE:
s2 := mustPop(&nfa) s2 := mustPop(&nfa)
s1 := mustPop(&nfa) // Relax the requirements for concatenation a little bit - If
s1 = concatenate(s1, s2) // the second element is not found ie. the postfixNodes look
nfa = append(nfa, s1) // like 'a~', then that's fine, we just skip the concatenation.
s1, err := pop(&nfa)
if err != nil {
nfa = append(nfa, s2)
} else {
s1 = concatenate(s1, s2)
nfa = append(nfa, s1)
}
case KLEENE: // Create a 0-state, concat the popped state after it, concat the 0-state after the popped state case KLEENE: // Create a 0-state, concat the popped state after it, concat the 0-state after the popped state
s1 := mustPop(&nfa) s1 := mustPop(&nfa)
stateToAdd := kleene(*s1) stateToAdd := kleene(*s1)

Loading…
Cancel
Save