Manual
Manual
Manual
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
56 Bison 2.3<br />
the types for a terminal or nonterminal symbol (see Section 3.7.5 [Nonterminal Symbols],<br />
page 56).<br />
As an extension to POSIX, a tag is allowed after the union. For example:<br />
%union value {<br />
double val;<br />
symrec *tptr;<br />
}<br />
specifies the union tag value, so the corresponding C type is union value. If you do not<br />
specify a tag, it defaults to YYSTYPE.<br />
As another extension to POSIX, you may specify multiple %union declarations; their<br />
contents are concatenated. However, only the first %union declaration can specify a tag.<br />
Note that, unlike making a union declaration in C, you need not write a semicolon after<br />
the closing brace.<br />
3.7.5 Nonterminal Symbols<br />
When you use %union to specify multiple value types, you must declare the value type of<br />
each nonterminal symbol for which values are used. This is done with a %type declaration,<br />
like this:<br />
%type nonterminal...<br />
Here nonterminal is the name of a nonterminal symbol, and type is the name given in the<br />
%union to the alternative that you want (see Section 3.7.4 [The Collection of Value Types],<br />
page 55). You can give any number of nonterminal symbols in the same %type declaration,<br />
if they have the same value type. Use spaces to separate the symbol names.<br />
You can also declare the value type of a terminal symbol. To do this, use the same <br />
construction in a declaration for the terminal symbol. All kinds of token declarations allow<br />
.<br />
3.7.6 Performing Actions before Parsing<br />
Sometimes your parser needs to perform some initializations before parsing. The %initialaction<br />
directive allows for such arbitrary code.<br />
%initial-action { code }<br />
[Directive]<br />
Declare that the braced code must be invoked before parsing each time yyparse is<br />
called. The code may use $$ and @$ — initial value and location of the look-ahead<br />
— and the %parse-param.<br />
For instance, if your locations use a file name, you may use<br />
%parse-param { char const *file_name };<br />
%initial-action<br />
{<br />
@$.initialize (file_name);<br />
};