Lex & Yacc

Front Cover
"O'Reilly Media, Inc.", 1992 - Computers - 366 pages
10 Reviews

This book shows you how to use two Unix utilities, lex andyacc, in program development. These tools help programmers build compilers and interpreters, but they also have a wider range of applications.

The second edition contains completely revised tutorial sections for novice users and reference sections for advanced users. This edition is twice the size of the first and has an expanded index.

The following material has been added:

  • Each utility is explained in a chapter that covers basic usage and simple, stand-alone applications
  • How to implement a full SQL grammar, with full sample code
  • Major MS-DOS and Unix versions of lex and yacc are explored in depth, including AT&T lex and yacc, Berkeley yacc, Berkeley/GNU Flex, GNU Bison, MKS lex andyacc, and Abraxas PCYACC
  

What people are saying - Write a review

User ratings

5 stars
5
4 stars
3
3 stars
1
2 stars
1
1 star
0

User Review - Flag as inappropriate

bought this book way back in 2001, still on my study desk. worth every penny.

Review: Lex & Yacc

User Review  - Will - Goodreads

Very helpful, lots of useful examples. Read full review

Contents

Lex and Yacc
1
The Simplest Lex Program
2
Recognizing Words with Lex
3
Grammars
13
Running Lex and Yacc
21
Lex vs Handwritten Lexers
22
Exercises
25
Using Lex
27
A Reference for Yacc Grammars
181
Actions
182
Ambiguity and Conflicts
184
Bugs in Yacc
186
End Marker
188
ident Declaration
189
Lexical Feedback
191
Literal Block
192

Regular Expressions
28
A Word Counting Program
32
Parsing a Command Line
38
A C Source Code Analyzer
45
Summary
48
Exercises
49
Using Yacc
51
ShiftReduce Parsing
53
A Yacc Parser
56
The Lexer
58
Arithmetic Expressions and Ambiguity
60
Variables and Typed Tokens
64
Symbol Tables
67
Functions and Reserved Words
71
Building Parsers with Make
77
Summary
78
A Menu Generation Language
81
Developing the MGL
83
Building the MGL
92
Screen Processing
97
Termination
100
Sample MGL Code
102
Exercises
107
Parsing SQL
109
The Syntax Checker
114
The Parser
119
Embedded SQL
141
Exercises
146
A Reference for Lex Specifications
147
BEGIN
149
Character Translations
150
Context Sensitivity
151
Definitions Substitutions
153
ECHO
154
Input from Strings
156
input
158
Internal Tables N Declarations
159
lex Library
160
Literal Block
161
output
165
Portability of Lex Lexers
166
Regular Expression Syntax
167
REJECT
170
Returning Values from yylex
171
unput
173
yyinput yyoutput yyunput
174
yylex
175
yymore
176
yytext
177
yywrap
179
Portability of Yacc Parsers
193
Precedence Associativity and Operator Declarations
194
Recursive Rules
197
Rules
198
Special Characters
199
Start Declaration
201
Tokens
202
type Declaration
204
union Declaration
205
youtput Files
210
Yacc Library
211
YYABORT
212
YYBACKUP
213
yyerrok
214
YYERROR
215
yyparse
216
Yacc Ambiguities and Conflicts
217
Common Examples of Conflicts
229
How Do I Fix the Conflict?
233
Summary
240
Exercises
241
Error Reporting and Recovery
243
Error Recovery
247
Exercises
252
ATT Lex
253
Error Messages
254
ATT Yacc
261
Error Messages
262
Berkeley Yacc
271
GNU Bison
277
Flex
279
Options
280
Error Messages
281
Flex Versions of Lexer Examples
285
MKS lex and yacc
289
New Features
290
Abraxas lex and yacc
291
POSIX lex and yacc
293
Differences
294
MGL Compiler Code
295
MGL Lex Source
299
Supporting C Code
300
SQL Parser Code
309
Lex Scanner
326
Supporting Code
329
Glossary
333
Bibliography
339
Index
341
Copyright

Common terms and phrases

References to this book

All Book Search results »

About the author (1992)

Gregory Satir helps develop online publishing tools in the Portland, Oregon, office of Electronic Book Technologies. He graduated with a B.S. in computer science from Brown University. Doug Brown is a consultant/contractor in Beaverton, Oregon. He has been developing software for circuit simulation, synthesis, and testing since 1977. Doug coauthored lex & yacc, another O'Reilly & Associates Nutshell Handbook. He received an M.S. in electrical engineering from the University of Illinois at Urbana-Champaign in 1976.

John R. Levine writes, lectures, and consults on Unix and compiler topics. He moderates the online comp.compilers discussion group at Usenet. He worked on Unix versions Lotus 1-2-3 and the Norton Utilities and was one of the architects of AIX for the IBM RT PC. He received a Ph.D in computer science from Yale in 1984.

Tony Mason is currently a member of the AFS development team at Transarc Corporation, a small start-up company specializing in distributed systems software. Previously, he worked with the Distributed Systems Group at Stanford University in the area of distributed operating systems and data communications. He received a B.S. in mathematics from the University of Chicago in 1987.

Bibliographic information