Computing Reviews
Today's Issue Hot Topics Search Browse Recommended My Account Log In
Review Help
Search
lex & yacc (2nd ed.)
Levine J., Mason T., Brown D., O’Reilly & Associates, Inc., Sebastopol, CA, 1992. Type: Book (9781565920002)
Date Reviewed: Jul 1 1993

The first edition of this book, written by Mason and Brown, was published in 1990 [1]. A number of developments in programming methodologies, standards, and hardware platforms have occurred since that time. John Levine has joined the original authors to produce a useful programmer’s guide that reflects some of those developments. A new chapter addresses parsing SQL statements, and some new appendices cover versions of lex and yacc for MS-DOS, OS/2, and other systems.

This book is intended for those who need to develop assemblers, compilers, menu generators, syntax checkers, and related utilities. It assumes a working knowledge of the C programming language. A series of graded examples is presented in each chapter, and the reader is encouraged to implement and develop an understanding of these as she or he moves through the book. The examples are available without charge through USENET, and the authors provide instructions for obtaining them using the uucp or anonymous ftp facilities.

Chapter 1 illustrates the capabilities of the lex lexical analyzer through a couple of examples that classify the words found in a sentence into verbs, adjectives, nouns, and so on. The examples show how the lex specifications are written as a series of rules for matching tokens; each rule has a set of action statements (written in C) that is executed when a match is found. The machine on which I tried these examples has an ancient C compiler, and I had to change them slightly to make them acceptable.

The lex examples of chapter 1 are then modified so that they can be called from the yacc parser. As explained in the text, yacc is an acronym for “yet another compiler-compiler.” Two simple yacc programs are developed to parse English sentences. The chapter concludes with some simple exercises.

Chapter 2, “Using Lex,” covers the use of lex in more detail, using a word-counting program and a C source code analyzer. Again, exercises are included at its end.

In a similar vein, chapter 3, “Using Yacc,” covers the use of yacc in more detail. A progressive series of examples leads eventually to the development of a simple desktop calculator that can assign values to variables and evaluate a range of arithmetic expressions. The concept of a Makefile is introduced to facilitate the multi-stage compile and load operations required for more complex applications.

In chapter 4, the authors direct their attention to compiler design, developing a compiler for a simple menu generation language. The resultant code could be applied directly in applications development.

An SQL parser is developed in chapter 5 as a means of illustrating the preprocessing of SQL statements embedded in C programs. One of the exercises at the end of the chapter suggests that the parser could also be extended into an SQL cross-referencer able to read a set of SQL statements and generate a report showing where each name is defined and referenced. My guess is that many readers would find such a tool useful in their everyday work.

Chapters 6 and 7, “A Reference for Lex Specifications” and “A Reference for Yacc Grammars,” include details relating to the standard functions found in lex libraries. They also list peculiarities of various implementations and illustrate some mechanisms for including multiple lexers and multiple parsers within the same program.

In chapter 8, the reader can learn how to resolve the conflicts that can arise within a yacc grammar. Chapter9 presents some techniques for incorporating error detection and reporting into a grammar. The reader is encouraged to estimate what should be found (for instance, at the end of a statement) as an aid to error recovery and resynchronization.

The appendices provide further details of the characteristics of various implementations, including AT&T Lex and Flex. These are followed by a glossary of the technical terms used in the book and a short bibliography. The book concludes with a comprehensive index.

If you have an application for lex and yacc, you should have this book on your shelf. Few other books provide such an appropriate combination of details and illustrative examples for these tools.

Reviewer:  G. K. Jenkins Review #: CR117031
1) Mason, T. and Brown, D. Lex and yacc. O’Reilly, Sebastopol, CA, 1990.
Bookmark and Share
  Featured Reviewer  
 
Lex (D.4.9 ... )
 
 
C (D.3.2 ... )
 
 
Unix (D.4.0 ... )
 
 
Yacc (D.4.9 ... )
 
 
Processors (D.3.4 )
 
Would you recommend this review?
yes
no
Other reviews under "Lex": Date
Lex & yacc
Mason T., Brown D., O’Reilly & Associates, Inc., Sebastopol, CA, 1990. Type: Book (9780937175491)
Jul 1 1991

E-Mail This Printer-Friendly
Send Your Comments
Contact Us
Reproduction in whole or in part without permission is prohibited.   Copyright 1999-2024 ThinkLoud®
Terms of Use
| Privacy Policy