In the bison manual in section 2.1.2 Grammar Rules for rpcalc, it is written that:
In each action, the pseudo-variable $$ stands for the semantic value
for the grouping that the rule is going to construct. Assigning a
value to $$ is the main job of most actions
Does that mean $$ is used for holding the result from a rule? like:
exp exp '+' { $$ = $1 + $2; }
And what’s the typical usage of $$ after begin assigned to?
Yes,
$$is used to hold the result of the rule. After being assigned to, it typically becomes a$xin some higher-level (or lower precedence) rule.Consider (for example) input like
2 * 3 + 4. Assuming you follow the normal precedence rules, you’d have an action something like:{ $$ = $1 * $3; }. In this case, that would be used for the2 * 3part and, obviously enough, assign6to$$. Then you’d have your{ $$ = $1 + $3; }to handle the addition. For this action,$1would be given the value6that you assigned to$$in the multiplication rule.