X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/23d13411c85d3a8705f9507219f61eddea57a218..975bb564319aa4f4204c48aba265757ba207a80f:/src/lalr.c diff --git a/src/lalr.c b/src/lalr.c index 1ceda002..ede8e607 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -1,6 +1,6 @@ /* Compute lookahead criteria for Bison. - Copyright (C) 1984, 1986, 1989, 2000-2012 Free Software Foundation, + Copyright (C) 1984, 1986, 1989, 2000-2014 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -67,17 +67,13 @@ static goto_number **includes; static goto_list **lookback; - - void set_goto_map (void) { state_number s; - goto_number *temp_map; + goto_number *temp_map = xnmalloc (nvars + 1, sizeof *temp_map); goto_map = xcalloc (nvars + 1, sizeof *goto_map); - temp_map = xnmalloc (nvars + 1, sizeof *temp_map); - ngotos = 0; for (s = 0; s < nstates; ++s) { @@ -132,16 +128,13 @@ set_goto_map (void) goto_number map_goto (state_number s0, symbol_number sym) { - goto_number high; - goto_number low; - goto_number middle; - state_number s; - - low = goto_map[sym - ntokens]; - high = goto_map[sym - ntokens + 1] - 1; + goto_number low = goto_map[sym - ntokens]; + goto_number high = goto_map[sym - ntokens + 1] - 1; for (;;) { + goto_number middle; + state_number s; aver (low <= high); middle = (low + high) / 2; s = from_state[middle]; @@ -342,7 +335,7 @@ state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept) /* We need a lookahead either to distinguish different reductions (i.e., there are two or more), or to distinguish a reduction from a shift. Otherwise, it is straightforward, and the state is - `consistent'. However, do not treat a state with any reductions as + 'consistent'. However, do not treat a state with any reductions as consistent unless it is the accepting state (because there is never a lookahead token that makes sense there, and so no lookahead token should be read) if the user has otherwise disabled default @@ -371,7 +364,7 @@ initialize_LA (void) bool default_reduction_only_for_accept; { char *default_reductions = - muscle_percent_define_get ("lr.default-reductions"); + muscle_percent_define_get ("lr.default-reduction"); default_reduction_only_for_accept = STREQ (default_reductions, "accepting"); free (default_reductions); } @@ -412,7 +405,6 @@ static void lookahead_tokens_print (FILE *out) { state_number i; - int j, k; fprintf (out, "Lookahead tokens: BEGIN\n"); for (i = 0; i < nstates; ++i) { @@ -421,21 +413,25 @@ lookahead_tokens_print (FILE *out) int n_lookahead_tokens = 0; if (reds->lookahead_tokens) - for (k = 0; k < reds->num; ++k) - if (reds->lookahead_tokens[k]) - ++n_lookahead_tokens; + { + int j; + for (j = 0; j < reds->num; ++j) + if (reds->lookahead_tokens[j]) + ++n_lookahead_tokens; + } fprintf (out, "State %d: %d lookahead tokens\n", i, n_lookahead_tokens); if (reds->lookahead_tokens) - for (j = 0; j < reds->num; ++j) - BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0) - { - fprintf (out, " on %d (%s) -> rule %d\n", - k, symbols[k]->tag, - reds->rules[j]->number); - }; + { + int j, k; + for (j = 0; j < reds->num; ++j) + BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0) + fprintf (out, " on %d (%s) -> rule %d\n", + k, symbols[k]->tag, + reds->rules[j]->number); + } } fprintf (out, "Lookahead tokens: END\n"); }