mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 13:23:04 +00:00
For consistency, use lookahead' instead of look-ahead' or
`look_ahead'. Discussed starting at <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00049.html> and then at <http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00017.html>. * NEWS: For the next release, note the change to `--report'. * TODO, doc/bison.1: Update English. * doc/bison.texinfo: Update English. (Understanding Your Parser, Bison Options): Document as `--report=lookahead' rather than `--report=look-ahead'. * src/conflicts.c: Update English in comments. (lookahead_set): Rename from look_ahead_set. (flush_reduce): Rename argument look_ahead_tokens to lookahead_tokens. (resolve_sr_conflict): Rename local look_ahead_tokens to lookahead_tokens, and update other uses. (flush_shift, set_conflicts, conflicts_solve, count_sr_conflicts, count_rr_conflicts, conflicts_free): Update uses. * src/getargs.c (report_args): Move "lookahead" before alternate spellings. (report_types): Update uses. (usage): For `--report' usage description, state `lookahead' spelling rather than `look-ahead'. * src/getargs.h (report.report_lookahead_tokens): Rename from report_look_ahead_tokens. * src/lalr.c: Update English in comments. (compute_lookahead_tokens): Rename from compute_look_ahead_tokens. (state_lookahead_tokens_count): Rename from state_look_ahead_tokens_count. Rename local n_look_ahead_tokens to n_lookahead_tokens. (lookahead_tokens_print): Rename from look_ahead_tokens_print. Rename local n_look_ahead_tokens to n_lookahead_tokens. Update other uses. Update English in output. (add_lookback_edge, initialize_LA, lalr, lalr_free): Update uses. * src/print.c: Update English in comments. (lookahead_set): Rename from look_ahead_set. (print_reduction): Rename argument lookahead_token from look_ahead_token. (print_core, state_default_rule, print_reductions, print_results): Update uses. * src/print_graph.c: Update English in comments. (print_core): Update uses. * src/state.c: Update English in comments. (reductions_new): Update uses. (state_rule_lookahead_tokens_print): Rename from state_rule_look_ahead_tokens_print, and update other uses. * src/state.h: Update English in comments. (reductions.lookahead_tokens): Rename from look_ahead_tokens. (state_rule_lookahead_tokens_print): Rename from state_rule_look_ahead_tokens_print. * src/tables.c: Update English in comments. (conflict_row, action_row): Update uses. * tests/glr-regression.at (Incorrect lookahead during deterministic GLR, Incorrect lookahead during nondeterministic GLR): Rename print_look_ahead to print_lookahead. * tests/torture.at: Update English in comments. (AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR): Rename from AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR. (Many lookahead tokens): Update uses. * data/glr.c: Update English in comments. * lalr1.cc: Likewise. * yacc.c: Likewise. * src/conflicts.h: Likewise. * src/lalr.h: Likewise. * src/main.c: Likewise. * src/output.c: Likewise. * src/parse-gram.c: Likewise. * src/tables.h: Likewise. * tests/calc.at: Likewise.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Find and resolve or report look-ahead conflicts for bison,
|
||||
/* Find and resolve or report lookahead conflicts for bison,
|
||||
|
||||
Copyright (C) 1984, 1989, 1992, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
@@ -43,7 +43,7 @@ static char *conflicts;
|
||||
static struct obstack solved_conflicts_obstack;
|
||||
|
||||
static bitset shift_set;
|
||||
static bitset look_ahead_set;
|
||||
static bitset lookahead_set;
|
||||
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ flush_shift (state *s, int token)
|
||||
transitions *trans = s->transitions;
|
||||
int i;
|
||||
|
||||
bitset_reset (look_ahead_set, token);
|
||||
bitset_reset (lookahead_set, token);
|
||||
for (i = 0; i < trans->num; i++)
|
||||
if (!TRANSITION_IS_DISABLED (trans, i)
|
||||
&& TRANSITION_SYMBOL (trans, i) == token)
|
||||
@@ -157,14 +157,14 @@ flush_shift (state *s, int token)
|
||||
|
||||
/*--------------------------------------------------------------------.
|
||||
| Turn off the reduce recorded for the specified token for the |
|
||||
| specified look-ahead. Used when we resolve a shift-reduce conflict |
|
||||
| specified lookahead. Used when we resolve a shift-reduce conflict |
|
||||
| in favor of the shift. |
|
||||
`--------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
flush_reduce (bitset look_ahead_tokens, int token)
|
||||
flush_reduce (bitset lookahead_tokens, int token)
|
||||
{
|
||||
bitset_reset (look_ahead_tokens, token);
|
||||
bitset_reset (lookahead_tokens, token);
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ flush_reduce (bitset look_ahead_tokens, int token)
|
||||
| rule has a precedence. A conflict is resolved by modifying the |
|
||||
| shift or reduce tables so that there is no longer a conflict. |
|
||||
| |
|
||||
| RULENO is the number of the look-ahead bitset to consider. |
|
||||
| RULENO is the number of the lookahead bitset to consider. |
|
||||
| |
|
||||
| ERRORS can be used to store discovered explicit errors. |
|
||||
`------------------------------------------------------------------*/
|
||||
@@ -187,12 +187,12 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
|
||||
/* Find the rule to reduce by to get precedence of reduction. */
|
||||
rule *redrule = reds->rules[ruleno];
|
||||
int redprec = redrule->prec->prec;
|
||||
bitset look_ahead_tokens = reds->look_ahead_tokens[ruleno];
|
||||
bitset lookahead_tokens = reds->lookahead_tokens[ruleno];
|
||||
int nerrs = 0;
|
||||
|
||||
for (i = 0; i < ntokens; i++)
|
||||
if (bitset_test (look_ahead_tokens, i)
|
||||
&& bitset_test (look_ahead_set, i)
|
||||
if (bitset_test (lookahead_tokens, i)
|
||||
&& bitset_test (lookahead_set, i)
|
||||
&& symbols[i]->prec)
|
||||
{
|
||||
/* Shift-reduce conflict occurs for token number i
|
||||
@@ -206,7 +206,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
|
||||
else if (symbols[i]->prec > redprec)
|
||||
{
|
||||
log_resolution (redrule, i, shift_resolution);
|
||||
flush_reduce (look_ahead_tokens, i);
|
||||
flush_reduce (lookahead_tokens, i);
|
||||
}
|
||||
else
|
||||
/* Matching precedence levels.
|
||||
@@ -221,7 +221,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
|
||||
|
||||
case right_assoc:
|
||||
log_resolution (redrule, i, right_resolution);
|
||||
flush_reduce (look_ahead_tokens, i);
|
||||
flush_reduce (lookahead_tokens, i);
|
||||
break;
|
||||
|
||||
case left_assoc:
|
||||
@@ -232,7 +232,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
|
||||
case non_assoc:
|
||||
log_resolution (redrule, i, nonassoc_resolution);
|
||||
flush_shift (s, i);
|
||||
flush_reduce (look_ahead_tokens, i);
|
||||
flush_reduce (lookahead_tokens, i);
|
||||
/* Record an explicit error for this token. */
|
||||
errors[nerrs++] = symbols[i];
|
||||
break;
|
||||
@@ -258,7 +258,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors)
|
||||
| Solve the S/R conflicts of state S using the |
|
||||
| precedence/associativity, and flag it inconsistent if it still has |
|
||||
| conflicts. ERRORS can be used as storage to compute the list of |
|
||||
| look-ahead tokens on which S raises a syntax error (%nonassoc). |
|
||||
| lookahead tokens on which S raises a syntax error (%nonassoc). |
|
||||
`-------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
@@ -271,27 +271,27 @@ set_conflicts (state *s, symbol **errors)
|
||||
if (s->consistent)
|
||||
return;
|
||||
|
||||
bitset_zero (look_ahead_set);
|
||||
bitset_zero (lookahead_set);
|
||||
|
||||
FOR_EACH_SHIFT (trans, i)
|
||||
bitset_set (look_ahead_set, TRANSITION_SYMBOL (trans, i));
|
||||
bitset_set (lookahead_set, TRANSITION_SYMBOL (trans, i));
|
||||
|
||||
/* Loop over all rules which require look-ahead in this state. First
|
||||
/* Loop over all rules which require lookahead in this state. First
|
||||
check for shift-reduce conflict, and try to resolve using
|
||||
precedence. */
|
||||
for (i = 0; i < reds->num; ++i)
|
||||
if (reds->rules[i]->prec && reds->rules[i]->prec->prec
|
||||
&& !bitset_disjoint_p (reds->look_ahead_tokens[i], look_ahead_set))
|
||||
&& !bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
|
||||
resolve_sr_conflict (s, i, errors);
|
||||
|
||||
/* Loop over all rules which require look-ahead in this state. Check
|
||||
/* Loop over all rules which require lookahead in this state. Check
|
||||
for conflicts not resolved above. */
|
||||
for (i = 0; i < reds->num; ++i)
|
||||
{
|
||||
if (!bitset_disjoint_p (reds->look_ahead_tokens[i], look_ahead_set))
|
||||
if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set))
|
||||
conflicts[s->number] = 1;
|
||||
|
||||
bitset_or (look_ahead_set, look_ahead_set, reds->look_ahead_tokens[i]);
|
||||
bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,12 +305,12 @@ void
|
||||
conflicts_solve (void)
|
||||
{
|
||||
state_number i;
|
||||
/* List of look-ahead tokens on which we explicitly raise a syntax error. */
|
||||
/* List of lookahead tokens on which we explicitly raise a syntax error. */
|
||||
symbol **errors = xnmalloc (ntokens + 1, sizeof *errors);
|
||||
|
||||
conflicts = xcalloc (nstates, sizeof *conflicts);
|
||||
shift_set = bitset_create (ntokens, BITSET_FIXED);
|
||||
look_ahead_set = bitset_create (ntokens, BITSET_FIXED);
|
||||
lookahead_set = bitset_create (ntokens, BITSET_FIXED);
|
||||
obstack_init (&solved_conflicts_obstack);
|
||||
|
||||
for (i = 0; i < nstates; i++)
|
||||
@@ -342,18 +342,18 @@ count_sr_conflicts (state *s)
|
||||
if (!trans)
|
||||
return 0;
|
||||
|
||||
bitset_zero (look_ahead_set);
|
||||
bitset_zero (lookahead_set);
|
||||
bitset_zero (shift_set);
|
||||
|
||||
FOR_EACH_SHIFT (trans, i)
|
||||
bitset_set (shift_set, TRANSITION_SYMBOL (trans, i));
|
||||
|
||||
for (i = 0; i < reds->num; ++i)
|
||||
bitset_or (look_ahead_set, look_ahead_set, reds->look_ahead_tokens[i]);
|
||||
bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]);
|
||||
|
||||
bitset_and (look_ahead_set, look_ahead_set, shift_set);
|
||||
bitset_and (lookahead_set, lookahead_set, shift_set);
|
||||
|
||||
src_count = bitset_count (look_ahead_set);
|
||||
src_count = bitset_count (lookahead_set);
|
||||
|
||||
return src_count;
|
||||
}
|
||||
@@ -378,7 +378,7 @@ count_rr_conflicts (state *s, bool one_per_token)
|
||||
int count = 0;
|
||||
int j;
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->look_ahead_tokens[j], i))
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
count++;
|
||||
|
||||
if (count >= 2)
|
||||
@@ -433,7 +433,7 @@ conflicts_output (FILE *out)
|
||||
/*--------------------------------------------------------.
|
||||
| Total the number of S/R and R/R conflicts. Unlike the |
|
||||
| code in conflicts_output, however, count EACH pair of |
|
||||
| reductions for the same state and look-ahead as one |
|
||||
| reductions for the same state and lookahead as one |
|
||||
| conflict. |
|
||||
`--------------------------------------------------------*/
|
||||
|
||||
@@ -530,6 +530,6 @@ conflicts_free (void)
|
||||
{
|
||||
free (conflicts);
|
||||
bitset_free (shift_set);
|
||||
bitset_free (look_ahead_set);
|
||||
bitset_free (lookahead_set);
|
||||
obstack_free (&solved_conflicts_obstack, NULL);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Find and resolve or report look-ahead conflicts for bison,
|
||||
/* Find and resolve or report lookahead conflicts for bison,
|
||||
Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -145,7 +145,7 @@ static const char * const report_args[] =
|
||||
"none",
|
||||
"state", "states",
|
||||
"itemset", "itemsets",
|
||||
"look-ahead", "lookahead", "lookaheads",
|
||||
"lookahead", "lookaheads", "look-ahead",
|
||||
"solved",
|
||||
"all",
|
||||
0
|
||||
@@ -156,9 +156,9 @@ static const int report_types[] =
|
||||
report_none,
|
||||
report_states, report_states,
|
||||
report_states | report_itemsets, report_states | report_itemsets,
|
||||
report_states | report_look_ahead_tokens,
|
||||
report_states | report_look_ahead_tokens,
|
||||
report_states | report_look_ahead_tokens,
|
||||
report_states | report_lookahead_tokens,
|
||||
report_states | report_lookahead_tokens,
|
||||
report_states | report_lookahead_tokens,
|
||||
report_states | report_solved_conflicts,
|
||||
report_all
|
||||
};
|
||||
@@ -247,7 +247,7 @@ Output:\n\
|
||||
THINGS is a list of comma separated words that can include:\n\
|
||||
`state' describe the states\n\
|
||||
`itemset' complete the core item sets with their closure\n\
|
||||
`look-ahead' explicitly associate look-ahead tokens to items\n\
|
||||
`lookahead' explicitly associate lookahead tokens to items\n\
|
||||
`solved' describe shift/reduce conflicts solving\n\
|
||||
`all' include all the above information\n\
|
||||
`none' disable the report\n\
|
||||
|
||||
@@ -84,7 +84,7 @@ enum report
|
||||
report_none = 0,
|
||||
report_states = 1 << 0,
|
||||
report_itemsets = 1 << 1,
|
||||
report_look_ahead_tokens= 1 << 2,
|
||||
report_lookahead_tokens = 1 << 2,
|
||||
report_solved_conflicts = 1 << 3,
|
||||
report_all = ~0
|
||||
};
|
||||
|
||||
80
src/lalr.c
80
src/lalr.c
@@ -1,4 +1,4 @@
|
||||
/* Compute look-ahead criteria for Bison.
|
||||
/* Compute lookahead criteria for Bison.
|
||||
|
||||
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2006 Free Software Foundation, Inc.
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
/* Compute how to make the finite state machine deterministic; find
|
||||
which rules need look-ahead in each state, and which look-ahead
|
||||
which rules need lookahead in each state, and which lookahead
|
||||
tokens they accept. */
|
||||
|
||||
#include <config.h>
|
||||
@@ -219,9 +219,9 @@ add_lookback_edge (state *s, rule *r, goto_number gotono)
|
||||
{
|
||||
int ri = state_reduction_find (s, r);
|
||||
goto_list *sp = xmalloc (sizeof *sp);
|
||||
sp->next = lookback[(s->reductions->look_ahead_tokens - LA) + ri];
|
||||
sp->next = lookback[(s->reductions->lookahead_tokens - LA) + ri];
|
||||
sp->value = gotono;
|
||||
lookback[(s->reductions->look_ahead_tokens - LA) + ri] = sp;
|
||||
lookback[(s->reductions->lookahead_tokens - LA) + ri] = sp;
|
||||
}
|
||||
|
||||
|
||||
@@ -314,7 +314,7 @@ compute_FOLLOWS (void)
|
||||
|
||||
|
||||
static void
|
||||
compute_look_ahead_tokens (void)
|
||||
compute_lookahead_tokens (void)
|
||||
{
|
||||
size_t i;
|
||||
goto_list *sp;
|
||||
@@ -332,27 +332,27 @@ compute_look_ahead_tokens (void)
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------.
|
||||
| Count the number of look-ahead tokens required for S |
|
||||
| (N_LOOK_AHEAD_TOKENS member). |
|
||||
`-----------------------------------------------------*/
|
||||
/*----------------------------------------------------.
|
||||
| Count the number of lookahead tokens required for S |
|
||||
| (N_LOOKAHEAD_TOKENS member). |
|
||||
`----------------------------------------------------*/
|
||||
|
||||
static int
|
||||
state_look_ahead_tokens_count (state *s)
|
||||
state_lookahead_tokens_count (state *s)
|
||||
{
|
||||
int k;
|
||||
int n_look_ahead_tokens = 0;
|
||||
int n_lookahead_tokens = 0;
|
||||
reductions *rp = s->reductions;
|
||||
transitions *sp = s->transitions;
|
||||
|
||||
/* We need a look-ahead either to distinguish different
|
||||
/* 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'. */
|
||||
if (rp->num > 1
|
||||
|| (rp->num == 1 && sp->num &&
|
||||
!TRANSITION_IS_DISABLED (sp, 0) && TRANSITION_IS_SHIFT (sp, 0)))
|
||||
n_look_ahead_tokens += rp->num;
|
||||
n_lookahead_tokens += rp->num;
|
||||
else
|
||||
s->consistent = 1;
|
||||
|
||||
@@ -363,13 +363,13 @@ state_look_ahead_tokens_count (state *s)
|
||||
break;
|
||||
}
|
||||
|
||||
return n_look_ahead_tokens;
|
||||
return n_lookahead_tokens;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------.
|
||||
| Compute LA, NLA, and the look_ahead_tokens members. |
|
||||
`-----------------------------------------------------*/
|
||||
/*----------------------------------------------------.
|
||||
| Compute LA, NLA, and the lookahead_tokens members. |
|
||||
`----------------------------------------------------*/
|
||||
|
||||
static void
|
||||
initialize_LA (void)
|
||||
@@ -377,10 +377,10 @@ initialize_LA (void)
|
||||
state_number i;
|
||||
bitsetv pLA;
|
||||
|
||||
/* Compute the total number of reductions requiring a look-ahead. */
|
||||
/* Compute the total number of reductions requiring a lookahead. */
|
||||
nLA = 0;
|
||||
for (i = 0; i < nstates; i++)
|
||||
nLA += state_look_ahead_tokens_count (states[i]);
|
||||
nLA += state_lookahead_tokens_count (states[i]);
|
||||
/* Avoid having to special case 0. */
|
||||
if (!nLA)
|
||||
nLA = 1;
|
||||
@@ -388,54 +388,54 @@ initialize_LA (void)
|
||||
pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
|
||||
lookback = xcalloc (nLA, sizeof *lookback);
|
||||
|
||||
/* Initialize the members LOOK_AHEAD_TOKENS for each state whose reductions
|
||||
require look-ahead tokens. */
|
||||
/* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions
|
||||
require lookahead tokens. */
|
||||
for (i = 0; i < nstates; i++)
|
||||
{
|
||||
int count = state_look_ahead_tokens_count (states[i]);
|
||||
int count = state_lookahead_tokens_count (states[i]);
|
||||
if (count)
|
||||
{
|
||||
states[i]->reductions->look_ahead_tokens = pLA;
|
||||
states[i]->reductions->lookahead_tokens = pLA;
|
||||
pLA += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*----------------------------------------------.
|
||||
| Output the look-ahead tokens for each state. |
|
||||
`----------------------------------------------*/
|
||||
/*---------------------------------------------.
|
||||
| Output the lookahead tokens for each state. |
|
||||
`---------------------------------------------*/
|
||||
|
||||
static void
|
||||
look_ahead_tokens_print (FILE *out)
|
||||
lookahead_tokens_print (FILE *out)
|
||||
{
|
||||
state_number i;
|
||||
int j, k;
|
||||
fprintf (out, "Look-ahead tokens: BEGIN\n");
|
||||
fprintf (out, "Lookahead tokens: BEGIN\n");
|
||||
for (i = 0; i < nstates; ++i)
|
||||
{
|
||||
reductions *reds = states[i]->reductions;
|
||||
bitset_iterator iter;
|
||||
int n_look_ahead_tokens = 0;
|
||||
int n_lookahead_tokens = 0;
|
||||
|
||||
if (reds->look_ahead_tokens)
|
||||
if (reds->lookahead_tokens)
|
||||
for (k = 0; k < reds->num; ++k)
|
||||
if (reds->look_ahead_tokens[k])
|
||||
++n_look_ahead_tokens;
|
||||
if (reds->lookahead_tokens[k])
|
||||
++n_lookahead_tokens;
|
||||
|
||||
fprintf (out, "State %d: %d look-ahead tokens\n",
|
||||
i, n_look_ahead_tokens);
|
||||
fprintf (out, "State %d: %d lookahead tokens\n",
|
||||
i, n_lookahead_tokens);
|
||||
|
||||
if (reds->look_ahead_tokens)
|
||||
if (reds->lookahead_tokens)
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
BITSET_FOR_EACH (iter, reds->look_ahead_tokens[j], k, 0)
|
||||
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, "Look-ahead tokens: END\n");
|
||||
fprintf (out, "Lookahead tokens: END\n");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -446,10 +446,10 @@ lalr (void)
|
||||
initialize_F ();
|
||||
build_relations ();
|
||||
compute_FOLLOWS ();
|
||||
compute_look_ahead_tokens ();
|
||||
compute_lookahead_tokens ();
|
||||
|
||||
if (trace_flag & trace_sets)
|
||||
look_ahead_tokens_print (stderr);
|
||||
lookahead_tokens_print (stderr);
|
||||
}
|
||||
|
||||
|
||||
@@ -458,6 +458,6 @@ lalr_free (void)
|
||||
{
|
||||
state_number s;
|
||||
for (s = 0; s < nstates; ++s)
|
||||
states[s]->reductions->look_ahead_tokens = NULL;
|
||||
states[s]->reductions->lookahead_tokens = NULL;
|
||||
bitsetv_free (LA);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Compute look-ahead criteria for bison,
|
||||
/* Compute lookahead criteria for bison,
|
||||
|
||||
Copyright (C) 1984, 1986, 1989, 2000, 2002, 2004 Free Software
|
||||
Foundation, Inc.
|
||||
@@ -33,12 +33,12 @@
|
||||
# include "state.h"
|
||||
|
||||
/* Compute how to make the finite state machine deterministic; find
|
||||
which rules need look-ahead in each state, and which look-ahead
|
||||
which rules need lookahead in each state, and which lookahead
|
||||
tokens they accept. */
|
||||
|
||||
void lalr (void);
|
||||
|
||||
/* Release the information related to look-ahead tokens. Can be performed
|
||||
/* Release the information related to lookahead tokens. Can be performed
|
||||
once the action tables are computed. */
|
||||
|
||||
void lalr_free (void);
|
||||
|
||||
@@ -110,7 +110,7 @@ main (int argc, char *argv[])
|
||||
timevar_pop (TV_LALR);
|
||||
|
||||
/* Find and record any conflicts: places where one token of
|
||||
look-ahead is not enough to disambiguate the parsing. In file
|
||||
lookahead is not enough to disambiguate the parsing. In file
|
||||
conflicts. Also resolve s/r conflicts based on precedence
|
||||
declarations. */
|
||||
timevar_push (TV_CONFLICTS);
|
||||
@@ -150,7 +150,7 @@ main (int argc, char *argv[])
|
||||
if (complaint_issued)
|
||||
goto finish;
|
||||
|
||||
/* Look-ahead tokens are no longer needed. */
|
||||
/* Lookahead tokens are no longer needed. */
|
||||
timevar_push (TV_FREE);
|
||||
lalr_free ();
|
||||
timevar_pop (TV_FREE);
|
||||
|
||||
@@ -448,7 +448,7 @@ static void
|
||||
prepare_actions (void)
|
||||
{
|
||||
/* Figure out the actions for the specified state, indexed by
|
||||
look-ahead token type. */
|
||||
lookahead token type. */
|
||||
|
||||
muscle_insert_rule_number_table ("defact", yydefact,
|
||||
yydefact[0], 1, nstates);
|
||||
|
||||
@@ -1456,15 +1456,15 @@ yyparse ()
|
||||
#endif
|
||||
#endif
|
||||
{
|
||||
/* The look-ahead symbol. */
|
||||
/* The lookahead symbol. */
|
||||
int yychar;
|
||||
|
||||
/* The semantic value of the look-ahead symbol. */
|
||||
/* The semantic value of the lookahead symbol. */
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* Number of syntax errors so far. */
|
||||
int yynerrs;
|
||||
/* Location data for the look-ahead symbol. */
|
||||
/* Location data for the lookahead symbol. */
|
||||
YYLTYPE yylloc;
|
||||
|
||||
int yystate;
|
||||
@@ -1472,7 +1472,7 @@ YYLTYPE yylloc;
|
||||
int yyresult;
|
||||
/* Number of tokens to shift before error messages enabled. */
|
||||
int yyerrstatus;
|
||||
/* Look-ahead token as an internal (translated) token number. */
|
||||
/* Lookahead token as an internal (translated) token number. */
|
||||
int yytoken = 0;
|
||||
#if YYERROR_VERBOSE
|
||||
/* Buffer for error messages, and its allocated size. */
|
||||
@@ -1640,16 +1640,16 @@ YYLTYPE yylloc;
|
||||
yybackup:
|
||||
|
||||
/* Do appropriate processing given the current state. Read a
|
||||
look-ahead token if we need one and don't already have one. */
|
||||
lookahead token if we need one and don't already have one. */
|
||||
|
||||
/* First try to decide what to do without reference to look-ahead token. */
|
||||
/* First try to decide what to do without reference to lookahead token. */
|
||||
yyn = yypact[yystate];
|
||||
if (yyn == YYPACT_NINF)
|
||||
goto yydefault;
|
||||
|
||||
/* Not known => get a look-ahead token if don't already have one. */
|
||||
/* Not known => get a lookahead token if don't already have one. */
|
||||
|
||||
/* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
|
||||
/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
|
||||
if (yychar == YYEMPTY)
|
||||
{
|
||||
YYDPRINTF ((stderr, "Reading a token: "));
|
||||
@@ -1689,7 +1689,7 @@ yybackup:
|
||||
if (yyerrstatus)
|
||||
yyerrstatus--;
|
||||
|
||||
/* Shift the look-ahead token. */
|
||||
/* Shift the lookahead token. */
|
||||
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
|
||||
|
||||
/* Discard the shifted token unless it is eof. */
|
||||
@@ -2216,7 +2216,7 @@ yyerrlab:
|
||||
|
||||
if (yyerrstatus == 3)
|
||||
{
|
||||
/* If just tried and failed to reuse look-ahead token after an
|
||||
/* If just tried and failed to reuse lookahead token after an
|
||||
error, discard it. */
|
||||
|
||||
if (yychar <= YYEOF)
|
||||
@@ -2233,7 +2233,7 @@ yyerrlab:
|
||||
}
|
||||
}
|
||||
|
||||
/* Else will try to reuse look-ahead token after shifting the error
|
||||
/* Else will try to reuse lookahead token after shifting the error
|
||||
token. */
|
||||
goto yyerrlab1;
|
||||
|
||||
@@ -2298,7 +2298,7 @@ yyerrlab1:
|
||||
|
||||
yyerror_range[1] = yylloc;
|
||||
/* Using YYLLOC is tempting, but would change the location of
|
||||
the look-ahead. YYLOC is available though. */
|
||||
the lookahead. YYLOC is available though. */
|
||||
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
|
||||
*++yylsp = yyloc;
|
||||
|
||||
|
||||
62
src/print.c
62
src/print.c
@@ -40,7 +40,7 @@
|
||||
#include "symtab.h"
|
||||
|
||||
static bitset shift_set;
|
||||
static bitset look_ahead_set;
|
||||
static bitset lookahead_set;
|
||||
|
||||
#if 0
|
||||
static void
|
||||
@@ -111,9 +111,9 @@ print_core (FILE *out, state *s)
|
||||
for (/* Nothing */; *sp >= 0; ++sp)
|
||||
fprintf (out, " %s", symbols[*sp]->tag);
|
||||
|
||||
/* Display the look-ahead tokens? */
|
||||
if (report_flag & report_look_ahead_tokens)
|
||||
state_rule_look_ahead_tokens_print (s, &rules[r], out);
|
||||
/* Display the lookahead tokens? */
|
||||
if (report_flag & report_lookahead_tokens)
|
||||
state_rule_lookahead_tokens_print (s, &rules[r], out);
|
||||
|
||||
fputc ('\n', out);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ print_transitions (state *s, FILE *out, bool display_transitions_p)
|
||||
size_t width = 0;
|
||||
int i;
|
||||
|
||||
/* Compute the width of the look-ahead token column. */
|
||||
/* Compute the width of the lookahead token column. */
|
||||
for (i = 0; i < trans->num; i++)
|
||||
if (!TRANSITION_IS_DISABLED (trans, i)
|
||||
&& TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
|
||||
@@ -148,7 +148,7 @@ print_transitions (state *s, FILE *out, bool display_transitions_p)
|
||||
fputc ('\n', out);
|
||||
width += 2;
|
||||
|
||||
/* Report look-ahead tokens and shifts. */
|
||||
/* Report lookahead tokens and shifts. */
|
||||
for (i = 0; i < trans->num; i++)
|
||||
if (!TRANSITION_IS_DISABLED (trans, i)
|
||||
&& TRANSITION_IS_SHIFT (trans, i) == display_transitions_p)
|
||||
@@ -180,7 +180,7 @@ print_errs (FILE *out, state *s)
|
||||
size_t width = 0;
|
||||
int i;
|
||||
|
||||
/* Compute the width of the look-ahead token column. */
|
||||
/* Compute the width of the lookahead token column. */
|
||||
for (i = 0; i < errp->num; ++i)
|
||||
if (errp->symbols[i])
|
||||
max_length (&width, errp->symbols[i]->tag);
|
||||
@@ -192,7 +192,7 @@ print_errs (FILE *out, state *s)
|
||||
fputc ('\n', out);
|
||||
width += 2;
|
||||
|
||||
/* Report look-ahead tokens and errors. */
|
||||
/* Report lookahead tokens and errors. */
|
||||
for (i = 0; i < errp->num; ++i)
|
||||
if (errp->symbols[i])
|
||||
{
|
||||
@@ -218,11 +218,11 @@ state_default_rule (state *s)
|
||||
int cmax = 0;
|
||||
int i;
|
||||
|
||||
/* No need for a look-ahead. */
|
||||
/* No need for a lookahead. */
|
||||
if (s->consistent)
|
||||
return reds->rules[0];
|
||||
|
||||
/* 1. Each reduction is possibly masked by the look-ahead tokens on which
|
||||
/* 1. Each reduction is possibly masked by the lookahead tokens on which
|
||||
we shift (S/R conflicts)... */
|
||||
bitset_zero (shift_set);
|
||||
{
|
||||
@@ -237,7 +237,7 @@ state_default_rule (state *s)
|
||||
}
|
||||
}
|
||||
|
||||
/* 2. Each reduction is possibly masked by the look-ahead tokens on which
|
||||
/* 2. Each reduction is possibly masked by the lookahead tokens on which
|
||||
we raise an error (due to %nonassoc). */
|
||||
{
|
||||
errs *errp = s->errs;
|
||||
@@ -250,10 +250,10 @@ state_default_rule (state *s)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
/* How many non-masked look-ahead tokens are there for this
|
||||
/* How many non-masked lookahead tokens are there for this
|
||||
reduction? */
|
||||
bitset_andn (look_ahead_set, reds->look_ahead_tokens[i], shift_set);
|
||||
count = bitset_count (look_ahead_set);
|
||||
bitset_andn (lookahead_set, reds->lookahead_tokens[i], shift_set);
|
||||
count = bitset_count (lookahead_set);
|
||||
|
||||
if (count > cmax)
|
||||
{
|
||||
@@ -264,27 +264,27 @@ state_default_rule (state *s)
|
||||
/* 3. And finally, each reduction is possibly masked by previous
|
||||
reductions (in R/R conflicts, we keep the first reductions).
|
||||
*/
|
||||
bitset_or (shift_set, shift_set, reds->look_ahead_tokens[i]);
|
||||
bitset_or (shift_set, shift_set, reds->lookahead_tokens[i]);
|
||||
}
|
||||
|
||||
return default_rule;
|
||||
}
|
||||
|
||||
|
||||
/*--------------------------------------------------------------------------.
|
||||
| Report a reduction of RULE on LOOK_AHEAD_TOKEN (which can be `default'). |
|
||||
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
|
||||
| R/R conflicts). |
|
||||
`--------------------------------------------------------------------------*/
|
||||
/*-------------------------------------------------------------------------.
|
||||
| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be `default'). |
|
||||
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
|
||||
| R/R conflicts). |
|
||||
`-------------------------------------------------------------------------*/
|
||||
|
||||
static void
|
||||
print_reduction (FILE *out, size_t width,
|
||||
const char *look_ahead_token,
|
||||
const char *lookahead_token,
|
||||
rule *r, bool enabled)
|
||||
{
|
||||
int j;
|
||||
fprintf (out, " %s", look_ahead_token);
|
||||
for (j = width - strlen (look_ahead_token); j > 0; --j)
|
||||
fprintf (out, " %s", lookahead_token);
|
||||
for (j = width - strlen (lookahead_token); j > 0; --j)
|
||||
fputc (' ', out);
|
||||
if (!enabled)
|
||||
fputc ('[', out);
|
||||
@@ -320,17 +320,17 @@ print_reductions (FILE *out, state *s)
|
||||
FOR_EACH_SHIFT (trans, i)
|
||||
bitset_set (shift_set, TRANSITION_SYMBOL (trans, i));
|
||||
|
||||
/* Compute the width of the look-ahead token column. */
|
||||
/* Compute the width of the lookahead token column. */
|
||||
if (default_rule)
|
||||
width = strlen (_("$default"));
|
||||
|
||||
if (reds->look_ahead_tokens)
|
||||
if (reds->lookahead_tokens)
|
||||
for (i = 0; i < ntokens; i++)
|
||||
{
|
||||
bool count = bitset_test (shift_set, i);
|
||||
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->look_ahead_tokens[j], i))
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
{
|
||||
if (! count)
|
||||
{
|
||||
@@ -352,15 +352,15 @@ print_reductions (FILE *out, state *s)
|
||||
fputc ('\n', out);
|
||||
width += 2;
|
||||
|
||||
/* Report look-ahead tokens (or $default) and reductions. */
|
||||
if (reds->look_ahead_tokens)
|
||||
/* Report lookahead tokens (or $default) and reductions. */
|
||||
if (reds->lookahead_tokens)
|
||||
for (i = 0; i < ntokens; i++)
|
||||
{
|
||||
bool defaulted = false;
|
||||
bool count = bitset_test (shift_set, i);
|
||||
|
||||
for (j = 0; j < reds->num; ++j)
|
||||
if (bitset_test (reds->look_ahead_tokens[j], i))
|
||||
if (bitset_test (reds->lookahead_tokens[j], i))
|
||||
{
|
||||
if (! count)
|
||||
{
|
||||
@@ -563,11 +563,11 @@ print_results (void)
|
||||
new_closure (nritems);
|
||||
/* Storage for print_reductions. */
|
||||
shift_set = bitset_create (ntokens, BITSET_FIXED);
|
||||
look_ahead_set = bitset_create (ntokens, BITSET_FIXED);
|
||||
lookahead_set = bitset_create (ntokens, BITSET_FIXED);
|
||||
for (i = 0; i < nstates; i++)
|
||||
print_state (out, states[i]);
|
||||
bitset_free (shift_set);
|
||||
bitset_free (look_ahead_set);
|
||||
bitset_free (lookahead_set);
|
||||
if (report_flag & report_itemsets)
|
||||
free_closure ();
|
||||
|
||||
|
||||
@@ -88,21 +88,21 @@ print_core (struct obstack *oout, state *s)
|
||||
for (/* Nothing */; *sp >= 0; ++sp)
|
||||
obstack_fgrow1 (oout, " %s", symbols[*sp]->tag);
|
||||
|
||||
/* Experimental feature: display the look-ahead tokens. */
|
||||
if (report_flag & report_look_ahead_tokens)
|
||||
/* Experimental feature: display the lookahead tokens. */
|
||||
if (report_flag & report_lookahead_tokens)
|
||||
{
|
||||
/* Find the reduction we are handling. */
|
||||
reductions *reds = s->reductions;
|
||||
int redno = state_reduction_find (s, &rules[r]);
|
||||
|
||||
/* Print them if there are. */
|
||||
if (reds->look_ahead_tokens && redno != -1)
|
||||
if (reds->lookahead_tokens && redno != -1)
|
||||
{
|
||||
bitset_iterator biter;
|
||||
int k;
|
||||
char const *sep = "";
|
||||
obstack_sgrow (oout, "[");
|
||||
BITSET_FOR_EACH (biter, reds->look_ahead_tokens[redno], k, 0)
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
|
||||
{
|
||||
obstack_fgrow2 (oout, "%s%s", sep, symbols[k]->tag);
|
||||
sep = ", ";
|
||||
|
||||
16
src/state.c
16
src/state.c
@@ -105,7 +105,7 @@ reductions_new (int num, rule **reds)
|
||||
size_t rules_size = num * sizeof *reds;
|
||||
reductions *res = xmalloc (offsetof (reductions, rules) + rules_size);
|
||||
res->num = num;
|
||||
res->look_ahead_tokens = NULL;
|
||||
res->lookahead_tokens = NULL;
|
||||
memcpy (res->rules, reds, rules_size);
|
||||
return res;
|
||||
}
|
||||
@@ -218,26 +218,26 @@ state_errs_set (state *s, int num, symbol **tokens)
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------.
|
||||
| Print on OUT all the look-ahead tokens such that S |
|
||||
| wants to reduce R. |
|
||||
`---------------------------------------------------*/
|
||||
/*--------------------------------------------------.
|
||||
| Print on OUT all the lookahead tokens such that S |
|
||||
| wants to reduce R. |
|
||||
`--------------------------------------------------*/
|
||||
|
||||
void
|
||||
state_rule_look_ahead_tokens_print (state *s, rule *r, FILE *out)
|
||||
state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out)
|
||||
{
|
||||
/* Find the reduction we are handling. */
|
||||
reductions *reds = s->reductions;
|
||||
int red = state_reduction_find (s, r);
|
||||
|
||||
/* Print them if there are. */
|
||||
if (reds->look_ahead_tokens && red != -1)
|
||||
if (reds->lookahead_tokens && red != -1)
|
||||
{
|
||||
bitset_iterator biter;
|
||||
int k;
|
||||
char const *sep = "";
|
||||
fprintf (out, " [");
|
||||
BITSET_FOR_EACH (biter, reds->look_ahead_tokens[red], k, 0)
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0)
|
||||
{
|
||||
fprintf (out, "%s%s", sep, symbols[k]->tag);
|
||||
sep = ", ";
|
||||
|
||||
12
src/state.h
12
src/state.h
@@ -46,11 +46,11 @@
|
||||
Each core contains a vector of NITEMS items which are the indices
|
||||
in the RITEMS vector of the items that are selected in this state.
|
||||
|
||||
The two types of actions are shifts/gotos (push the look-ahead token
|
||||
The two types of actions are shifts/gotos (push the lookahead token
|
||||
and read another/goto to the state designated by a nterm) and
|
||||
reductions (combine the last n things on the stack via a rule,
|
||||
replace them with the symbol that the rule derives, and leave the
|
||||
look-ahead token alone). When the states are generated, these
|
||||
lookahead token alone). When the states are generated, these
|
||||
actions are represented in two other lists.
|
||||
|
||||
Each transition structure describes the possible transitions out
|
||||
@@ -185,7 +185,7 @@ errs *errs_new (int num, symbol **tokens);
|
||||
typedef struct
|
||||
{
|
||||
int num;
|
||||
bitset *look_ahead_tokens;
|
||||
bitset *lookahead_tokens;
|
||||
rule *rules[1];
|
||||
} reductions;
|
||||
|
||||
@@ -203,7 +203,7 @@ struct state
|
||||
reductions *reductions;
|
||||
errs *errs;
|
||||
|
||||
/* Nonzero if no look-ahead is needed to decide what to do in state S. */
|
||||
/* Nonzero if no lookahead is needed to decide what to do in state S. */
|
||||
char consistent;
|
||||
|
||||
/* If some conflicts were solved thanks to precedence/associativity,
|
||||
@@ -234,9 +234,9 @@ int state_reduction_find (state *s, rule *r);
|
||||
/* Set the errs of STATE. */
|
||||
void state_errs_set (state *s, int num, symbol **errors);
|
||||
|
||||
/* Print on OUT all the look-ahead tokens such that this STATE wants to
|
||||
/* Print on OUT all the lookahead tokens such that this STATE wants to
|
||||
reduce R. */
|
||||
void state_rule_look_ahead_tokens_print (state *s, rule *r, FILE *out);
|
||||
void state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out);
|
||||
|
||||
/* Create/destroy the states hash table. */
|
||||
void state_hash_new (void);
|
||||
|
||||
14
src/tables.c
14
src/tables.c
@@ -198,7 +198,7 @@ conflict_row (state *s)
|
||||
/* Find all reductions for token J, and record all that do not
|
||||
match ACTROW[J]. */
|
||||
for (i = 0; i < reds->num; i += 1)
|
||||
if (bitset_test (reds->look_ahead_tokens[i], j)
|
||||
if (bitset_test (reds->lookahead_tokens[i], j)
|
||||
&& (actrow[j]
|
||||
!= rule_number_as_item_number (reds->rules[i]->number)))
|
||||
{
|
||||
@@ -219,7 +219,7 @@ conflict_row (state *s)
|
||||
|
||||
/*------------------------------------------------------------------.
|
||||
| Decide what to do for each type of token if seen as the |
|
||||
| look-ahead in specified state. The value returned is used as the |
|
||||
| lookahead in specified state. The value returned is used as the |
|
||||
| default action (yydefact) for the state. In addition, ACTROW is |
|
||||
| filled with what to do for each kind of token, index by symbol |
|
||||
| number, with zero meaning do the default action. The value |
|
||||
@@ -227,7 +227,7 @@ conflict_row (state *s)
|
||||
| situation is an error. The parser recognizes this value |
|
||||
| specially. |
|
||||
| |
|
||||
| This is where conflicts are resolved. The loop over look-ahead |
|
||||
| This is where conflicts are resolved. The loop over lookahead |
|
||||
| rules considered lower-numbered rules last, and the last rule |
|
||||
| considered that likes a token gets to handle it. |
|
||||
| |
|
||||
@@ -252,17 +252,17 @@ action_row (state *s)
|
||||
for (i = 0; i < ntokens; i++)
|
||||
actrow[i] = conflrow[i] = 0;
|
||||
|
||||
if (reds->look_ahead_tokens)
|
||||
if (reds->lookahead_tokens)
|
||||
{
|
||||
int j;
|
||||
bitset_iterator biter;
|
||||
/* loop over all the rules available here which require
|
||||
look-ahead (in reverse order to give precedence to the first
|
||||
lookahead (in reverse order to give precedence to the first
|
||||
rule) */
|
||||
for (i = reds->num - 1; i >= 0; --i)
|
||||
/* and find each token which the rule finds acceptable
|
||||
to come next */
|
||||
BITSET_FOR_EACH (biter, reds->look_ahead_tokens[i], j, 0)
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[i], j, 0)
|
||||
{
|
||||
/* and record this rule as the rule to use if that
|
||||
token follows. */
|
||||
@@ -410,7 +410,7 @@ save_row (state_number s)
|
||||
|
||||
/*------------------------------------------------------------------.
|
||||
| Figure out the actions for the specified state, indexed by |
|
||||
| look-ahead token type. |
|
||||
| lookahead token type. |
|
||||
| |
|
||||
| The YYDEFACT table is output now. The detailed info is saved for |
|
||||
| putting into YYTABLE later. |
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
something else to do.
|
||||
|
||||
YYPACT[S] = index in YYTABLE of the portion describing state S.
|
||||
The look-ahead token's type is used to index that portion to find
|
||||
The lookahead token's type is used to index that portion to find
|
||||
out what to do.
|
||||
|
||||
If the value in YYTABLE is positive, we shift the token and go to
|
||||
|
||||
Reference in New Issue
Block a user