设计一个简单的状态机生成器

发布于 2024-09-29 12:21:30 字数 217 浏览 1 评论 0原文

我知道为正则表达式设计状态机生成器并不简单,但是简单的字符串又如何呢(当我说简单的字符串时,我的意思是像“abcd”这样的东西——没有任何正则表达式语法的东西)。我正在考虑使用状态机编写一个简单的字符串匹配器,但我希望在运行时生成状态机。

状态机生成器的输入是要匹配的字符串,输出是状态机。我不是在寻找代码,而是寻找执行此操作的方法/算法。

是的,我可以使用任何现成的库,但不用了,谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皇甫轩 2024-10-06 12:21:30

如果您想要一个非常简单的匹配器,您甚至不需要构建状态机。您可以像在字符串中前进一样在模式中前进。这是《美丽的代码》一书中的一个非常好的示例:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文