使用一个有限状态机一个良好的设计对于一般的文本分析? [英] Is using a finite state machine a good design for general text parsing?
问题描述
我读一个充满文件 用十六进制数。我必须确定一个 特定的模式,从说aaad(不带引号) 它。每当我看到这个模式,我 生成一些数据,以某些其他文件
I am reading a file that is filled with hex numbers. I have to identify a particular pattern, say "aaad" (without quotes) from it. Every time I see the pattern, I generate some data to some other file.
这是在设计方案很常见的情况 - 分析和寻找一个特定的模式
This would be a very common case in designing programs - parsing and looking for a particular pattern.
我设计了其作为有限状态机并采用结构化结构在C 的switch-case
改变状态。这是发生在我的第一个实施。
I have designed it as a Finite State Machine and structured structured it in C using switch-case
to change states. This was the first implementation that occured to me.
- 设计:有没有一些更好的设计可能
- 执行情况:你看到一些问题,使用开关的情况下,因为我提到的
- DESIGN: Are there some better designs possible?
- IMPLEMENTATION: Do you see some problems with using a switch case as I mentioned?
推荐答案
一个手卷FSM可以很好地工作对于简单的做法,但他们往往会得到笨重的状态和投入数量的增长。
A hand-rolled FSM can work well for simple situations, but they tend to get unwieldy as the number of states and inputs grows.
有可能是没有理由去改变你已经设计/实施,但如果你有兴趣在通用的文本解析技术,你应该看的东西像普通EX pressions,弯曲,野牛和ANTLR。
There is probably no reason to change what you have already designed/implemented, but if you are interested in general-purpose text parsing techniques, you should probably look at things like regular expressions, Flex, Bison, and ANTLR.
这篇关于使用一个有限状态机一个良好的设计对于一般的文本分析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!