www.delorie.com/gnu/docs/bison/bison_67.html   search  
 
Buy the book!


Bison 1.875

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.7.9 Bison Declaration Summary

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

Directive: %union
Declare the collection of data types that semantic values may have (see section The Collection of Value Types).

Directive: %token
Declare a terminal symbol (token type name) with no precedence or associativity specified (see section Token Type Names).

Directive: %right
Declare a terminal symbol (token type name) that is right-associative (see section Operator Precedence).

Directive: %left
Declare a terminal symbol (token type name) that is left-associative (see section Operator Precedence).

Directive: %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 section Operator Precedence).

Directive: %type
Declare the type of semantic values for a nonterminal symbol (see section Nonterminal Symbols).

Directive: %start
Specify the grammar's start symbol (see section The Start-Symbol).

Directive: %expect
Declare the expected number of shift-reduce conflicts (see section Suppressing Conflict Warnings).

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

Directive: %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 section Tracing Your Parser.

Directive: %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 section Semantic Values of Tokens.

Directive: %destructor
Specifying how the parser should reclaim the memory associated to discarded symbols. See section Freeing Discarded Symbols.

Directive: %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'.

Directive: %locations
Generate the code processing the locations (see section 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 syntax error messages.

Directive: %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, yylloc, yychar, yydebug, and possible yylloc. For example, if you use `%name-prefix="c_"', the names become c_parse, c_lex, and so on. See section Multiple Parsers in the Same Program.

Directive: %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.

Directive: %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.

Directive: %output="filename"
Specify the filename for the parser file.

Directive: %pure-parser
Request a pure (reentrant) parser program (see section A Pure (Reentrant) Parser).

Directive: %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 correspond to the predefined tokens "$end", "error", and "$undefined"; 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 section 5.5 Parser States).

Directive: %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. See section Understanding Your Parser, for more information.

Directive: %yacc
Pretend the option `--yacc' was given, i.e., imitate Yacc, including its naming conventions. See section 9.1 Bison Options, for more.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003