Bisonc++ (Version 6.02.00) User Guide

Frank B. Brokken

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

2005-2018

Table of Contents

Chapter 1: Introduction

1.1: What's new in version 6.02.00

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: Using Bisonc++: main steps

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

Chapter 4: Bisonc++ grammar files

4.1: Outline of a Bisonc++ Grammar File

4.2: Symbols, Terminal and Nonterminal Symbols

4.3: Syntax of Grammar Rules

4.4: Writing recursive rules

4.5: Bisonc++ Directives

4.5.1: %baseclass-preinclude: specifying a header included by the baseclass
4.5.2: %class-name: defining the name of the parser class
4.5.3: %debug: adding debugging code to the `parse()' member
4.5.4: %default-actions: adding `$$ = $1' action blocks to production rules
4.5.5: %error-verbose: dumping the parser's state stack
4.5.6: %expect: suppressing conflict warnings
4.5.7: %flex: using the traditional `flex++' interface
4.5.8: %include: splitting the input file
4.5.9: %left, %right, %nonassoc: defining operator precedence
4.5.10: %locationstruct: specifying a dedicated location struct
4.5.11: %lsp-needed: using the default location type
4.5.12: %ltype: using an existing location type
4.5.13: %namespace: using a namespace
4.5.14: %negative-dollar-indices: using constructions like $-1
4.5.15: %no-lines: suppressing `#line' directives
4.5.16: %polymorphic: using polymorphism to define multiple semantic values
4.5.17: %prec: overruling default precedences
4.5.18: %print-tokens: displaying tokens and matched text
4.5.19: %prompt: show prompts when using debug
4.5.20: %required-tokens: defining the minimum number of tokens between error reports
4.5.21: %scanner: using a standard scanner interface
4.5.22: %scanner-matched-text-function: define the name of the scanner's member returning the matched texttoken
4.5.23: %scanner-token-function: define the name of the scanner's token function
4.5.24: %stack-expansion: the number of elements added to the semantic value stack
4.5.25: %start: defining the start rule
4.5.26: %stype: defining a single semantic value type
4.5.27: %tag-mismatches: check for tag-mismatches with polymorphic semantic values
4.5.28: %thread-safe: use thread-local data with polymorphic semantic values
4.5.29: %token: defining token names
4.5.29.1: Improper token names
4.5.30: %type: associating semantic values with (non)terminals
4.5.31: %union: using a 'union' to define multiple semantic values
4.5.32: %weak-tags: %polymorphic declaring 'enum Tag_'
4.5.33: Directives controlling the names of generated files
4.5.33.1: %baseclass-header: defining the parser's base class header
4.5.33.2: %class-header: defining the parser's class header
4.5.33.3: %filenames: specifying a generic filename
4.5.33.4: %implementation-header: defining the implementation header
4.5.33.5: %parsefun-source: defining the parse() function's sourcefile
4.5.33.6: %target-directory: defining the directory where files must be written

4.6: The Meaning Of Things: Semantics

4.6.1: Polymorphism and Multiple Semantic Values: `%polymorphic'
4.6.1.1: The %polymorphic directive
4.6.1.2: Code generated by %polymorphic
4.6.1.3: A parser using a polymorphic semantic value type
4.6.1.4: A scanner using a polymorphic semantic value type
4.6.2: Actions and shorthand ($) notations
4.6.2.1: %stype shorthand notations
4.6.2.2: %union shorthand notations
4.6.2.3: %polymorphic shorthand notations
4.6.2.4: Mid-Rule Action Blocks

4.7: Basic Grammatical Constructions

4.7.1: Plain Alternatives
4.7.2: One Or More Alternatives, No Separators
4.7.3: Zero Or More Alternatives, No Separators
4.7.4: One Or More Alternatives, Using Separators
4.7.5: Zero Or More Alternatives, Using Separators
4.7.6: Nested Blocks

4.8: Multiple Parsers in the Same Program

Chapter 5: The Generated Parser Class' Members

5.1: Public Symbols

5.2: Protected Enumerations and Types

5.3: Non-public Member Functions

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

5.4: Protected Data Members

5.5: Types and Variables in the Anonymous Namespace

5.6: Summary of Special Constructions for Actions

Chapter 6: Examples

6.1: Rpn: a Reverse Polish Notation Calculator

6.1.1: Declarations for the `rpn' calculator
6.1.2: Grammar rules for the `rpn' calculator
6.1.2.1: Explanation of `input'
6.1.2.2: Explanation of `line'
6.1.2.3: Explanation of `expr'
6.1.3: The Lexical Scanner used by `rpn'
6.1.4: The Controlling Function `main()'
6.1.5: The error reporting member `error()'
6.1.6: Running Bisonc++ to generate the Parser
6.1.7: Constructing and running `rpn'

6.2: `calc': an Infix Notation Calculator

6.3: Basic Error Recovery

6.4: `mfcalc': a Multi-Function Calculator

6.4.1: The Declaration Section for `mfcalc'
6.4.2: Grammar Rules for `mfcalc'
6.4.3: The `mfcalc' Symbol- and Function Tables
6.4.4: The new `lex()' member
6.4.5: Constructing `mfcalc'

6.5: Exercises

Chapter 7: About Analyzing LALR(1) Grammars

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: Syntactic Error Recovery

8.1.1: Error Recovery

8.2: Semantic Error Recovery

Chapter 9: Invoking Bisonc++

9.1: Bisonc++ options

9.2: Bisonc++ usage