help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set_goto_map() has unintentional ++ operator


From: Akim Demaille
Subject: Re: set_goto_map() has unintentional ++ operator
Date: Mon, 29 Dec 2014 16:29:13 +0100

> Le 21 déc. 2014 à 21:51, Sean Nakasone <address@hidden> a écrit :
> 
> in lalr.c
> 
> the ++ at the end of the following line doesn't have a purpose
> 
> goto_number k = temp_map[TRANSITION_SYMBOL(sp, i) - ntokens]++;
> 
> it can be misleading. 

hi Sean,

Well, this piece of code is old, and it does not seem immediate
(to me) that the ++ is useless :)

  from_state = xcalloc (ngotos, sizeof *from_state);
  to_state = xcalloc (ngotos, sizeof *to_state);

  for (s = 0; s < nstates; ++s)
    {
      transitions *sp = states[s]->transitions;
      int i;
      for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)
        {
          goto_number k = temp_map[TRANSITION_SYMBOL (sp, i) - ntokens]++;
          from_state[k] = s;
          to_state[k] = sp->states[i]->number;
        }
    }

  free (temp_map);

FTR, byacc (beach and bison are forks of a common ancestor) reads:

    from_state = NEW2(ngotos, Value_t);
    to_state = NEW2(ngotos, Value_t);

    for (sp = first_shift; sp; sp = sp->next)
    {
        state1 = sp->number;
        for (i = sp->nshifts - 1; i >= 0; i--)
        {
            state2 = sp->shift[i];
            symbol = accessing_symbol[state2];

            if (ISTOKEN(symbol))
                break;

            k = temp_map[symbol]++;
            from_state[k] = state1;
            to_state[k] = state2;
        }
    }

    FREE(temp_map + ntokens);

it has the same ++.


What makes you think it is useless?  If I remove it, some tests fail
(they hang), or I can even get a SEGV.

$ cat input.y
%%
start: end end {} ;
end: { }  ;
$ ./_build/35s/tests/bison input.y
./_build/35s/tests/bison: line 28: 87593 Segmentation fault: 11  $PREBISON 
"$abs_top_builddir/src/bison" ${1+"$@"}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]