<center><strong>Bisonc++</strong> (Version 2.4.5) User Guide</center>

Bisonc++ (Version 2.4.5) User Guide

Frank B. Brokken

Center for Information Technology,
University of Groningen
Nettelbosje 1,
P.O. Box 11044,
9700 CA Groningen
The Netherlands

2005-2008

Table of Contents

Chapter 1: Introduction

Chapter 2: Conditions for Using Bisonc++

2.1: The `GNU General Public License' (GPL)

Chapter 3: Bisonc++ concepts

3.1: Languages and Context-Free Grammars

3.2: From Formal Rules to Bisonc++ Input

3.3: Semantic Values

3.4: Semantic Actions

3.5: Bisonc++ output: the Parser class

3.5.1: Bisonc++: an optionally reentrant Parser

3.6: Stages in Using Bisonc++

3.7: The Overall Layout of a Bisonc++ Grammar File

Chapter 4: Examples

4.1: rpn: a Reverse Polish Notation Calculator

4.1.1: Declarations for the `rpn' calculator
4.1.2: Grammar rules for the `rpn' calculator
4.1.2.1: Explanation of `input'
4.1.2.2: Explanation of `line'
4.1.2.3: Explanation of `expr'
4.1.3: The Lexical Scanner used by `rpn'
4.1.4: The Controlling Function `main()'
4.1.5: The error reporting member `error()'
4.1.6: Running Bisonc++ to generate the Parser
4.1.7: Constructing and running `rpn'

4.2: `calc': an Infix Notation Calculator

4.3: Basic Error Recovery

4.4: `mfcalc': a Multi-Function Calculator

4.4.1: The Declaration Section for `mfcalc'
4.4.2: Grammar Rules for `mfcalc'
4.4.3: The `mfcalc' Symbol- and Function Tables
4.4.4: The revised `lex()' member
4.4.5: Constructing `mfcalc'

4.5: Exercises

Chapter 5: Bisonc++ grammar files

5.1: Outline of a Bisonc++ Grammar File

5.2: Symbols, Terminal and Nonterminal Symbols

5.3: Syntax of Grammar Rules

5.4: Writing recursive rules

5.5: Defining Language Semantics

5.5.1: Data Types of Semantic Values
5.5.2: More Than One Value Type
5.5.3: More Than One Value Type: Using Polymorphism
5.5.3.1: The parser using a polymorphic semantic value type
5.5.3.2: The scanner using a polymorphic semantic value type
5.5.4: Actions
5.5.5: Data Types of Values in Actions
5.5.6: Actions in Mid-Rule

5.6: Bisonc++ Directives

5.6.1: %baseclass-preinclude: specifying a header included by the baseclass
5.6.2: %class-name: defining the name of the parser class
5.6.3: %debug: adding debugging code to the `parse()' member
5.6.4: %error-verbose: dumping the parser's state stack
5.6.5: %expect: suppressing conflict warnings
5.6.6: %include: splitting the input file
5.6.7: %left, %right, %nonassoc: defining operator precedence
5.6.8: %lines: inserting `#line' directives
5.6.9: %locationstruct: specifying a dedicated location struct
5.6.10: %lsp-needed: using the default location type
5.6.11: %ltype: using an existing location type
5.6.12: %namespace: using a namespace
5.6.13: %negative-dollar-indices: using constructions like $-1
5.6.14: %prec: overruling default precedences
5.6.15: %required-tokens: defining the minimum number of tokens between error reports
5.6.16: %scanner: using a standard scanner interface
5.6.17: %start: defining the start rule
5.6.18: %stype: specifying the semantic stack type
5.6.19: %token: defining token names
5.6.19.1: Improper token names
5.6.20: %type: associating semantic values to (non)terminals
5.6.21: %union: using multiple semantic values
5.6.22: Directives controlling the names of generated files
5.6.22.1: %baseclass-header: defining the parser's base class header
5.6.22.2: %class-header: defining the parser's class header
5.6.22.3: %filenames: specifying a generic filename
5.6.22.4: %implementation-header: defining the implementation header
5.6.22.5: %parsefun-source: defining the parse() function's sourcefile

5.7: Basic Grammatical Constructions

5.7.1: Plain Alternatives
5.7.2: One Or More Alternatives, No Separators
5.7.3: Zero Or More Alternatives, No Separators
5.7.4: One Or More Alternatives, Using Separators
5.7.5: Zero Or More Alternatives, Using Separators
5.7.6: Nested Blocks

5.8: Multiple Parsers in the Same Program

Chapter 6: The Generated Parser Class' Members

6.1: Public Members and Types

6.2: Protected Enumerations and Types

6.3: Non-public Member Functions

6.3.1: `lex()': Interfacing the Lexical Analyzer

6.4: Protected Data Members

6.5: Types and Variables in the Anonymous Namespace

6.6: Summary of Special Constructions for Actions

Chapter 7: The Bisonc++ Parser Algorithm

7.1: Analyzing A Grammar

7.1.1: The FIRST Sets
7.1.2: The FOLLOW Sets
7.1.3: The States
7.1.4: The Lookahead Sets
7.1.4.1: Preamble
7.1.5: The Final Transition Tables
7.1.5.1: Preamble
7.1.6: Processing Input

7.2: Shift/Reduce Conflicts

7.3: Operator Precedence

7.3.1: When Precedence is Needed
7.3.2: Specifying Operator Precedence
7.3.3: Precedence Examples
7.3.4: How Precedence Works

7.4: Context-Dependent Precedence

7.5: Reduce/Reduce Conflicts

7.6: Mysterious Reduce/Reduce Conflicts

Chapter 8: Error Recovery

8.1: Syntactical Error Recovery

8.1.1: Error Recovery
8.1.1.1: Error recovery --debug output

8.2: Semantical Error Recovery

Chapter 9: Invoking Bisonc++

9.1: Bisonc++ options

9.2: Bisonc++ usage