06.01.2015 Views

Manual

Manual

Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3: Bison Grammar Files 61<br />

This option also tells Bison to write the C code for the grammar actions into a file<br />

named ‘file.act’, in the form of a brace-surrounded body fit for a switch statement.<br />

%no-lines<br />

[Directive]<br />

Don’t generate any #line preprocessor commands in the parser file. Ordinarily Bison<br />

writes these commands in the parser file so that the C compiler and debuggers will<br />

associate errors and object code with your source file (the grammar file). This directive<br />

causes them to associate errors with the parser file, treating it an independent<br />

source file in its own right.<br />

%output="file"<br />

Specify file for the parser file.<br />

[Directive]<br />

%pure-parser<br />

[Directive]<br />

Request a pure (reentrant) parser program (see Section 3.7.10 [A Pure (Reentrant)<br />

Parser], page 58).<br />

%require "version"<br />

[Directive]<br />

Require version version or higher of Bison. See Section 3.7.1 [Require a Version of<br />

Bison], page 54.<br />

%token-table<br />

[Directive]<br />

Generate an array of token names in the parser file. The name of the array is yytname;<br />

yytname[i] is the name of the token whose internal Bison token code number is i.<br />

The first three elements of yytname correspond to the predefined tokens "$end",<br />

"error", and "$undefined"; after these come the symbols defined in the grammar<br />

file.<br />

The name in the table includes all the characters needed to represent the token in<br />

Bison. For single-character literals and literal strings, this includes the surrounding<br />

quoting characters and any escape sequences. For example, the Bison single-character<br />

literal ’+’ corresponds to a three-character name, represented in C as "’+’"; and<br />

the Bison two-character literal string "\\/" corresponds to a five-character name,<br />

represented in C as "\"\\\\/\"".<br />

When you specify %token-table, Bison also generates macro definitions for macros<br />

YYNTOKENS, YYNNTS, and YYNRULES, and YYNSTATES:<br />

YYNTOKENS<br />

YYNNTS<br />

YYNRULES<br />

YYNSTATES<br />

The highest token number, plus one.<br />

The number of nonterminal symbols.<br />

The number of grammar rules,<br />

The number of parser states (see Section 5.5 [Parser States], page 75).<br />

%verbose<br />

[Directive]<br />

Write an extra output file containing verbose descriptions of the parser states and<br />

what is done for each type of look-ahead token in that state. See Section 8.1 [Understanding<br />

Your Parser], page 89, for more information.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!