简体   繁体   中英

Designing a simple state machine generator

I know that designing state machine generators for regular expressions is not trivial, but what about simple strings (when I say a simple string, I mean something like "abcd" -- something without any regular expression syntax). I was thinking of writing a simple string matcher using state machines, but I wanted the state machine to be generated at runtime

The input to the state machine generator is the string to be matched, the output is the state machine. I am not looking for code, but a method/algorithm to do this.

Yes, I could use any of the readily available libraries, but no thanks.

If you want a really simple matcher, you don't even need to build the state machine. You can just march through the pattern as you march through the string. Here is a really nice example from the book called, "Beautiful Code":

http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM