Node:Decl Summary, Previous:Pure Decl, Up:Declarations



Bison Declaration Summary

Here is a summary of the declarations used to define a grammar:

%union
Declare the collection of data types that semantic values may have (see The Collection of Value Types).
%token
Declare a terminal symbol (token type name) with no precedence or associativity specified (see Token Type Names).
%right
Declare a terminal symbol (token type name) that is right-associative (see Operator Precedence).
%left
Declare a terminal symbol (token type name) that is left-associative (see Operator Precedence).
%nonassoc
Declare a terminal symbol (token type name) that is nonassociative (using it in a way that would be associative is a syntax error) (see Operator Precedence).
%type
Declare the type of semantic values for a nonterminal symbol (see Nonterminal Symbols).
%start
Specify the grammar's start symbol (see The Start-Symbol).
%expect
Declare the expected number of shift-reduce conflicts (see Suppressing Conflict Warnings).

In order to change the behavior of bison, use the following directives:

%debug
In the parser file, define the macro YYDEBUG to 1 if it is not already defined, so that the debugging facilities are compiled. See Debugging Your Parser.
%defines
Write an extra output file containing macro definitions for the token type names defined in the grammar and the semantic value type 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"
Specify a prefix to use for all Bison output file names. The names are chosen as if the input file were named prefix.y.
%locations
Generate the code processing the locations (see Special Features for Use in Actions). This mode is enabled as soon as the grammar uses the special @n tokens, but if your grammar does not use it, using %locations allows for more accurate parse error messages.
%name-prefix="prefix"
Rename the external symbols used in the parser so that they start with prefix instead of 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
Do not include any C code in the parser file; generate tables only. The parser file contains just #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
Don't generate any #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"
Specify the filename for the parser file.
%pure-parser
Request a pure (reentrant) parser program (see A Pure (Reentrant) Parser).
%token_table
Generate an array of token names in the parser file. The name of the array is 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
The highest token number, plus one.
YYNNTS
The number of nonterminal symbols.
YYNRULES
The number of grammar rules,
YYNSTATES
The number of parser states (see Parser States).

%verbose
Write an extra output file containing verbose descriptions of the parser states and what is done for each type of look-ahead token in that state.

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
Pretend the option --yacc was given, i.e., imitate Yacc, including its naming conventions. See Bison Options, for more.