What is $$ in bison?

The bison manual in section 2.1.2 Grammar rules for rpcalc states that:

In each action, the pseudo-variable $$ denotes the semantic value for the grouping that the rule is going to build. Assigning the value of $$ is the main task of most actions

Does this mean that it is $$used to store the result from the rule? as:

exp exp '+'   { $$ = $1 + $2;      }

And what is the typical use $$after the start is assigned?

+3
source share
4 answers

Yes, it is $$used to store the result of the rule. After assignment, it usually becomes $xin some rule a higher level (or lower priority).

() 2 * 3 + 4. , , - : { $$ = $1 * $3; }. 2 * 3 , , 6 $$. { $$ = $1 + $3; } . $1 6, $$ .

+5

, $$ ? :

.

$$ ?

. Bison . $1 $2 exp, - exp, $$.

+4

$$ . , . .

!

+1

. YACC :

%token NUMBER
%%
exp:    exp '+' NUMBER  { $$ = $1 + $3; }
    |   exp '-' NUMBER  { $$ = $1 - $3; }
    |   NUMBER          { $$ = $1; }
    ;

Bison YACC. Bison, , YACC - . "#line". "# 3"; :

#line 3 "DollarDollar.y"
    { (yyval) = (yyvsp[(1) - (3)]) + (yyvsp[(3) - (3)]); }
    break;

, "$$" "yyval". , "yyvsp", , , , "yyval".

+1

All Articles