Next: Some Simple Examples, Previous: Reporting Bugs, Up: flex [Contents][Index]
flex is a tool for generating scanners. A scanner is a
program which recognizes lexical patterns in text. The flex
program reads the given input files, or its standard input if no file
names are given, for a description of a scanner to generate. The
description is in the form of pairs of regular expressions and
fragments of source code
called rules. flex generates as output a source file
in your target language which defines a routine yylex().
This file can be compiled and (if you are using the C/C++ back end)
optionally linked with the flex runtime library to
produce an executable. When the executable is run, it analyzes its
input for occurrences of the regular expressions. Whenever it finds
one, it executes the corresponding rule code.
When your target language is C, the name of the generated scanner lex.yy.c by default. Other languages will glue the suffix they normally use for source-code files to the prefix lex.yy.
The examples in this manual are in C, which is Flex’s default target language and until release 2.6.4 it is the only one.