Skip to Main Content
flex & bison
book

flex & bison

by John Levine
August 2009
Intermediate to advanced content levelIntermediate to advanced
292 pages
7h 31m
English
O'Reilly Media, Inc.
Content preview from flex & bison

Chapter 6. A Reference for Bison Specifications

In this chapter we describe the syntax of bison programs, along with the various options and support functions available. POSIX yacc is almost an exact subset of bison, so we note which parts of bison are extensions beyond what POSIX requires.

After the section on the structure of a bison grammar, the sections in this chapter are in alphabetical order by feature.

Structure of a Bison Grammar

A bison grammar consists of three sections: the definition section, the rules section, and the user subroutines section.

    ... definition section ...
    %%
    ... rules section ...
    %%
    ... user subroutines section ...

The sections are separated by lines consisting of two percent signs. The first two sections are required, although a section may be empty. The third section and the preceding %% line may be omitted.

Symbols

A bison grammar is constructed from symbols, which are the “words” of the grammar. Symbols are strings of letters, digits, periods, and underscores that do not start with a digit. The symbol error is reserved for error recovery; otherwise, bison attaches no fixed meaning to any symbol. (Since bison defines a C preprocessor symbol for each token, you also need to be sure token names don’t collide with C reserved words or bison’s own symbols such as yyparse, or strange errors will ensue.)

Symbols produced by the lexer are called terminal symbols or tokens. Those that are defined on the left-hand side of rules are called nonterminal symbols or

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Design Patterns, 2nd Edition

Head First Design Patterns, 2nd Edition

Eric Freeman, Elisabeth Robson
Learning React, 2nd Edition

Learning React, 2nd Edition

Alex Banks, Eve Porcello

Publisher Resources

ISBN: 9780596805418Errata Page