Bison Parser
Previous: <Semantic Actions=>SemanticAc> * Next: <Stages=>Stages> * Up: <Concepts=>Concepts>

#Wrap on
{fH3}Bison Output: the Parser File{f}

When you run Bison, you give it a Bison grammar file as input.  The output
is a C source file that parses the language described by the grammar.
This file is called a {fUnderline}Bison parser{f}.  Keep in mind that the Bison
utility and the Bison parser are two distinct programs: the Bison utility
is a program whose output is the Bison parser that becomes part of your
program.

The job of the Bison parser is to group tokens into groupings according to
the grammar rules---for example, to build identifiers and operators into
expressions.  As it does this, it runs the actions for the grammar rules it
uses.

The tokens come from a function called the {fUnderline}lexical analyzer{f} that you
must supply in some fashion (such as by writing it in C).  The Bison parser
calls the lexical analyzer each time it wants a new token.  It doesn't know
what is ``inside'' the tokens (though their semantic values may reflect
this).  Typically the lexical analyzer makes the tokens by parsing
characters of text, but Bison does not depend on this.  \*Note <Lexical=>Lexical>: The Lexical Analyzer Function {fCode}yylex{f}.

The Bison parser file is C code which defines a function named
{fCode}yyparse{f} which implements that grammar.  This function does not make
a complete C program: you must supply some additional functions.  One is
the lexical analyzer.  Another is an error-reporting function which the
parser calls to report an error.  In addition, a complete C program must
start with a function called {fCode}main{f}; you have to provide this, and
arrange for it to call {fCode}yyparse{f} or the parser will never run.
\*Note <Interface=>Interface>: Parser C-Language Interface.

Aside from the token type names and the symbols in the actions you
write, all variable and function names used in the Bison parser file
begin with {fEmphasis}yy{f} or {fEmphasis}YY{f}.  This includes interface functions
such as the lexical analyzer function {fCode}yylex{f}, the error reporting
function {fCode}yyerror{f} and the parser function {fCode}yyparse{f} itself.
This also includes numerous identifiers used for internal purposes.
Therefore, you should avoid using C identifiers starting with {fEmphasis}yy{f}
or {fEmphasis}YY{f} in the Bison grammar file except for the ones defined in
this manual.

