O'Reilly logo

lex & yacc, 2nd Edition by Tony Mason, John Levine, Doug Brown

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. AT&T Lex

AT&T lex is the most common version found on UNIX systems. If you’re not sure which version of lex you have, try running a lexer through it with the -v flag. If the produces a terse two-line summary like this, it’s AT&T lex:

    5/2000 nodes(%e), 16/5000 positions(%p), 5/2500 (%n),
    4 transitions, 0/1000 packed char classes(%k), 6/5000
    packed transitions(%a), 113/5000 output slots(%o)

If produces a page of statistics with lex’s version number on the first line, it’s flex.

Lex processes a specification file and generates source code for a lexical analyzer. By convention, the specification file has a .l extension. The file that lex generates is named lex.yy.c.

The syntax of the AT&T lex command is:

lex [options] file

where options are as follows:

-c

Writes the lexer in C (default). The obsolescent flag is not present in many versions.

-n

Don’t print the summary line with the table sizes. This is the default unless the definition section changes the size of one of lex’s internal tables.

-r

Actions are written in RATFOR, a dialect of FORTRAN. This option no longer works in most versions of lex, and is not even present in many of them.

-t

Source code is sent to standard output instead of to the default file lex.yy.c. This is useful in Makefiles and shell scripts that direct the output of lex to a named file.

-v

Generates a one-line statistical summary of the finite state machine. This option is implied when any of the tables sizes are specified in the definitions section ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required