lex — Generate a program for lexical tasks

Format

lex [–achlntTv] [–o file.c] [–P proto] [–p prefix] [file.l …]

Description

lex reads a description of a lexical syntax, in the form of regular expressions and actions, from file.l. If you do not provide file.l, or if the file is named , lex reads the description from standard input (stdin). It produces a set of tables that, together with additional prototype code from /etc/yylex.c, constitute a lexical analyzer to scan those expressions. The resulting recognizer is suitable for use with yacc. You can find detailed information about the use of lex in z/OS UNIX System Services Programming Tools.

For a description of the typedefs, constants, variables, macros, and functions in the table file, which can be used to access the lexical analyzer's variables or to control its operations, see z/OS UNIX System Services Programming Tools.

A locale is the subset of a user's environment that depends on language and cultural conventions. A locale defines such things as the definition of characters, and the collation sequence of those characters. POSIX.2 defines a POSIX locale, which is essentially USASCII. Because lex generates code that is then compiled before being executed, it is difficult for lex to act properly on collation information. The POSIX.2 standard therefore does not require lex to accept any locales other than the POSIX locale. lex accepts regular expressions in this locale only.

Options

–a
Generates 8-bit tables instead of 7-bit tables. On systems with 8-bit character sets (such as this one), this option is always enabled.
–c
Generates C code. Because this is the default, this option is provided only for compatibility with other implementations.
–h
Prints a brief list of the options and quits.
–l
Suppresses #line directives in the generated code.
–n
Suppresses the display of table sizes by the –v option. If you did not specify –v and their are no table sizes specified in file.1, lex behaves as though you specified –n.
–o file.c
Writes the lexical analyzer (internal state tables) onto the named output file, instead of the default file lex.yy.c.
–P proto
Uses the named code file, instead of the default prototype file /etc/yylex.c.
–p prefix
Uses the given prefix instead of the prefix yy in the generated code.
–T
Writes a description of the analyzer onto the file l.output.
–t
Writes the lexical analyzer onto standard output (stdout) instead of the file lex.yy.c.
–v
Displays the space used by the various internal tables. Normally lex displays these statistics on stdout, but if you also specified the –t option, it displays them on stderr. If you did not choose this option and file.1 specifies table sizes, lex still displays these statistics unless you specified the –n option.

The lex library contains a number of functions essential for use with lex. These functions are described in z/OS UNIX System Services Programming Tools . The actual library to use depends on your system and compiler. For z/OS programs, you should use –ll.

Some lex programs can cause one or more tables within lex to overflow. These tables are the NFA, DFA, and move tables; lex displays an appropriate message if an overflow occurs. Change table sizes by inserting the appropriate line into the definition section of the lex input, with the number size giving the number of entries to use. This is shown in Table 1.

Table 1. Internal table sizes (lex command)
Line Table size affected Default
%esize Number of NFA entries 1000
%nsize Number of DFA entries 500
%psize Number of move entries 2500

You can often reduce the NFA and DFA space to make room for more move entries.

Files

lex uses the following files:
l.output
Scanner machine description
lex.yy.c
Tables and action routines
/etc/yylex.c
The prototype lex scanner
/usr/lib/libl.a
lex archive library with functions compiled for 31–bit addressing mode.
/usr/lib/liblxp.a
lex archive library with functions compiled with XPLINK. Includes two versions: 64–bit addressing mode and 31–bit addressing mode.

Localization

lex uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_COLLATE
  • LC_CTYPE
  • LC_MESSAGES
  • LC_SYNTAX
  • NLSPATH

See Localization for more information.

Exit values

0
Successful completion
1
Failure due to any of the following reasons:
  • Inability to create an output file
  • Inability to open the file
  • Missing output file name after –o
  • Missing prefix after –p
  • No lex rules
  • No memory for DFA moves
  • Out of NFA state space
  • Out of DFA move space
  • Out of DFA state space
  • Push-back buffer overflow
  • Read error on file
  • Table too large for machine
  • Too many character classes
  • Too many translations
  • Unknown option
  • Write error on file
  • Incomplete %{ declaration
  • Token buffer overflow

Limits

The parser stack depth is limited to 150 levels. Attempting to process complicated syntaxes might result in an overflow, causing an error.

Portability

POSIX.2, POSIX.2 C-Language Development Utilities Option, UNIX systems.

The –a, –h, –l, –o, –p, –P, and –T options are extensions of the POSIX standard.

Related information

yacc

For more information, see z/OS UNIX System Services Programming Tools.