Skip to Content
lex & yacc, 2nd Edition
book

lex & yacc, 2nd Edition

by John Levine, Doug Brown, Tony Mason
October 1992
Intermediate to advanced
384 pages
7h 8m
English
O'Reilly Media, Inc.
Content preview from lex & yacc, 2nd Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

The GNU Make Book

The GNU Make Book

John Graham-Cumming
Learn LLVM 12

Learn LLVM 12

Kai Nacke
flex & bison

flex & bison

John Levine

Publisher Resources

ISBN: 9781565920002Errata Page