0

I wonder, why is Flex used even till now as far as I know?

If it is not used now and was used earlier, then also what is the advantage it provided over writing C code directly?

This is what I read about 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.

What is the need of Flex? Is it better than writing directly C programs? better in terms of execution or speed of code writing?

I am referring this as my source

splash
  • 13,037
  • 1
  • 44
  • 67
prashantitis
  • 1,797
  • 3
  • 23
  • 52

1 Answers1

4

Compared with writing out a state machine by hand, it certainly takes less code to produce a lexical scanner with flex. It is also much easier to read a flex specification and understand what tokens are recognized by it.

While it is possible to hand-optimize a scanner and beat flex in terms of execution time, it is rarely a good use of programmer time. In most parsing problems, the lexical scan is not the bottleneck, and a small performance improvement will be invisible. Also, the naive use of tools like regular expression libraries is likely to produce code which is both much slower and much harder to maintain.

Nothing has changed in the C language over the last 20 years which would affect either of the above statements.

All of the above is contingent on the programmer having some understanding of how to use the tool and for which problems it is and is not appropriate. As with any toolset.

rici
  • 234,347
  • 28
  • 237
  • 341