X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/81ebdef91dce5d4b2f0d2b3bbfa8e0ac8877aa01..9b33de72cd2469bedac2b5f0a48a8782571ea9db:/src/gram.c diff --git a/src/gram.c b/src/gram.c index a0e1dc5a..28666b0c 100644 --- a/src/gram.c +++ b/src/gram.c @@ -1,5 +1,7 @@ -/* Allocate input grammar variables for bison, - Copyright (C) 1984, 1986, 1989, 2001, 2002 Free Software Foundation, Inc. +/* Allocate input grammar variables for Bison. + + Copyright (C) 1984, 1986, 1989, 2001, 2002, 2003, 2005, 2006 Free + Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -15,10 +17,10 @@ You should have received a copy of the GNU General Public License along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ +#include #include "system.h" #include @@ -45,10 +47,6 @@ symbol_number *token_translations = NULL; int max_user_token_number = 256; -int glr_parser = 0; -int pure_parser = 0; - - /*--------------------------------------------------------------. | Return true IFF the rule has a `number' smaller than NRULES. | `--------------------------------------------------------------*/ @@ -67,7 +65,7 @@ rule_useful_p (rule *r) bool rule_useless_p (rule *r) { - return r->number >= nrules; + return !rule_useful_p (r); } @@ -79,7 +77,7 @@ rule_useless_p (rule *r) bool rule_never_reduced_p (rule *r) { - return !r->useful && r->number < nrules; + return !r->useful && rule_useful_p (r); } @@ -202,7 +200,7 @@ void grammar_rules_partial_print (FILE *out, const char *title, rule_filter filter) { - int r; + rule_number r; bool first = true; symbol *previous_lhs = NULL; @@ -269,11 +267,11 @@ grammar_dump (FILE *out, const char *title) for (i = 0; i < nrules + nuseless_productions; i++) { rule *rule_i = &rules[i]; - item_number *r = NULL; + item_number *rp = NULL; unsigned int rhs_itemno = rule_i->rhs - ritem; - unsigned int rhs_count = 0; + unsigned int rhs_count = 0; /* Find the last RHS index in ritems. */ - for (r = rule_i->rhs; *r >= 0; ++r) + for (rp = rule_i->rhs; *rp >= 0; ++rp) ++rhs_count; fprintf (out, "%3d (%2d, %2d, %2d, %2u-%2u) %2d ->", i, @@ -284,9 +282,9 @@ grammar_dump (FILE *out, const char *title) rhs_itemno + rhs_count - 1, rule_i->lhs->number); /* Dumped the RHS. */ - for (r = rule_i->rhs; *r >= 0; r++) - fprintf (out, " %3d", *r); - fprintf (out, " [%d]\n", item_number_as_rule_number (*r)); + for (rp = rule_i->rhs; *rp >= 0; rp++) + fprintf (out, " %3d", *rp); + fprintf (out, " [%d]\n", item_number_as_rule_number (*rp)); } } fprintf (out, "\n\n"); @@ -319,8 +317,7 @@ grammar_rules_never_reduced_report (const char *message) if (!rules[r].useful) { location_print (stderr, rules[r].location); - fprintf (stderr, ": %s: %s: ", - _("warning"), message); + fprintf (stderr, ": %s: %s: ", _("warning"), message); rule_print (&rules[r], stderr); } } @@ -328,9 +325,10 @@ grammar_rules_never_reduced_report (const char *message) void grammar_free (void) { - XFREE (ritem); + if (ritem) + free (ritem - 1); free (rules); - XFREE (token_translations); + free (token_translations); /* Free the symbol table data structure. */ symbols_free (); free_merger_functions ();