flex 与 bison(影印版)

Preface
1. Introducing Flex and Bison
Lexical Analysis and Pa ing
Regular Expressio and Scanning
Our Fi t Flex Program
Programs in Plain Flex
Putting Flex and Bison Together
The Scanner as Coroutine
Toke and Values
Gramma and Pa ing
BNF Gramma
Bison's Rule Input Language
Compiling Flex and Bison Programs Together
Ambiguous Gramma : Not Quite
Adding a Few More Rules
Flex and Bison vs. Handwritten Scanne and Pa e
Exercises
2. Using Flex
Regular Expressio
Regular Expression Examples
How Flex Handles Ambiguous Patter
Context-Dependent Toke
File I/O in Flex Scanne
Reading Several Files
The I/O Structure of a Flex Scanner
Input to a Flex Scanner
Flex Scanner Output
Start States and Nested Input Files
Symbol Tables and a Concordance Generator
Managing Symbol Tables
Using a Symbol Table
C Language Cross-Reference
Exercises
3. Using Bison
How a Bison Pa er Matches Its Input
Shift/Reduce Pa ing
What Bison's LALR(1) Pa er Cannot Pa e
A Bison Pa er
Abstract Syntax Trees
An Improved Calculator That Creates ASTs
Literal Character Toke
Building the AST Calculator
Shift/Reduce Conflicts and Operator Precedence
When Not to Use Precedence Rules
An Advanced Calculator
Advanced Calculator Pa er
Calculator Statement Syntax
Calculator Expression Syntax
Top-Level Calculator Grammar
Basic Pa er Error Recovery
The Advanced Calculator Lexer
Reserved Words
Building and Interpreting ASTs
Evaluating Functio in the Calculator
User-Defined Functio
Using the Advanced Calculator
Exercises
4. Pa ing SQL
A Quick Overview of SQL
Relational Databases
Manipulating Relatio
hree Ways to Use SQL
SQL to RPN
The Lexer
Scanning SQL Keywords
Scanning Numbe
Scanning Operato and Punctuation
Scanning Functio and Names
Comments and Miscellany
The Pa er
The Top-Level Pa ing Rules
SQL Expressio
Select Statements
Delete Statement
I ert and Replace Statements
Update Statement
Create Database
Create Table
User Variables
The Pa er Routines
The Makefile for the SQL Pa er
Exercises
5. A Reference for Flex Specificatio
Structure of a Flex Specification
Definition Section
Rules Section
User Subroutines
BEGIN
C++ Scanne
Context Se itivity
Left Context
Right Context
Definitio (Substitutio )
ECHO
Input Management
Stdio File Chaining
Input Buffe
Input from Strings
File Nesting
input()
YY_INPUT
Flex Library
Interactive and Batch Scanne
Line Numbe and yylineno
Literal Block
Multiple Lexe in One Program
Combined Lexe
Multiple Lexe
Optio When Building a Scanner
Portability of Flex Lexe
Porting Generated C Lexe
Reentrant Scanne
Extra Data for Reentrant Scanne
Access to Reentrant Scanner Data
Reentrant Scanne , Nested Files, and Multiple Scanne
Using Reentrant Scanne with Bison
Regular Expression Syntax
Metacharacte
REJECT
Returning Values from yylex()
Start States
unput()
yyinput() yyunput()
yyleng
yyless()
yylex() and YY_DECL
yymore()
yyrestart()
yy_scan_string and yy_scan_buffer
YY_USER_ACTION
yywrap()
6. A Reference for Bison Specificatio
Structure of a Bison Grammar
Symbols
Definition Section
Rules Section
User Subroutines Section
Actio
Embedded Actio
Symbol Types for Embedded Actio
Ambiguity and Conflicts
Types of Conflicts
Shift/Reduce Conflicts
Reduce/Reduce Conflicts
%expect
GLR Pa e
Bugs in Bison Programs
Infinite Recu ion
Interchanging Precedence
Embedded Actio
C++ Pa e
%code Blocks
End Marker
Error Token and Error Recovery
%destructor
Inherited Attributes ($0)
Symbol Types for Inherited Attributes
%initial-action
Lexical Feedback
Literal Block
Literal Toke
Locatio
%pa e-param
Portability of Bison Pa e
Porting Bison Gramma
Porting Generated C Pa e
Libraries
Character Codes
Precedence and Associativity Declaratio
Precedence
Associativity
Precedence Declaratio
Using Precedence and Associativity to Resolve Conflicts
Typical Uses of Precedence
Recu ive Rules
Left and Right Recu ion
Rules
Special Characte
%start Declaration
Symbol Values
Declaring Symbol Types
Explicit Symbol Types
Toke
Token Numbe
Token Values
%type Declaration
%union Declaration
Variant and Multiple Gramma
Combined Pa e
Multiple Pa e
Using %name-prefix or the -p Flag
Lexe for Multiple Pa e
Pure Pa e
y.output Files
Bison Library
main()
yyerror()
YYABORT
YYACCEPT
YYBACKUP
yyclearin
yydebug and YYDEBUG
YYDEBUG
yydebug
yyerrok
YYERROR
yyerror()
yypa e()
YYRECOVERING()
7. Ambiguities and Conflicts
The Pointer Model and Conflicts
Kinds of Conflicts
Pa er States
Contents of name.output
Reduce/Reduce Conflicts
Shift/Reduce Conflicts
Review of Conflicts in name.output
Common Examples of Conflicts
Expression Gramma
IF/THEN/ELSE
Nested List Grammar
How Do You Fix the Conflict?
IF/THEN/ELSE (Shift/Reduce)
Loop Within a Loop (Shift/Reduce)
Expression Precedence (Shift/Reduce)
Limited Lookahead (Shift/Reduce or Reduce/Reduce)
Overlap of Alternatives (Reduce/Reduce)
Summary
Exercises
8. Error Reporting and Recovery
Error Reporting
Locatio
Adding Locatio to the Pa er
Adding Locatio to the Lexer
More Sophisticated Locatio with Filenames
Error Recovery
Bison Error Recovery
Freeing Discarded Symbols
Error Recovery in Interactive Pa e
Where to Put Error Toke
Compiler Error Recovery
Exercises
9. Advanced Flex and Bison
Pure Scanne and Pa e
Pure Scanne in Flex
Pure Pa e in Bison
Using Pure Scanne and Pa e Together
A Reentrant Calculator
GLR Pa ing
GLR Ve ion of the SQL Pa er
C++ Pa e
A C++ Calculator
C++ Pa er Naming
A C++ Pa er
Interfacing a Scanner with a C++ Pa er
Should You Write Your Pa er in C++ ?
Exercises
Appendix: SQL Pa er Grammar and Cross-Reference
Glossary
Index
1. Introducing Flex and Bison
Lexical Analysis and Pa ing
Regular Expressio and Scanning
Our Fi t Flex Program
Programs in Plain Flex
Putting Flex and Bison Together
The Scanner as Coroutine
Toke and Values
Gramma and Pa ing
BNF Gramma
Bison's Rule Input Language
Compiling Flex and Bison Programs Together
Ambiguous Gramma : Not Quite
Adding a Few More Rules
Flex and Bison vs. Handwritten Scanne and Pa e
Exercises
2. Using Flex
Regular Expressio
Regular Expression Examples
How Flex Handles Ambiguous Patter
Context-Dependent Toke
File I/O in Flex Scanne
Reading Several Files
The I/O Structure of a Flex Scanner
Input to a Flex Scanner
Flex Scanner Output
Start States and Nested Input Files
Symbol Tables and a Concordance Generator
Managing Symbol Tables
Using a Symbol Table
C Language Cross-Reference
Exercises
3. Using Bison
How a Bison Pa er Matches Its Input
Shift/Reduce Pa ing
What Bison's LALR(1) Pa er Cannot Pa e
A Bison Pa er
Abstract Syntax Trees
An Improved Calculator That Creates ASTs
Literal Character Toke
Building the AST Calculator
Shift/Reduce Conflicts and Operator Precedence
When Not to Use Precedence Rules
An Advanced Calculator
Advanced Calculator Pa er
Calculator Statement Syntax
Calculator Expression Syntax
Top-Level Calculator Grammar
Basic Pa er Error Recovery
The Advanced Calculator Lexer
Reserved Words
Building and Interpreting ASTs
Evaluating Functio in the Calculator
User-Defined Functio
Using the Advanced Calculator
Exercises
4. Pa ing SQL
A Quick Overview of SQL
Relational Databases
Manipulating Relatio
hree Ways to Use SQL
SQL to RPN
The Lexer
Scanning SQL Keywords
Scanning Numbe
Scanning Operato and Punctuation
Scanning Functio and Names
Comments and Miscellany
The Pa er
The Top-Level Pa ing Rules
SQL Expressio
Select Statements
Delete Statement
I ert and Replace Statements
Update Statement
Create Database
Create Table
User Variables
The Pa er Routines
The Makefile for the SQL Pa er
Exercises
5. A Reference for Flex Specificatio
Structure of a Flex Specification
Definition Section
Rules Section
User Subroutines
BEGIN
C++ Scanne
Context Se itivity
Left Context
Right Context
Definitio (Substitutio )
ECHO
Input Management
Stdio File Chaining
Input Buffe
Input from Strings
File Nesting
input()
YY_INPUT
Flex Library
Interactive and Batch Scanne
Line Numbe and yylineno
Literal Block
Multiple Lexe in One Program
Combined Lexe
Multiple Lexe
Optio When Building a Scanner
Portability of Flex Lexe
Porting Generated C Lexe
Reentrant Scanne
Extra Data for Reentrant Scanne
Access to Reentrant Scanner Data
Reentrant Scanne , Nested Files, and Multiple Scanne
Using Reentrant Scanne with Bison
Regular Expression Syntax
Metacharacte
REJECT
Returning Values from yylex()
Start States
unput()
yyinput() yyunput()
yyleng
yyless()
yylex() and YY_DECL
yymore()
yyrestart()
yy_scan_string and yy_scan_buffer
YY_USER_ACTION
yywrap()
6. A Reference for Bison Specificatio
Structure of a Bison Grammar
Symbols
Definition Section
Rules Section
User Subroutines Section
Actio
Embedded Actio
Symbol Types for Embedded Actio
Ambiguity and Conflicts
Types of Conflicts
Shift/Reduce Conflicts
Reduce/Reduce Conflicts
%expect
GLR Pa e
Bugs in Bison Programs
Infinite Recu ion
Interchanging Precedence
Embedded Actio
C++ Pa e
%code Blocks
End Marker
Error Token and Error Recovery
%destructor
Inherited Attributes ($0)
Symbol Types for Inherited Attributes
%initial-action
Lexical Feedback
Literal Block
Literal Toke
Locatio
%pa e-param
Portability of Bison Pa e
Porting Bison Gramma
Porting Generated C Pa e
Libraries
Character Codes
Precedence and Associativity Declaratio
Precedence
Associativity
Precedence Declaratio
Using Precedence and Associativity to Resolve Conflicts
Typical Uses of Precedence
Recu ive Rules
Left and Right Recu ion
Rules
Special Characte
%start Declaration
Symbol Values
Declaring Symbol Types
Explicit Symbol Types
Toke
Token Numbe
Token Values
%type Declaration
%union Declaration
Variant and Multiple Gramma
Combined Pa e
Multiple Pa e
Using %name-prefix or the -p Flag
Lexe for Multiple Pa e
Pure Pa e
y.output Files
Bison Library
main()
yyerror()
YYABORT
YYACCEPT
YYBACKUP
yyclearin
yydebug and YYDEBUG
YYDEBUG
yydebug
yyerrok
YYERROR
yyerror()
yypa e()
YYRECOVERING()
7. Ambiguities and Conflicts
The Pointer Model and Conflicts
Kinds of Conflicts
Pa er States
Contents of name.output
Reduce/Reduce Conflicts
Shift/Reduce Conflicts
Review of Conflicts in name.output
Common Examples of Conflicts
Expression Gramma
IF/THEN/ELSE
Nested List Grammar
How Do You Fix the Conflict?
IF/THEN/ELSE (Shift/Reduce)
Loop Within a Loop (Shift/Reduce)
Expression Precedence (Shift/Reduce)
Limited Lookahead (Shift/Reduce or Reduce/Reduce)
Overlap of Alternatives (Reduce/Reduce)
Summary
Exercises
8. Error Reporting and Recovery
Error Reporting
Locatio
Adding Locatio to the Pa er
Adding Locatio to the Lexer
More Sophisticated Locatio with Filenames
Error Recovery
Bison Error Recovery
Freeing Discarded Symbols
Error Recovery in Interactive Pa e
Where to Put Error Toke
Compiler Error Recovery
Exercises
9. Advanced Flex and Bison
Pure Scanne and Pa e
Pure Scanne in Flex
Pure Pa e in Bison
Using Pure Scanne and Pa e Together
A Reentrant Calculator
GLR Pa ing
GLR Ve ion of the SQL Pa er
C++ Pa e
A C++ Calculator
C++ Pa er Naming
A C++ Pa er
Interfacing a Scanner with a C++ Pa er
Should You Write Your Pa er in C++ ?
Exercises
Appendix: SQL Pa er Grammar and Cross-Reference
Glossary
Index
如果你需要分析或处理Linux或Unix中的文本数据,这本有用的书籍就向你讲解了如何使用flex和bison迅速解决问题。《flex与bison》被期待已久,是经典OReilly系列书籍《lex&yacc》的续篇。在原书出版以来的近20年中,flex和bison已被证明比原来的Unix工具更可靠、更强大。《flex与bison》一书涵盖了Linux和Unix程序开发中相同的重要核心功能,以及一些重要的新主题。你会找到适用于新手的修订教程和适用于高级用户的参考资料,以及对每个程序的基本用法的解释,并且运用它们创建简单、独立的应用程序。有了《flex与bison》,你会发现这些灵活的工具提供的广泛用途。
比价列表
公众号、微信群

微信公众号

实时获取购书优惠