[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RFC: generate the default semantic action
From: |
Akim Demaille |
Subject: |
Re: RFC: generate the default semantic action |
Date: |
Sun, 14 Oct 2018 18:49:07 +0200 |
> Le 14 oct. 2018 à 18:13, Hans Åberg <address@hidden> a écrit :
>
> POSIX probably got it from there through copy-and-paste, then.
Right.
> So rules with empty RHS do not have any default value. What happen with
> Bison’s default value in such a case, that is, what does it get when there is
> no $1?
Garbage.
Except in C++ with variants, where $$ is only default constructed.
yacc.c:
> yyreduce:
> /* yyn is the number of a rule to reduce with. */
> yylen = yyr2[yyn];
>
> /* If YYLEN is nonzero, implement the default value of the action:
> '$$ = $1'.
>
> Otherwise, the following line sets YYVAL to garbage.
> This behavior is undocumented and Bison
> users should not rely upon it. Assigning to YYVAL
> unconditionally makes the parser a bit smaller, and it avoids a
> GCC warning that YYVAL may be used uninitialized. */
> yyval = yyvsp[1-yylen];
glr.c:
> /* Default (constant) value used for initialization for null
> right-hand sides. Unlike the standard yacc.c template, here we set
> the default value of $$ to a zeroed-out value. Since the default
> value is undefined, this behavior is technically correct. */
> static YYSTYPE yyval_default;
…
> if (yyrhslen == 0)
> *yyvalp = yyval_default;
> else
> *yyvalp = yyvsp[YYFILL
> (1-yyrhslen)].yystate.yysemantics.yysval;]b4_locations_if([[
lalr1.cc:
> yyreduce:
> yylen = yyr2_[yyn];
> {
> stack_symbol_type yylhs;
> yylhs.state = yy_lr_goto_state_ (yystack_[yylen].state,
> yyr1_[yyn]);]b4_variant_if([
> /* Variants are always initialized to an empty instance of the
> correct type. The default '$$ = $1' action is NOT applied
> when using variants. */
> b4_symbol_variant(address@hidden@}]], [yylhs.value], [build])], [
> /* If YYLEN is nonzero, implement the default value of the
> action: '$$ = $1'. Otherwise, use the top of the stack.
>
> Otherwise, the following line sets YYLHS.VALUE to garbage.
> This behavior is undocumented and Bison users should not rely
> upon it. */
> if (yylen)
> yylhs.value = address@hidden - address@hidden;
> else
> yylhs.value = address@hidden@}.value;])[
lalr1.java:
> /* If YYLEN is nonzero, implement the default value of the action:
> '$$ = $1'. Otherwise, use the top of the stack.
>
> Otherwise, the following line sets YYVAL to garbage.
> This behavior is undocumented and Bison
> users should not rely upon it. */
> if (yylen > 0)
> yyval = yystack.valueAt (yylen - 1);
> else
> yyval = yystack.valueAt (0);
Re: RFC: generate the default semantic action, Paul Eggert, 2018/10/14