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

Diff of /bison/src/lalr.c

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

revision 1.83 by akim, Wed Jul 3 06:51:43 2002 UTC revision 1.84 by akim, Wed Jul 3 10:54:33 2002 UTC
# Line 32  Line 32 
32  #include "symtab.h"  #include "symtab.h"
33  #include "gram.h"  #include "gram.h"
34  #include "reader.h"  #include "reader.h"
 #include "types.h"  
35  #include "LR0.h"  #include "LR0.h"
36  #include "complain.h"  #include "complain.h"
37  #include "lalr.h"  #include "lalr.h"
# Line 40  Line 39 
39  #include "derives.h"  #include "derives.h"
40  #include "getargs.h"  #include "getargs.h"
41    
42    goto_number_t *goto_map = NULL;
43    static goto_number_t ngotos = 0;
44    state_number_t *from_state = NULL;
45    state_number_t *to_state = NULL;
46    
47    /* Linked list of goto numbers.  */
48    typedef struct goto_list_s
49    {
50      struct goto_list_s *next;
51      goto_number_t value;
52    } goto_list_t;
53    
54    
55  rule_t **LArule = NULL;  rule_t **LArule = NULL;
56  bitsetv LA = NULL;  bitsetv LA = NULL;
57  size_t nLA;  size_t nLA;
58    
 static int ngotos;  
 short *goto_map = NULL;  
 state_number_t *from_state = NULL;  
 state_number_t *to_state = NULL;  
59    
60  /* And for the famous F variable, which name is so descriptive that a  /* And for the famous F variable, which name is so descriptive that a
61     comment is hardly needed.  <grin>.  */     comment is hardly needed.  <grin>.  */
62  static bitsetv F = NULL;  static bitsetv F = NULL;
63    
64  static short **includes;  static goto_number_t **includes;
65  static shorts **lookback;  static goto_list_t **lookback;
66    
67    
68    
# Line 72  initialize_LA (void) Line 80  initialize_LA (void)
80    
81    LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);    LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
82    LArule = XCALLOC (rule_t *, nLA);    LArule = XCALLOC (rule_t *, nLA);
83    lookback = XCALLOC (shorts *, nLA);    lookback = XCALLOC (goto_list_t *, nLA);
84    
85    np = LArule;    np = LArule;
86    for (i = 0; i < nstates; i++)    for (i = 0; i < nstates; i++)
# Line 86  static void Line 94  static void
94  set_goto_map (void)  set_goto_map (void)
95  {  {
96    state_number_t state;    state_number_t state;
97    short *temp_map;    goto_number_t *temp_map;
98    
99    goto_map = XCALLOC (short, nvars + 1) - ntokens;    goto_map = XCALLOC (goto_number_t, nvars + 1) - ntokens;
100    temp_map = XCALLOC (short, nvars + 1) - ntokens;    temp_map = XCALLOC (goto_number_t, nvars + 1) - ntokens;
101    
102    ngotos = 0;    ngotos = 0;
103    for (state = 0; state < nstates; ++state)    for (state = 0; state < nstates; ++state)
# Line 98  set_goto_map (void) Line 106  set_goto_map (void)
106        int i;        int i;
107        for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)        for (i = sp->num - 1; i >= 0 && TRANSITION_IS_GOTO (sp, i); --i)
108          {          {
109            if (ngotos == SHRT_MAX)            if (ngotos == GOTO_NUMBER_MAX)
110              fatal (_("too many gotos (max %d)"), SHRT_MAX);              fatal (_("too many gotos (max %d)"), GOTO_NUMBER_MAX);
111    
112            ngotos++;            ngotos++;
113            goto_map[TRANSITION_SYMBOL (sp, i)]++;            goto_map[TRANSITION_SYMBOL (sp, i)]++;
# Line 178  map_goto (state_number_t state, symbol_n Line 186  map_goto (state_number_t state, symbol_n
186  static void  static void
187  initialize_F (void)  initialize_F (void)
188  {  {
189    short **reads = XCALLOC (short *, ngotos);    goto_number_t **reads = XCALLOC (goto_number_t *, ngotos);
190    short *edge = XCALLOC (short, ngotos + 1);    goto_number_t *edge = XCALLOC (goto_number_t, ngotos + 1);
191    int nedges = 0;    int nedges = 0;
192    
193    int i;    int i;
# Line 204  initialize_F (void) Line 212  initialize_F (void)
212    
213        if (nedges)        if (nedges)
214          {          {
215            reads[i] = XCALLOC (short, nedges + 1);            reads[i] = XCALLOC (goto_number_t, nedges + 1);
216            memcpy (reads[i], edge, nedges * sizeof (edge[0]));            memcpy (reads[i], edge, nedges * sizeof (edge[0]));
217            reads[i][nedges] = -1;            reads[i][nedges] = -1;
218            nedges = 0;            nedges = 0;
# Line 225  static void Line 233  static void
233  add_lookback_edge (state_t *state, rule_number_t ruleno, int gotono)  add_lookback_edge (state_t *state, rule_number_t ruleno, int gotono)
234  {  {
235    int i;    int i;
236    shorts *sp;    goto_list_t *sp;
237    
238    for (i = 0; i < state->nlookaheads; ++i)    for (i = 0; i < state->nlookaheads; ++i)
239      if (state->lookaheads_rule[i]->number == ruleno)      if (state->lookaheads_rule[i]->number == ruleno)
# Line 233  add_lookback_edge (state_t *state, rule_ Line 241  add_lookback_edge (state_t *state, rule_
241    
242    assert (state->lookaheads_rule[i]->number == ruleno);    assert (state->lookaheads_rule[i]->number == ruleno);
243    
244    sp = XCALLOC (shorts, 1);    sp = XCALLOC (goto_list_t, 1);
245    sp->next = lookback[(state->lookaheads - LA) + i];    sp->next = lookback[(state->lookaheads - LA) + i];
246    sp->value = gotono;    sp->value = gotono;
247    lookback[(state->lookaheads - LA) + i] = sp;    lookback[(state->lookaheads - LA) + i] = sp;
# Line 244  add_lookback_edge (state_t *state, rule_ Line 252  add_lookback_edge (state_t *state, rule_
252  static void  static void
253  build_relations (void)  build_relations (void)
254  {  {
255    short *edge = XCALLOC (short, ngotos + 1);    goto_number_t *edge = XCALLOC (goto_number_t, ngotos + 1);
256    state_number_t *states1 = XCALLOC (state_number_t, ritem_longest_rhs () + 1);    state_number_t *states1 = XCALLOC (state_number_t, ritem_longest_rhs () + 1);
257    int i;    int i;
258    
259    includes = XCALLOC (short *, ngotos);    includes = XCALLOC (goto_number_t *, ngotos);
260    
261    for (i = 0; i < ngotos; i++)    for (i = 0; i < ngotos; i++)
262      {      {
# Line 295  build_relations (void) Line 303  build_relations (void)
303        if (nedges)        if (nedges)
304          {          {
305            int j;            int j;
306            includes[i] = XCALLOC (short, nedges + 1);            includes[i] = XCALLOC (goto_number_t, nedges + 1);
307            for (j = 0; j < nedges; j++)            for (j = 0; j < nedges; j++)
308              includes[i][j] = edge[j];              includes[i][j] = edge[j];
309            includes[i][nedges] = -1;            includes[i][nedges] = -1;
# Line 328  static void Line 336  static void
336  compute_lookaheads (void)  compute_lookaheads (void)
337  {  {
338    size_t i;    size_t i;
339    shorts *sp;    goto_list_t *sp;
340    
341    for (i = 0; i < nLA; i++)    for (i = 0; i < nLA; i++)
342      for (sp = lookback[i]; sp; sp = sp->next)      for (sp = lookback[i]; sp; sp = sp->next)
# Line 336  compute_lookaheads (void) Line 344  compute_lookaheads (void)
344    
345    /* Free LOOKBACK. */    /* Free LOOKBACK. */
346    for (i = 0; i < nLA; i++)    for (i = 0; i < nLA; i++)
347      LIST_FREE (shorts, lookback[i]);      LIST_FREE (goto_list_t, lookback[i]);
348    
349    XFREE (lookback);    XFREE (lookback);
350    bitsetv_free (F);    bitsetv_free (F);

Legend:
Removed from v.1.83  
changed lines
  Added in v.1.84

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