(bison.info)Grammar Layout


Prev: Stages Up: Concepts

The Overall Layout of a Bison Grammar
=====================================

   The input file for the Bison utility is a "Bison grammar file".  The
general form of a Bison grammar file is as follows:

     %{
     C DECLARATIONS
     %}
     
     BISON DECLARATIONS
     
     %%
     GRAMMAR RULES
     %%
     ADDITIONAL C CODE

The `%%', `%{' and `%}' are punctuation that appears in every Bison
grammar file to separate the sections.

   The C declarations may define types and variables used in the
actions.  You can also use preprocessor commands to define macros used
there, and use `#include' to include header files that do any of these
things.

   The Bison declarations declare the names of the terminal and
nonterminal symbols, and may also describe operator precedence and the
data types of semantic values of various symbols.

   The grammar rules define how to construct each nonterminal symbol
from its parts.

   The additional C code can contain any C code you want to use.  Often
the definition of the lexical analyzer `yylex' goes here, plus
subroutines called by the actions in the grammar rules.  In a simple
program, all the rest of the program can go here.


automatically generated by info version 1.5

Dirfile and infopages generated Sat Dec 3 02:07:54 2005