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

Diff of /bison/src/LR0.c

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

revision 1.76 by akim, Sun Jun 30 17:34:52 2002 UTC revision 1.77 by akim, Wed Jul 3 06:51:43 2002 UTC
# Line 46  typedef struct state_list_s Line 46  typedef struct state_list_s
46  static state_list_t *first_state = NULL;  static state_list_t *first_state = NULL;
47  static state_list_t *last_state = NULL;  static state_list_t *last_state = NULL;
48    
49  static void  
50  state_list_append (state_t *state)  /*------------------------------------------------------------------.
51    | A state was just discovered from another state.  Queue it for     |
52    | later examination, in order to find its transitions.  Return it.  |
53    `------------------------------------------------------------------*/
54    
55    static state_t *
56    state_list_append (symbol_number_t symbol,
57                       size_t core_size, item_number_t *core)
58  {  {
59    state_list_t *node = XMALLOC (state_list_t, 1);    state_list_t *node = XMALLOC (state_list_t, 1);
60      state_t *state = state_new (symbol, core_size, core);
61    
62      if (trace_flag)
63        fprintf (stderr, "state_list_append (state = %d, symbol = %d (%s))\n",
64                 nstates, symbol, symbols[symbol]->tag);
65    
66      /* If this is the eoftoken, and this is not the initial state, then
67         this is the final state.  */
68      if (symbol == 0 && first_state)
69        final_state = state;
70    
71    node->next = NULL;    node->next = NULL;
72    node->state = state;    node->state = state;
73    
# Line 58  state_list_append (state_t *state) Line 76  state_list_append (state_t *state)
76    if (last_state)    if (last_state)
77      last_state->next = node;      last_state->next = node;
78    last_state = node;    last_state = node;
79    
80      return state;
81  }  }
82    
83  static int nshifts;  static int nshifts;
# Line 184  new_itemsets (state_t *state) Line 204  new_itemsets (state_t *state)
204    
205    
206    
 /*-----------------------------------------------------------------.  
 | Subroutine of get_state.  Create a new state for those items, if |  
 | necessary.                                                       |  
 `-----------------------------------------------------------------*/  
   
 static state_t *  
 new_state (symbol_number_t symbol, size_t core_size, item_number_t *core)  
 {  
   state_t *res;  
   
   if (trace_flag)  
     fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n",  
              nstates, symbol, symbols[symbol]->tag);  
   
   res = state_new (symbol, core_size, core);  
   state_hash_insert (res);  
   
   /* If this is the eoftoken, and this is not the initial state, then  
      this is the final state.  */  
   if (symbol == 0 && first_state)  
     final_state = res;  
   
   state_list_append (res);  
   return res;  
 }  
   
   
207  /*--------------------------------------------------------------.  /*--------------------------------------------------------------.
208  | Find the state number for the state we would get to (from the |  | Find the state number for the state we would get to (from the |
209  | current state) by shifting symbol.  Create a new state if no  |  | current state) by shifting symbol.  Create a new state if no  |
# Line 228  get_state (symbol_number_t symbol, size_ Line 221  get_state (symbol_number_t symbol, size_
221    
222    sp = state_hash_lookup (core_size, core);    sp = state_hash_lookup (core_size, core);
223    if (!sp)    if (!sp)
224      sp = new_state (symbol, core_size, core);      sp = state_list_append (symbol, core_size, core);
225    
226    if (trace_flag)    if (trace_flag)
227      fprintf (stderr, "Exiting get_state => %d\n", sp->number);      fprintf (stderr, "Exiting get_state => %d\n", sp->number);
# Line 277  append_states (state_t *state) Line 270  append_states (state_t *state)
270  }  }
271    
272    
 static void  
 new_states (void)  
 {  
   /* The 0 at the lhs is the index of the item of this initial rule.  */  
   kernel_base[0][0] = 0;  
   kernel_size[0] = 1;  
   state_list_append (new_state (0, kernel_size[0], kernel_base[0]));  
 }  
   
   
   
273  /*----------------------------------------------------------------.  /*----------------------------------------------------------------.
274  | Find which rules can be used for reduction transitions from the |  | Find which rules can be used for reduction transitions from the |
275  | current state and make a reductions structure for the state to  |  | current state and make a reductions structure for the state to  |
# Line 332  set_states (void) Line 314  set_states (void)
314        state_list_t *this = first_state;        state_list_t *this = first_state;
315    
316        /* Pessimization, but simplification of the code: make sure all        /* Pessimization, but simplification of the code: make sure all
317           the states have a shifts, errs, and reductions, even if           the states have valid transitions and reductions members,
318           reduced to 0.  */           even if reduced to 0.  It is too soon for errs, which are
319             computed later, but set_conflicts.  */
320        state_t *state = this->state;        state_t *state = this->state;
321        if (!state->shifts)        if (!state->transitions)
322          state_transitions_set (state, 0, 0);          state_transitions_set (state, 0, 0);
       if (!state->errs)  
         state->errs = errs_new (0);  
323        if (!state->reductions)        if (!state->reductions)
324          state_reductions_set (state, 0, 0);          state_reductions_set (state, 0, 0);
325    
# Line 363  generate_states (void) Line 344  generate_states (void)
344    state_list_t *list = NULL;    state_list_t *list = NULL;
345    allocate_storage ();    allocate_storage ();
346    new_closure (nritems);    new_closure (nritems);
347    new_states ();  
348      /* Create the initial state.  The 0 at the lhs is the index of the
349         item of this initial rule.  */
350      kernel_base[0][0] = 0;
351      kernel_size[0] = 1;
352      state_list_append (0, kernel_size[0], kernel_base[0]);
353    
354    list = first_state;    list = first_state;
355    
356    while (list)    while (list)

Legend:
Removed from v.1.76  
changed lines
  Added in v.1.77

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