/[bison]/bison/src/state.c
ViewVC logotype

Diff of /bison/src/state.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by akim, Sun Jun 30 17:32:17 2002 UTC revision 1.14 by akim, Sun Jun 30 17:33:37 2002 UTC
# Line 35  Line 35 
35  | Create a new array of N shifts/gotos.  |  | Create a new array of N shifts/gotos.  |
36  `---------------------------------------*/  `---------------------------------------*/
37    
38  #define SHIFTS_ALLOC(Nshifts)                                           \  #define TRANSITIONS_ALLOC(Nshifts)                                              \
39    (shifts_t *) xcalloc ((unsigned) (sizeof (shifts_t)                   \    (transitions_t *) xcalloc ((unsigned) (sizeof (transitions_t)                         \
40                                    + (Nshifts - 1) * sizeof (state_number_t)), 1)                                    + (Nshifts - 1) * sizeof (state_number_t)), 1)
41    
42  static shifts_t *  static transitions_t *
43  shifts_new (int nshifts, state_number_t *shifts)  transitions_new (int num, state_number_t *the_states)
44  {  {
45    shifts_t *res = SHIFTS_ALLOC (nshifts);    transitions_t *res = TRANSITIONS_ALLOC (num);
46    res->nshifts = nshifts;    res->num = num;
47    memcpy (res->shifts, shifts, nshifts * sizeof (shifts[0]));    memcpy (res->states, the_states, num * sizeof (the_states[0]));
48    return res;    return res;
49  }  }
50    
51    
52  /*-----------------------------------------------------------------.  /*-------------------------------------------------------------------.
53  | Return the state such these SHIFTS contain a shift/goto to it on |  | Return the state such these TRANSITIONS contain a shift/goto to it |
54  | SYMBOL.  Aborts if none found.                                   |  | on SYMBOL.  Aborts if none found.                                  |
55  `-----------------------------------------------------------------*/  `-------------------------------------------------------------------*/
56    
57  state_t *  state_t *
58  shifts_to (shifts_t *shifts, symbol_number_t s)  transitions_to (transitions_t *shifts, symbol_number_t s)
59  {  {
60    int j;    int j;
61    for (j = 0; j < shifts->nshifts; j++)    for (j = 0; j < shifts->num; j++)
62      if (SHIFT_SYMBOL (shifts, j) == s)      if (TRANSITION_SYMBOL (shifts, j) == s)
63        return states[shifts->shifts[j]];        return states[shifts->states[j]];
64    abort ();    abort ();
65  }  }
66    
# Line 168  state_new (symbol_number_t accessing_sym Line 168  state_new (symbol_number_t accessing_sym
168  `--------------------------*/  `--------------------------*/
169    
170  void  void
171  state_shifts_set (state_t *state, int nshifts, state_number_t *shifts)  state_transitions_set (state_t *state, int nshifts, state_number_t *shifts)
172  {  {
173    state->shifts = shifts_new (nshifts, shifts);    state->shifts = transitions_new (nshifts, shifts);
174  }  }
175    
176    

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26