A "symbol" groups together the symbol type (INT, PLUS, etc.), its
possible semantic value, and its optional location. The type is
needed to access the value, as it is stored as a variant/union.
There are two kinds of symbols. "symbol_type" are "external symbols":
they have type, value and location, and are returned by yylex.
"stack_symbol_type" are "internal symbols", they group state number,
value and location, and are stored in the parser stack. The type of
the symbol is computed from the state number.
The class template symbol_base_type<Exact> factors the code common to
stack_symbol_type and symbol_type. It uses the Curiously Recurring
Template pattern so that we can always (static_) downcast to the exact
type. symbol_base_type features value and location, and delegates the
handling of the type to its parameter.
When trying to generalize the support for variant, a significant issue
was revealed: because stack_symbol_type and symbol_type _derive_ from
symbol_base_type, the type/state member is defined _after_ the value
and location. In C++ the order of the definition of the members
defines the order in which they are initialized, things go backward:
the value is initialized _before_ the type. This is wrong, since the
type is needed to access the value.
Therefore, we need another means to factor the common code, one that
ensures the order of the members.
The idea is simple: define two (base) classes that code the symbol
type ("by_type" codes it by its type, and "by_state" by the state
number). Define basic_symbol<Base> as the class template that
provides value and location support. Make it _derive_ from its
parameter, by_type or by_state. Then define stack_symbol_type and
symbol_type as basic_symbol<by_state>, basic_symbol<by_type>. The
name basic_symbol was chosen by similarity with basic_string and
basic_ostream.
* data/c++.m4 (symbol_base_type<Exact>): Remove, replace by...
(basic_symbol<Base>): which derives from its parameter, one of...
(by_state, by_type): which provide means to retrieve the actual type of
symbol.
(symbol_type): Is now basic_symbol<by_type>.
(stack_symbol_type): Is now basic_symbol<by_state>.
* data/lalr1.cc: Many adjustments.