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

Diff of /bison/src/conflicts.c

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

revision 1.75 by akim, Sat May 25 16:12:40 2002 UTC revision 1.76 by akim, Sun May 26 20:25:52 2002 UTC
# Line 35  Line 35 
35  /* -1 stands for not specified. */  /* -1 stands for not specified. */
36  int expected_conflicts = -1;  int expected_conflicts = -1;
37  static char *conflicts = NULL;  static char *conflicts = NULL;
38    struct obstack solved_conflicts_obstack;
39    
40  static bitset shiftset;  static bitset shiftset;
41  static bitset lookaheadset;  static bitset lookaheadset;
42    
43    
44    
45    enum conflict_resolution_e
46      {
47        shift_resolution,
48        reduce_resolution,
49        left_resolution,
50        right_resolution,
51        nonassoc_resolution,
52      };
53    
54    
55  static inline void  static inline void
56  log_resolution (state_t *state, int LAno, int token, const char *resolution)  log_resolution (int lookahead, int token,
57                    enum conflict_resolution_e resolution)
58  {  {
59    if (report_flag & report_states)    if (report_flag & report_solved_conflicts)
60      obstack_fgrow4 (&output_obstack,      {
61                      _("\        /* The description of the resolution. */
62  Conflict in state %d between rule %d and token %s resolved as %s.\n"),        switch (resolution)
63                      state->number,          {
64                      LArule[LAno]->number,          case shift_resolution:
65                      symbols[token]->tag,          case left_resolution:
66                      resolution);            obstack_fgrow2 (&solved_conflicts_obstack,
67                              _("\
68        Conflict between rule %d and token %s resolved as shift"),
69                              LArule[lookahead]->number,
70                              symbols[token]->tag);
71              break;
72            case reduce_resolution:
73            case right_resolution:
74              obstack_fgrow2 (&solved_conflicts_obstack,
75                              _("\
76        Conflict between rule %d and token %s resolved as reduce"),
77                              LArule[lookahead]->number,
78                              symbols[token]->tag);
79              break;
80            case nonassoc_resolution:
81              obstack_fgrow2 (&solved_conflicts_obstack,
82                              _("\
83        Conflict between rule %d and token %s resolved as an error"),
84                              LArule[lookahead]->number,
85                              symbols[token]->tag);
86              break;
87            }
88    
89          /* The reason. */
90          switch (resolution)
91            {
92            case shift_resolution:
93              obstack_fgrow2 (&solved_conflicts_obstack,
94                              " (%s < %s)",
95                              LArule[lookahead]->prec->tag,
96                              symbols[token]->tag);
97              break;
98    
99            case reduce_resolution:
100              obstack_fgrow2 (&solved_conflicts_obstack,
101                              " (%s < %s)",
102                              symbols[token]->tag,
103                              LArule[lookahead]->prec->tag);
104              break;
105    
106            case left_resolution:
107              obstack_printf (&solved_conflicts_obstack,
108                              " (%%left %s)",
109                              symbols[token]->tag);
110              break;
111    
112            case right_resolution:
113              obstack_fgrow1 (&solved_conflicts_obstack,
114                              " (%%right %s)",
115                              symbols[token]->tag);
116              break;
117            case nonassoc_resolution:
118              obstack_fgrow1 (&solved_conflicts_obstack,
119                              " (%%nonassoc %s)",
120                              symbols[token]->tag);
121              break;
122            }
123          obstack_sgrow (&solved_conflicts_obstack, ".\n");
124        }
125  }  }
126    
127    
# Line 112  resolve_sr_conflict (state_t *state, int Line 183  resolve_sr_conflict (state_t *state, int
183             The precedence of shifting is that of token i.  */             The precedence of shifting is that of token i.  */
184          if (symbols[i]->prec < redprec)          if (symbols[i]->prec < redprec)
185            {            {
186              log_resolution (state, lookahead, i, _("reduce"));              log_resolution (lookahead, i, reduce_resolution);
187              flush_shift (state, i);              flush_shift (state, i);
188            }            }
189          else if (symbols[i]->prec > redprec)          else if (symbols[i]->prec > redprec)
190            {            {
191              log_resolution (state, lookahead, i, _("shift"));              log_resolution (lookahead, i, shift_resolution);
192              flush_reduce (lookahead, i);              flush_reduce (lookahead, i);
193            }            }
194          else          else
# Line 129  resolve_sr_conflict (state_t *state, int Line 200  resolve_sr_conflict (state_t *state, int
200            switch (symbols[i]->assoc)            switch (symbols[i]->assoc)
201              {              {
202              case right_assoc:              case right_assoc:
203                log_resolution (state, lookahead, i, _("shift"));                log_resolution (lookahead, i, right_resolution);
204                flush_reduce (lookahead, i);                flush_reduce (lookahead, i);
205                break;                break;
206    
207              case left_assoc:              case left_assoc:
208                log_resolution (state, lookahead, i, _("reduce"));                log_resolution (lookahead, i, left_resolution);
209                flush_shift (state, i);                flush_shift (state, i);
210                break;                break;
211    
212              case non_assoc:              case non_assoc:
213                log_resolution (state, lookahead, i, _("an error"));                log_resolution (lookahead, i, nonassoc_resolution);
214                flush_shift (state, i);                flush_shift (state, i);
215                flush_reduce (lookahead, i);                flush_reduce (lookahead, i);
216                /* Record an explicit error for this token.  */                /* Record an explicit error for this token.  */
# Line 152  resolve_sr_conflict (state_t *state, int Line 223  resolve_sr_conflict (state_t *state, int
223       permanent errs structure for this state, to record them.  */       permanent errs structure for this state, to record them.  */
224    state->errs = errs_dup (errp);    state->errs = errs_dup (errp);
225    free (errp);    free (errp);
226    
227      if (obstack_object_size (&solved_conflicts_obstack))
228        {
229          obstack_1grow (&solved_conflicts_obstack, '\0');
230          state->solved_conflicts = obstack_finish (&solved_conflicts_obstack);
231        }
232  }  }
233    
234    
# Line 195  set_conflicts (state_t *state) Line 272  set_conflicts (state_t *state)
272  }  }
273    
274  void  void
275  solve_conflicts (void)  conflicts_solve (void)
276  {  {
277    size_t i;    size_t i;
278    
279    conflicts = XCALLOC (char, nstates);    conflicts = XCALLOC (char, nstates);
280    shiftset = bitset_create (ntokens, BITSET_FIXED);    shiftset = bitset_create (ntokens, BITSET_FIXED);
281    lookaheadset = bitset_create (ntokens, BITSET_FIXED);    lookaheadset = bitset_create (ntokens, BITSET_FIXED);
282      obstack_init (&solved_conflicts_obstack);
283    
284    for (i = 0; i < nstates; i++)    for (i = 0; i < nstates; i++)
285      set_conflicts (states[i]);      set_conflicts (states[i]);
# Line 393  conflicts_print (void) Line 471  conflicts_print (void)
471    
472    
473  void  void
474  free_conflicts (void)  conflicts_free (void)
475  {  {
476    XFREE (conflicts);    XFREE (conflicts);
477    bitset_free (shiftset);    bitset_free (shiftset);
478    bitset_free (lookaheadset);    bitset_free (lookaheadset);
479      obstack_free (&solved_conflicts_obstack, NULL);
480  }  }

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

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