Developer(s) | Vern Paxson |
---|---|
Initial release | around 1987 |
Stable release |
2.6.0 / November 17, 2015
|
Operating system | Unix-like |
Type | Lexical analyzer generator |
License | BSD license |
Website | github |
Flex (fast lexical analyzer generator) is a free and open-source software alternative to lex. It is a computer program that generates lexical analyzers (also known as "scanners" or "lexers"). It is frequently used as the lex implementation together with Berkeley Yacc parser generator on BSD-derived operating systems (as both lex
and yacc
are part of POSIX), or together with GNU bison (a version of yacc) in *BSD ports and in Linux distributions. Unlike Bison, flex is not part of the GNU Project and is not released under the GNU General Public License.
Flex was written in C by Vern Paxson around 1987. He was translating a Ratfor generator, which had been led by Jef Poskanzer.
This is an example of a Flex scanner for the instructional programming language PL/0.
The tokens recognized are: '+
', '-
', '*
', '/
', '=
', '(
', ')
', ',
', ';
', '.
', ':=
', '<
', '<=
', '<>
', '>
', '>=
'; numbers: 0-9 {0-9}
; identifiers: a-zA-Z {a-zA-Z0-9}
and keywords: begin
, call
, const
, do
, end
, if
, odd
, procedure
, then
, var
, while
.