Is using a finite state machine a good design for general text parsing?

北战南征 提交于 2019-12-06 11:23:39

A hand-rolled FSM can work well for simple situations, but they tend to get unwieldy as the number of states and inputs grows.

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.

For embarrassingly simple cases couple of if's or switch'es are sufficient. For parsing a string on POSIX systems, man regex (3). For fully featured parsing of whole files (e.g. complex configs) use Lex/Flex and Yacc/Bison.

When writing in C++, look at Boost Regex for the simpler case and Boost Spirit for more complex one. Flex & Bison work with C++ too.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!