Bisonc++ (Version 4.10.01) User Guide

Frank B. Brokken

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

2005-2015

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: Bisonc++ Directives

5.5.1: %baseclass-preinclude: specifying a header included by the baseclass
5.5.2: %class-name: defining the name of the parser class
5.5.3: %debug: adding debugging code to the `parse()' member
5.5.4: %error-verbose: dumping the parser's state stack
5.5.5: %expect: suppressing conflict warnings
5.5.6: %flex: using the traditional `flex++' interface
5.5.7: %include: splitting the input file
5.5.8: %left, %right, %nonassoc: defining operator precedence
5.5.9: %locationstruct: specifying a dedicated location struct
5.5.10: %lsp-needed: using the default location type
5.5.11: %ltype: using an existing location type
5.5.12: %namespace: using a namespace
5.5.13: %negative-dollar-indices: using constructions like $-1
5.5.14: %no-lines: suppressing `#line' directives
5.5.15: %prec: overruling default precedences
5.5.16: %polymorphic: using polymorphism to define multiple semantic values
5.5.17: %print-tokens: displaying tokens and matched text
5.5.18: %required-tokens: defining the minimum number of tokens between error reports
5.5.19: %scanner: using a standard scanner interface
5.5.20: %scanner-matched-text-function: define the name of the scanner's member returning the matched texttoken
5.5.21: %scanner-token-function: define the name of the scanner's token function
5.5.22: %start: defining the start rule
5.5.23: %stype: specifying the semantic stack type
5.5.24: %token: defining token names
5.5.24.1: Improper token names
5.5.25: %type: associating semantic values to (non)terminals
5.5.26: %union: using a 'union' to define multiple semantic values
5.5.27: %weak-tags: %polymorphic declaring 'enum Tag__'
5.5.28: Directives controlling the names of generated files
5.5.28.1: %baseclass-header: defining the parser's base class header
5.5.28.2: %class-header: defining the parser's class header
5.5.28.3: %filenames: specifying a generic filename
5.5.28.4: %implementation-header: defining the implementation header
5.5.28.5: %parsefun-source: defining the parse() function's sourcefile
5.5.28.6: %target-directory: defining the directory where files must be written

5.6: Defining Language Semantics

5.6.1: Data Types of Semantic Values
5.6.2: More Than One Value Type
5.6.3: Polymorphism and multiple semantic values: `%polymorphic'
5.6.3.1: The %polymorphic directive
5.6.3.2: The %polymorphic and %type: associating semantic values with (non-)terminals
5.6.3.3: Code generated by %polymorphic
5.6.3.4: A parser using a polymorphic semantic value type
5.6.3.5: A scanner using a polymorphic semantic value type
5.6.4: Actions
5.6.5: Data Types of Values in Actions
5.6.6: Actions in Mid-Rule

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.0.1: The FIRST Sets
7.0.2: The States
7.0.3: The Look-ahead Sets
7.0.3.1: The look-ahead token
7.0.3.2: How look-ahead sets are determined
7.0.4: The Final Transition Tables
7.0.4.1: Preamble
7.0.5: Processing Input

7.1: Shift/Reduce Conflicts

7.2: Operator Precedence

7.2.1: When Precedence is Needed
7.2.2: Specifying Operator Precedence
7.2.3: Precedence Examples
7.2.4: How Precedence Works
7.2.5: Rule precedence

7.3: Context-Dependent Precedence

7.4: Reduce/Reduce Conflicts

7.5: 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