Next: Generating the Semantic Value Type, Previous: Data Types of Semantic Values, Up: Defining Language Semantics [Contents][Index]
In most programs, you will need different data types for different kinds
of tokens and groupings. For example, a numeric constant may need type
int
or long
, while a string constant needs type
char *
, and an identifier might need a pointer to an entry in the
symbol table.
To use more than one data type for semantic values in one parser, Bison requires you to do two things:
%union
Bison declaration (see The Union Declaration);
%define
variable api.value.type
to be a union type
whose members are the type tags (see Providing a Structured Semantic Value Type);
typedef
or a #define
to define YYSTYPE
to be a
union type whose member names are the type tags.
%token
Bison declaration (see Token Kind Names) and
for groupings with the %nterm
/%type
Bison declarations
(see Nonterminal Symbols).