Node:Decl Summary, Previous:Pure Decl, Up:Declarations
Here is a summary of the declarations used to define a grammar:
%union
%token
%right
%left
%nonassoc
%type
%start
%expect
In order to change the behavior of bison
, use the following
directives:
%debug
YYDEBUG
to 1 if it is not
already defined, so that the debugging facilities are compiled.
See Debugging Your Parser.
%defines
YYSTYPE
, as well as a few extern
variable declarations.
If the parser output file is named name.c
then this file
is named name.h
.
This output file is essential if you wish to put the definition of
yylex
in a separate source file, because yylex
needs to
be able to refer to token type codes and the variable
yylval
. See Semantic Values of Tokens.
%file-prefix="prefix"
prefix.y
.
%locations
@n
tokens, but if your
grammar does not use it, using %locations
allows for more
accurate parse error messages.
%name-prefix="prefix"
yy
. The precise list of symbols renamed
is yyparse
, yylex
, yyerror
, yynerrs
,
yylval
, yychar
and yydebug
. For example, if you
use %name-prefix="c_"
, the names become c_parse
,
c_lex
, and so on. See Multiple Parsers in the Same Program.
%no-parser
#define
directives and static variable
declarations.
This option also tells Bison to write the C code for the grammar actions
into a file named filename.act
, in the form of a
brace-surrounded body fit for a switch
statement.
%no-lines
#line
preprocessor commands in the parser
file. Ordinarily Bison writes these commands in the parser file so that
the C compiler and debuggers will associate errors and object code with
your source file (the grammar file). This directive causes them to
associate errors with the parser file, treating it an independent source
file in its own right.
%output="filename"
%pure-parser
%token_table
yytname
; yytname[i]
is the name of the
token whose internal Bison token code number is i. The first three
elements of yytname
are always "$"
, "error"
, and
"$illegal"
; after these come the symbols defined in the grammar
file.
For single-character literal tokens and literal string tokens, the name
in the table includes the single-quote or double-quote characters: for
example, "'+'"
is a single-character literal and "\"<=\""
is a literal string token. All the characters of the literal string
token appear verbatim in the string found in the table; even
double-quote characters are not escaped. For example, if the token
consists of three characters *"*
, its string in yytname
contains "*"*"
. (In C, that would be written as
"\"*\"*\""
).
When you specify %token_table
, Bison also generates macro
definitions for macros YYNTOKENS
, YYNNTS
, and
YYNRULES
, and YYNSTATES
:
YYNTOKENS
YYNNTS
YYNRULES
YYNSTATES
%verbose
This file also describes all the conflicts, both those resolved by operator precedence and the unresolved ones.
The file's name is made by removing .tab.c
or .c
from
the parser output file name, and adding .output
instead.
Therefore, if the input file is foo.y
, then the parser file is
called foo.tab.c
by default. As a consequence, the verbose
output file is called foo.output
.
%yacc
%fixed-output-files
--yacc
was given, i.e., imitate Yacc,
including its naming conventions. See Bison Options, for more.