The
default action associated with any rule can be written as:
$$ = $1
which
means that the value of associated with
$1 on the value stack
is assigned
$$ on the value stack when the rule is reduced.
If, for example,
$1 is an integer, then
$$ is the
same integer after the reduction occurs.
On the other hand, suppose that the recognition action associated
with a rule explicitly states:
$$ = $1
This explicit assignment
may not have the same effect as the implicit assignment. For example,
suppose that you define:
%union {
float floatval;
int intval;
}
Also suppose that the type associated with
$$ is
floatval and
the type associated with
$1 is
intval. Then the
explicit statement:
$$ = $1
performs an integer to floating-point
conversion when the value of
$1 is assigned to
$$,
whereas the implicit statement did an integer to integer assignment
and did
not perform this conversion. You must
therefore be careful and think about the effects of implicit versus
explicit assignments.