Bison
The YACC-compatible Parser Generator
December 1992, Bison Version 1.20
by Charles Donnelly and Richard Stallman
Introduction
Conditions for Using Bison
GNU GENERAL PUBLIC LICENSE
Preamble
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
How to Apply These Terms to Your New Programs
The Concepts of Bison
Languages and Context-Free Grammars
From Formal Rules to Bison Input
Semantic Values
Semantic Actions
Bison Output: the Parser File
Stages in Using Bison
The Overall Layout of a Bison Grammar
Examples
Reverse Polish Notation Calculator
Declarations for
rpcalc
Grammar Rules for
rpcalc
Explanation of
input
Explanation of
line
Explanation of
expr
The
rpcalc
Lexical Analyzer
The Controlling Function
The Error Reporting Routine
Running Bison to Make the Parser
Compiling the Parser File
Infix Notation Calculator:
calc
Simple Error Recovery
Multi-Function Calculator:
mfcalc
Declarations for
mfcalc
Grammar Rules for
mfcalc
The
mfcalc
Symbol Table
Exercises
Bison Grammar Files
Outline of a Bison Grammar
The C Declarations Section
The Bison Declarations Section
The Grammar Rules Section
The Additional C Code Section
Symbols, Terminal and Nonterminal
Syntax of Grammar Rules
Recursive Rules
Defining Language Semantics
Data Types of Semantic Values
More Than One Value Type
Actions
Data Types of Values in Actions
Actions in Mid-Rule
Bison Declarations
Token Type Names
Operator Precedence
The Collection of Value Types
Nonterminal Symbols
Suppressing Conflict Warnings
The Start-Symbol
A Pure (Reentrant) Parser
Bison Declaration Summary
Multiple Parsers in the Same Program
Parser C-Language Interface
The Parser Function
yyparse
The Lexical Analyzer Function
yylex
Calling Convention for
yylex
Semantic Values of Tokens
Textual Positions of Tokens
Calling for Pure Parsers
The Error Reporting Function
yyerror
Special Features for Use in Actions
The Bison Parser Algorithm
Look-Ahead Tokens
Shift/Reduce Conflicts
Operator Precedence
When Precedence is Needed
Specifying Operator Precedence
Precedence Examples
How Precedence Works
Context-Dependent Precedence
Parser States
Reduce/Reduce Conflicts
Mysterious Reduce/Reduce Conflicts
Stack Overflow, and How to Avoid It
Error Recovery
Handling Context Dependencies
Semantic Info in Token Types
Lexical Tie-ins
Lexical Tie-ins and Error Recovery
Debugging Your Parser
Invoking Bison
Bison Options
Option Cross Key
Invoking Bison under VMS
Bison Symbols
Glossary
Index