+** Variable api.value.type
+
+ This new %define variable supersedes the #define macro YYSTYPE. The use
+ of YYSTYPE is discouraged. In particular, #defining YYSTYPE *and* either
+ using %union or %defining api.value.type results in undefined behavior.
+
+ Either define api.value.type, or use "%union":
+
+ %union
+ {
+ int ival;
+ char *sval;
+ }
+ %token <ival> INT "integer"
+ %token <sval> STRING "string"
+ %printer { fprintf (yyo, "%d", $$); } <ival>
+ %destructor { free ($$); } <sval>
+
+ /* In yylex(). */
+ yylval.ival = 42; return INT;
+ yylval.sval = "42"; return STRING;
+
+ The %define variable api.value.type supports both keyword and code values.
+
+ The keyword value 'union' means that the user provides genuine types, not
+ union member names such as "ival" and "sval" above (WARNING: will fail if
+ -y/--yacc/%yacc is enabled).
+
+ %define api.value.type union
+ %token <int> INT "integer"
+ %token <char *> STRING "string"
+ %printer { fprintf (yyo, "%d", $$); } <int>
+ %destructor { free ($$); } <char *>
+
+ /* In yylex(). */
+ yylval.INT = 42; return INT;
+ yylval.STRING = "42"; return STRING;
+
+ The keyword value variant is somewhat equivalent, but for C++ special
+ provision is made to allow classes to be used (more about this below).
+
+ %define api.value.type variant
+ %token <int> INT "integer"
+ %token <std::string> STRING "string"
+
+ Code values (in braces) denote user defined types. This is where YYSTYPE
+ used to be used.
+
+ %code requires
+ {
+ struct my_value
+ {
+ enum
+ {
+ is_int, is_string
+ } kind;
+ union
+ {
+ int ival;
+ char *sval;
+ } u;
+ };
+ }
+ %define api.value.type {struct my_value}
+ %token <u.ival> INT "integer"
+ %token <u.sval> STRING "string"
+ %printer { fprintf (yyo, "%d", $$); } <u.ival>
+ %destructor { free ($$); } <u.sval>
+
+ /* In yylex(). */
+ yylval.u.ival = 42; return INT;
+ yylval.u.sval = "42"; return STRING;
+