简体   繁体   English

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

[英]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). 我知道为正则表达式设计状态机生成器并不是一件容易的事,但是对于简单字符串呢(当我说一个简单字符串时,我的意思是类似“ abcd”的东西-没有任何正则表达式语法的东西)。 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": 这是名为“ Beautiful Code”的书中的一个非常好的示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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