Flex - 快速扫描仪生成器。为什么?

Flex - A fast scanner generator. Why?

我想知道,为什么据我所知到现在还在用Flex?

如果现在不用,以前用过,那么与直接写C代码相比,还有什么优势呢?

这是我读到的有关 Flex 的内容

It takes as its input a text file containing regular expressions, together with the action to be taken when each expression is matched. It produces an output file that contains C source code defining a function yylex that is a table-driven implementation of a DFA corresponding to the regular expressions of the input file. The Flex output file is then compiled with a C compiler to get an executable.

Flex 的需求是什么?是不是比直接写C程序好? 在执行或代码编写速度方面更好?

我指的是 this 作为我的来源

与手写状态机相比,使用 flex 生成词法扫描器所需的代码肯定更少。阅读 flex 规范并理解它识别的标记也容易得多。

虽然可以 hand-optimize 扫描器并在执行时间方面击败 flex,但它很少能很好地利用程序员的时间。在大多数解析问题中,词法扫描不是瓶颈,性能的小幅提升将是无形的。此外,天真地使用正则表达式库等工具可能会产生速度更慢且更难维护的代码。

在过去的 20 年中,C 语言没有发生任何会影响上述任何陈述的变化。

以上所有内容都取决于程序员对如何使用该工具以及它适用于和不适用的问题有一定的了解。与任何工具集一样。