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

Diff of /bison/src/gram.c

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

revision 1.42 by akim, Thu Jul 25 21:21:02 2002 UTC revision 1.43 by akim, Fri Aug 2 08:05:01 2002 UTC
# Line 47  int glr_parser = 0; Line 47  int glr_parser = 0;
47  int pure_parser = 0;  int pure_parser = 0;
48    
49    
50    /*--------------------------------------------------------------.
51    | Return true IFF the rule has a `number' smaller than NRULES.  |
52    `--------------------------------------------------------------*/
53    
54    bool
55    rule_useful_p (rule_t *r)
56    {
57      return r->number < nrules;
58    }
59    
60    
61    /*-------------------------------------------------------------.
62    | Return true IFF the rule has a `number' higher than NRULES.  |
63    `-------------------------------------------------------------*/
64    
65    bool
66    rule_useless_p (rule_t *r)
67    {
68      return r->number >= nrules;
69    }
70    
71    
72    /*--------------------------------------------------------------------.
73    | Return true IFF the rule is not flagged as useful *and* is useful.  |
74    | In other words, it was discarded because of conflicts.              |
75    `--------------------------------------------------------------------*/
76    
77    bool
78    rule_never_reduced_p (rule_t *r)
79    {
80      return !r->useful && r->number < nrules;
81    }
82    
83    
84  /*----------------------------------------------------------------.  /*----------------------------------------------------------------.
85  | Print this RULE's number and lhs on OUT.  If a PREVIOUS_LHS was |  | Print this RULE's number and lhs on OUT.  If a PREVIOUS_LHS was |
86  | already displayed (by a previous call for another rule), avoid  |  | already displayed (by a previous call for another rule), avoid  |
# Line 158  ritem_longest_rhs (void) Line 192  ritem_longest_rhs (void)
192  }  }
193    
194    
195  /*----------------------------------------------------------------.  /*-----------------------------------------------------------------.
196  | Print the grammar's rules numbers from BEGIN (inclusive) to END |  | Print the grammar's rules that match FILTER on OUT under TITLE.  |
197  | (exclusive) on OUT under TITLE.                                 |  `-----------------------------------------------------------------*/
 `----------------------------------------------------------------*/  
198    
199  void  void
200  grammar_rules_partial_print (FILE *out, const char *title,  grammar_rules_partial_print (FILE *out, const char *title,
201                               rule_number_t begin, rule_number_t end)                               rule_filter_t filter)
202  {  {
203    int r;    int r;
204      bool first = TRUE;
205    symbol_t *previous_lhs = NULL;    symbol_t *previous_lhs = NULL;
206    
207    /* rule # : LHS -> RHS */    /* rule # : LHS -> RHS */
208    fprintf (out, "%s\n\n", title);    for (r = 0; r < nrules + nuseless_productions; r++)
   for (r = begin; r < end; r++)  
209      {      {
210        if (previous_lhs && previous_lhs != rules[r].lhs)        if (filter && !filter (&rules[r]))
211            continue;
212          if (first)
213            fprintf (out, "%s\n\n", title);
214          else if (previous_lhs && previous_lhs != rules[r].lhs)
215          fputc ('\n', out);          fputc ('\n', out);
216          first = FALSE;
217        rule_lhs_print (&rules[r], previous_lhs, out);        rule_lhs_print (&rules[r], previous_lhs, out);
218        rule_rhs_print (&rules[r], out);        rule_rhs_print (&rules[r], out);
219        previous_lhs = rules[r].lhs;        previous_lhs = rules[r].lhs;
220      }      }
221    fputs ("\n\n", out);    if (!first)
222        fputs ("\n\n", out);
223  }  }
224    
225    
# Line 191  grammar_rules_partial_print (FILE *out, Line 230  grammar_rules_partial_print (FILE *out,
230  void  void
231  grammar_rules_print (FILE *out)  grammar_rules_print (FILE *out)
232  {  {
233    grammar_rules_partial_print (out, _("Grammar"), 0, nrules);    grammar_rules_partial_print (out, _("Grammar"), rule_useful_p);
234  }  }
235    
236    
# Line 262  grammar_dump (FILE *out, const char *tit Line 301  grammar_dump (FILE *out, const char *tit
301  }  }
302    
303    
304    /*------------------------------------------------------------------.
305    | Report on STDERR the rules that are not flagged USEFUL, using the |
306    | MESSAGE (which can be `useless rule' when invoked after grammar   |
307    | reduction, or `never reduced' after conflicts were taken into     |
308    | account).                                                         |
309    `------------------------------------------------------------------*/
310    
311    void
312    grammar_rules_never_reduced_report (const char *message)
313    {
314      rule_number_t r;
315      for (r = 0; r < nrules ; ++r)
316        if (!rules[r].useful)
317          {
318            LOCATION_PRINT (stderr, rules[r].location);
319            fprintf (stderr, ": %s: %s: ",
320                     _("warning"), message);
321            rule_print (&rules[r], stderr);
322          }
323    }
324    
325  void  void
326  grammar_free (void)  grammar_free (void)
327  {  {

Legend:
Removed from v.1.42  
changed lines
  Added in v.1.43

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