Union Decl
Previous: <Precedence Decl=>Precedence> * Next: <Type Decl=>TypeDecl> * Up: <Declarations=>Declaratio>

#Wrap on
{fH4}The Collection of Value Types{f}

The {fCode}%union{f} declaration specifies the entire collection of possible
data types for semantic values.  The keyword {fCode}%union{f} is followed by a
pair of braces containing the same thing that goes inside a {fCode}union{f} in
C.  

For example:

#Wrap off
#fCode
%union \{
  double val;
  symrec \*tptr;
\}
#f
#Wrap on

This says that the two alternative types are {fCode}double{f} and {fCode}symrec
\*{f}.  They are given names {fCode}val{f} and {fCode}tptr{f}; these names are used
in the {fCode}%token{f} and {fCode}%type{f} declarations to pick one of the types
for a terminal or nonterminal symbol (\*Note <Type Decl=>TypeDecl>: Nonterminal Symbols).

Note that, unlike making a {fCode}union{f} declaration in C, you do not write
a semicolon after the closing brace.

