More Kleene star fixes

This commit is contained in:
2024-10-23 10:26:50 -04:00
parent 9d3bc2b804
commit 11dd6aeb7c
3 changed files with 36 additions and 10 deletions

View File

@@ -143,7 +143,8 @@ func thompson(re string) *State {
s2 := pop(&nfa)
s3 := State{}
s3.transitions = make(map[int][]*State)
s3.output = append(s3.output, s1, s2)
s3.output = append(s3.output, s1.output...)
s3.output = append(s3.output, s2.output...)
s3.transitions[s1.content] = append(s3.transitions[s1.content], s1)
s3.transitions[s2.content] = append(s3.transitions[s2.content], s2)
s3.content = EPSILON
@@ -163,6 +164,11 @@ func thompson(re string) *State {
}
func main() {
// Process:
// 1. Convert regex into postfix notation (Shunting-Yard algorithm)
// a. Add explicit concatenation operators to facilitate this
// 2. Build NFA from postfix representation (Thompson's algorithm)
// 3. Run the string against the NFA
if len(os.Args) < 3 {
fmt.Println("ERROR: Missing cmdline args")
os.Exit(22)