Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
User Commands (d - f)
flex(1)
-Sskeleton
Overrides the default skeleton file from which the command constructs its scanners.
This is useful for flex maintenance or development.
-c Specifies table-compression options. (Obsolescent)
-n Suppresses the statistics summaries that the -v flag typically generates. (Obsolescent.)
DESCRIPTION
The lex and flex commands have the same functionality.
The flex command is a tool for generating scanners: programs that recognize lexical patterns in
text. flex reads the given input files, or its standard input file if no filenames are given or if a file
operand is - (dash), for a description of a scanner to generate. The description is in the form of
pairs of regular expressions and C code, called rules. flex generates as output a C source file,
named lex.yy.c, which defines a routine yylex(). This file is compiled and linked with the -ll
library to produce an executable. When the executable is run, it scans its input and the regular
expressions in its rules looking for the best match (longest input). When it has selected a rule it
executes the associated C code, which has access to the matched input sequence (commonly
referred to as a token). This process then repeats until input is exhausted.
flex treats multiple input files as one.
Syntax for flex Input
This subsection contains a description of the flex input files, which are normally named with a .l
suffix. It provides a listing of the special values, macros, and functions recognized by the flex com-
mand.
The flex input file consists of three sections, separated by a line with just %% in it:
[ definitions ]
%%
[ rules ]
[ %%
[ user_functions ]]
where
definitions Contains declarations to simplify the scanner specification and declarations of
start states, which are explained below.
rules Describes what the scanner is to do.
user_functions Contains user-supplied functions, which are copied directly to file lex.yy.c.
With the exception of the first %% sequence, all sections are optional. The minimal scanner,
%%, copies its input to the standard output file.
Each line in the definitions section can be:
name regexp Defines name to expand to regexp. name is a word beginning with a letter or an
underscore ( _ ) followed by zero or more letters, digits, underscores, or dashes ( -
). In the regular-expression parts of the rules section, the command substitutes
regexp wherever you refer to {name}(name within braces).
%x state [ state ... ] or %s state [ state ... ]
Defines names for states used in the rules section. A rule can be made condition-
ally active based on the current scanner state. Multiple lines defining states can
appear, and each can contain multiple state names, separated by white space. The
name of a state follows the same syntax as that of regexp names except that
527188-003 Hewlett-Packard Company 3−145