style: s/lookahead_tokens/lookaheads/g

Currently we use both names.  Let's stick to the short one.

* src/AnnotationList.c, src/conflicts.c, src/counterexample.c,
* src/getargs.c, src/getargs.h, src/graphviz.c, src/ielr.c,
* src/lalr.c, src/print-graph.c, src/print-xml.c, src/print.c,
* src/state-item.c, src/state.c, src/state.h, src/tables.c:
s/lookahead_token/lookahead/gi.
This commit is contained in:
Akim Demaille
2020-07-12 15:16:51 +02:00
parent c04693d651
commit 78f72a4516
16 changed files with 104 additions and 107 deletions

View File

@@ -169,10 +169,10 @@ AnnotationList__compute_conflicted_tokens (bitset shift_tokens,
bitset_copy (tokens, shift_tokens); bitset_copy (tokens, shift_tokens);
for (int i = 0; i < reds->num; ++i) for (int i = 0; i < reds->num; ++i)
{ {
bitset_and (conflicted_tokens_rule, tokens, reds->lookahead_tokens[i]); bitset_and (conflicted_tokens_rule, tokens, reds->lookaheads[i]);
bitset_or (conflicted_tokens, bitset_or (conflicted_tokens,
conflicted_tokens, conflicted_tokens_rule); conflicted_tokens, conflicted_tokens_rule);
bitset_or (tokens, tokens, reds->lookahead_tokens[i]); bitset_or (tokens, tokens, reds->lookaheads[i]);
/* Check that rules are sorted on rule number or the next step in /* Check that rules are sorted on rule number or the next step in
AnnotationList__compute_from_inadequacies will misbehave. */ AnnotationList__compute_from_inadequacies will misbehave. */
aver (i == 0 || reds->rules[i-1] < reds->rules[i]); aver (i == 0 || reds->rules[i-1] < reds->rules[i]);
@@ -401,7 +401,7 @@ AnnotationList__compute_from_inadequacies (
struct obstack *annotations_obstackp, struct obstack *annotations_obstackp,
InadequacyListNodeCount *inadequacy_list_node_count) InadequacyListNodeCount *inadequacy_list_node_count)
{ {
/* Return an empty list if s->lookahead_tokens = NULL. */ /* Return an empty list if s->lookaheads = NULL. */
if (s->consistent) if (s->consistent)
return; return;
@@ -422,7 +422,7 @@ AnnotationList__compute_from_inadequacies (
/* Allocate the annotation node. */ /* Allocate the annotation node. */
{ {
for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i) for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
if (bitset_test (s->reductions->lookahead_tokens[rule_i], if (bitset_test (s->reductions->lookaheads[rule_i],
conflicted_token)) conflicted_token))
++contribution_count; ++contribution_count;
if (bitset_test (shift_tokens, conflicted_token)) if (bitset_test (shift_tokens, conflicted_token))
@@ -445,7 +445,7 @@ AnnotationList__compute_from_inadequacies (
for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i) for (int rule_i = 0; rule_i < s->reductions->num; ++rule_i)
{ {
rule *the_rule = s->reductions->rules[rule_i]; rule *the_rule = s->reductions->rules[rule_i];
if (bitset_test (s->reductions->lookahead_tokens[rule_i], if (bitset_test (s->reductions->lookaheads[rule_i],
conflicted_token)) conflicted_token))
{ {
bitset_set (actions, rule_i); bitset_set (actions, rule_i);

View File

@@ -250,9 +250,9 @@ flush_shift (state *s, int token)
`--------------------------------------------------------------------*/ `--------------------------------------------------------------------*/
static void static void
flush_reduce (bitset lookahead_tokens, int token) flush_reduce (bitset lookaheads, int token)
{ {
bitset_reset (lookahead_tokens, token); bitset_reset (lookaheads, token);
} }
@@ -275,10 +275,10 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
/* Find the rule to reduce by to get precedence of reduction. */ /* Find the rule to reduce by to get precedence of reduction. */
rule *redrule = reds->rules[ruleno]; rule *redrule = reds->rules[ruleno];
int redprec = redrule->prec->prec; int redprec = redrule->prec->prec;
bitset lookahead_tokens = reds->lookahead_tokens[ruleno]; bitset lookaheads = reds->lookaheads[ruleno];
for (symbol_number i = 0; i < ntokens; ++i) for (symbol_number i = 0; i < ntokens; ++i)
if (bitset_test (lookahead_tokens, i) if (bitset_test (lookaheads, i)
&& bitset_test (lookahead_set, i) && bitset_test (lookahead_set, i)
&& symbols[i]->content->prec) && symbols[i]->content->prec)
{ {
@@ -295,7 +295,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
{ {
register_precedence (i, redrule->prec->number); register_precedence (i, redrule->prec->number);
log_resolution (redrule, i, shift_resolution); log_resolution (redrule, i, shift_resolution);
flush_reduce (lookahead_tokens, i); flush_reduce (lookaheads, i);
} }
else else
/* Matching precedence levels. /* Matching precedence levels.
@@ -316,7 +316,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
case right_assoc: case right_assoc:
register_assoc (i, redrule->prec->number); register_assoc (i, redrule->prec->number);
log_resolution (redrule, i, right_resolution); log_resolution (redrule, i, right_resolution);
flush_reduce (lookahead_tokens, i); flush_reduce (lookaheads, i);
break; break;
case left_assoc: case left_assoc:
@@ -329,7 +329,7 @@ resolve_sr_conflict (state *s, int ruleno, symbol **errors, int *nerrs)
register_assoc (i, redrule->prec->number); register_assoc (i, redrule->prec->number);
log_resolution (redrule, i, nonassoc_resolution); log_resolution (redrule, i, nonassoc_resolution);
flush_shift (s, i); flush_shift (s, i);
flush_reduce (lookahead_tokens, i); flush_reduce (lookaheads, i);
/* Record an explicit error for this token. */ /* Record an explicit error for this token. */
errors[(*nerrs)++] = symbols[i]; errors[(*nerrs)++] = symbols[i];
break; break;
@@ -369,7 +369,7 @@ set_conflicts (state *s, symbol **errors)
for (int i = 0; i < reds->num; ++i) for (int i = 0; i < reds->num; ++i)
if (reds->rules[i]->prec if (reds->rules[i]->prec
&& reds->rules[i]->prec->prec && reds->rules[i]->prec->prec
&& !bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set)) && !bitset_disjoint_p (reds->lookaheads[i], lookahead_set))
resolve_sr_conflict (s, i, errors, &nerrs); resolve_sr_conflict (s, i, errors, &nerrs);
if (nerrs) if (nerrs)
@@ -385,13 +385,13 @@ set_conflicts (state *s, symbol **errors)
/* Loop over all rules which require lookahead in this state. Check /* Loop over all rules which require lookahead in this state. Check
for conflicts not resolved above. for conflicts not resolved above.
reds->lookahead_tokens can be NULL if the LR type is LR(0). */ reds->lookaheads can be NULL if the LR type is LR(0). */
if (reds->lookahead_tokens) if (reds->lookaheads)
for (int i = 0; i < reds->num; ++i) for (int i = 0; i < reds->num; ++i)
{ {
if (!bitset_disjoint_p (reds->lookahead_tokens[i], lookahead_set)) if (!bitset_disjoint_p (reds->lookaheads[i], lookahead_set))
conflicts[s->number] = true; conflicts[s->number] = true;
bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]); bitset_or (lookahead_set, lookahead_set, reds->lookaheads[i]);
} }
} }
@@ -460,7 +460,7 @@ count_state_sr_conflicts (const state *s)
} }
for (int i = 0; i < reds->num; ++i) for (int i = 0; i < reds->num; ++i)
bitset_or (lookahead_set, lookahead_set, reds->lookahead_tokens[i]); bitset_or (lookahead_set, lookahead_set, reds->lookaheads[i]);
bitset_and (lookahead_set, lookahead_set, shift_set); bitset_and (lookahead_set, lookahead_set, shift_set);
@@ -499,7 +499,7 @@ count_state_rr_conflicts (const state *s)
{ {
int count = 0; int count = 0;
for (int j = 0; j < reds->num; ++j) for (int j = 0; j < reds->num; ++j)
count += bitset_test (reds->lookahead_tokens[j], i); count += bitset_test (reds->lookaheads[j], i);
if (2 <= count) if (2 <= count)
res += count-1; res += count-1;
} }
@@ -534,7 +534,7 @@ count_rule_state_sr_conflicts (rule *r, state *s)
for (int i = 0; i < reds->num; ++i) for (int i = 0; i < reds->num; ++i)
if (reds->rules[i] == r) if (reds->rules[i] == r)
{ {
bitset lookaheads = reds->lookahead_tokens[i]; bitset lookaheads = reds->lookaheads[i];
int j; int j;
FOR_EACH_SHIFT (trans, j) FOR_EACH_SHIFT (trans, j)
res += bitset_test (lookaheads, TRANSITION_SYMBOL (trans, j)); res += bitset_test (lookaheads, TRANSITION_SYMBOL (trans, j));
@@ -576,8 +576,8 @@ count_rule_state_rr_conflicts (rule *r, state *s)
if (reds->rules[j] != r) if (reds->rules[j] != r)
{ {
bitset_and (lookaheads, bitset_and (lookaheads,
reds->lookahead_tokens[i], reds->lookaheads[i],
reds->lookahead_tokens[j]); reds->lookaheads[j]);
res += bitset_count (lookaheads); res += bitset_count (lookaheads);
} }
bitset_free (lookaheads); bitset_free (lookaheads);

View File

@@ -1286,7 +1286,7 @@ counterexample_report_state (const state *s, FILE *out, const char *prefix)
{ {
const state_number sn = s->number; const state_number sn = s->number;
const reductions *reds = s->reductions; const reductions *reds = s->reductions;
bitset lookahead_tokens = bitset_create (ntokens, BITSET_FIXED); bitset lookaheads = bitset_create (ntokens, BITSET_FIXED);
for (int i = 0; i < reds->num; ++i) for (int i = 0; i < reds->num; ++i)
{ {
const rule *r1 = reds->rules[i]; const rule *r1 = reds->rules[i];
@@ -1296,25 +1296,25 @@ counterexample_report_state (const state *s, FILE *out, const char *prefix)
{ {
item_number conf = *state_items[c2].item; item_number conf = *state_items[c2].item;
if (item_number_is_symbol_number (conf) if (item_number_is_symbol_number (conf)
&& bitset_test (reds->lookahead_tokens[i], conf)) && bitset_test (reds->lookaheads[i], conf))
counterexample_report_shift_reduce (c1, c2, conf, out, prefix); counterexample_report_shift_reduce (c1, c2, conf, out, prefix);
} }
for (int j = i+1; j < reds->num; ++j) for (int j = i+1; j < reds->num; ++j)
{ {
const rule *r2 = reds->rules[j]; const rule *r2 = reds->rules[j];
// Conflicts: common lookaheads. // Conflicts: common lookaheads.
bitset_intersection (lookahead_tokens, bitset_intersection (lookaheads,
reds->lookahead_tokens[i], reds->lookaheads[i],
reds->lookahead_tokens[j]); reds->lookaheads[j]);
if (!bitset_empty_p (lookahead_tokens)) if (!bitset_empty_p (lookaheads))
for (state_item_number c2 = state_item_map[sn]; c2 < state_item_map[sn + 1]; ++c2) for (state_item_number c2 = state_item_map[sn]; c2 < state_item_map[sn + 1]; ++c2)
if (!SI_DISABLED (c2) if (!SI_DISABLED (c2)
&& item_rule (state_items[c2].item) == r2) && item_rule (state_items[c2].item) == r2)
{ {
counterexample_report_reduce_reduce (c1, c2, lookahead_tokens, out, prefix); counterexample_report_reduce_reduce (c1, c2, lookaheads, out, prefix);
break; break;
} }
} }
} }
bitset_free (lookahead_tokens); bitset_free (lookaheads);
} }

View File

@@ -221,7 +221,7 @@ static const argmatch_report_arg argmatch_report_args[] =
{ "none", report_none }, { "none", report_none },
{ "states", report_states }, { "states", report_states },
{ "itemsets", report_states | report_itemsets }, { "itemsets", report_states | report_itemsets },
{ "lookaheads", report_states | report_lookahead_tokens }, { "lookaheads", report_states | report_lookaheads },
{ "solved", report_states | report_solved_conflicts }, { "solved", report_states | report_solved_conflicts },
{ "counterexamples", report_cex }, { "counterexamples", report_cex },
{ "cex", report_cex }, { "cex", report_cex },

View File

@@ -77,7 +77,7 @@ enum report
report_none = 0, report_none = 0,
report_states = 1 << 0, report_states = 1 << 0,
report_itemsets = 1 << 1, report_itemsets = 1 << 1,
report_lookahead_tokens = 1 << 2, report_lookaheads = 1 << 2,
report_solved_conflicts = 1 << 3, report_solved_conflicts = 1 << 3,
report_cex = 1 << 4, report_cex = 1 << 4,
report_all = ~0 report_all = ~0

View File

@@ -184,9 +184,9 @@ output_red (state const *s, reductions const *reds, FILE *fout)
bool firste = true; bool firste = true;
rule_number ruleno = reds->rules[j]->number; rule_number ruleno = reds->rules[j]->number;
if (reds->lookahead_tokens) if (reds->lookaheads)
for (int i = 0; i < ntokens; i++) for (int i = 0; i < ntokens; i++)
if (bitset_test (reds->lookahead_tokens[j], i)) if (bitset_test (reds->lookaheads[j], i))
{ {
if (bitset_test (no_reduce_set, i)) if (bitset_test (no_reduce_set, i))
firstd = print_token (&dout, firstd, symbols[i]->tag); firstd = print_token (&dout, firstd, symbols[i]->tag);

View File

@@ -1025,7 +1025,7 @@ ielr_split_states (bitsetv follow_kernel_items, bitsetv always_follows,
{ {
rule *this_rule = node->state->reductions->rules[r]; rule *this_rule = node->state->reductions->rules[r];
bitset lookahead_set = bitset lookahead_set =
node->state->reductions->lookahead_tokens[r]; node->state->reductions->lookaheads[r];
if (item_number_is_rule_number (*this_rule->rhs)) if (item_number_is_rule_number (*this_rule->rhs))
ielr_compute_goto_follow_set (follow_kernel_items, ielr_compute_goto_follow_set (follow_kernel_items,
always_follows, node, always_follows, node,

View File

@@ -256,9 +256,9 @@ lookback_find_state (int lookback_index)
state *res = NULL; state *res = NULL;
for (int j = 0; j < nstates; ++j) for (int j = 0; j < nstates; ++j)
if (states[j]->reductions if (states[j]->reductions
&& states[j]->reductions->lookahead_tokens) && states[j]->reductions->lookaheads)
{ {
if (states[j]->reductions->lookahead_tokens - LA > lookback_index) if (states[j]->reductions->lookaheads - LA > lookback_index)
/* Went too far. */ /* Went too far. */
break; break;
else else
@@ -280,7 +280,7 @@ lookback_print (FILE *out)
{ {
fprintf (out, " %3d = ", i); fprintf (out, " %3d = ", i);
const state *s = lookback_find_state (i); const state *s = lookback_find_state (i);
int rnum = i - (s->reductions->lookahead_tokens - LA); int rnum = i - (s->reductions->lookaheads - LA);
const rule *r = s->reductions->rules[rnum]; const rule *r = s->reductions->rules[rnum];
fprintf (out, "(%3d, ", s->number); fprintf (out, "(%3d, ", s->number);
rule_print (r, NULL, out); rule_print (r, NULL, out);
@@ -305,7 +305,7 @@ static void
add_lookback_edge (state *s, rule const *r, goto_number gotono) add_lookback_edge (state *s, rule const *r, goto_number gotono)
{ {
int ri = state_reduction_find (s, r); int ri = state_reduction_find (s, r);
int idx = (s->reductions->lookahead_tokens - LA) + ri; int idx = (s->reductions->lookaheads - LA) + ri;
lookback[idx] = goto_list_new (gotono, lookback[idx]); lookback[idx] = goto_list_new (gotono, lookback[idx]);
} }
@@ -421,7 +421,7 @@ compute_follows (void)
static void static void
compute_lookahead_tokens (void) compute_lookaheads (void)
{ {
if (trace_flag & trace_automaton) if (trace_flag & trace_automaton)
lookback_print (stderr); lookback_print (stderr);
@@ -437,13 +437,12 @@ compute_lookahead_tokens (void)
} }
/*----------------------------------------------------. /*------------------------------------------------------.
| Count the number of lookahead tokens required for S | | Count the number of lookahead tokens required for S. |
| (N_LOOKAHEAD_TOKENS member). | `------------------------------------------------------*/
`----------------------------------------------------*/
static int static int
state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept) state_lookaheads_count (state *s, bool default_reduction_only_for_accept)
{ {
const reductions *reds = s->reductions; const reductions *reds = s->reductions;
const transitions *trans = s->transitions; const transitions *trans = s->transitions;
@@ -473,9 +472,9 @@ state_lookahead_tokens_count (state *s, bool default_reduction_only_for_accept)
} }
/*----------------------------------------------------. /*----------------------------------------------.
| Compute LA, NLA, and the lookahead_tokens members. | | Compute LA, NLA, and the lookaheads members. |
`----------------------------------------------------*/ `----------------------------------------------*/
void void
initialize_LA (void) initialize_LA (void)
@@ -491,25 +490,23 @@ initialize_LA (void)
/* Compute the total number of reductions requiring a lookahead. */ /* Compute the total number of reductions requiring a lookahead. */
nLA = 0; nLA = 0;
for (state_number i = 0; i < nstates; ++i) for (state_number i = 0; i < nstates; ++i)
nLA += nLA += state_lookaheads_count (states[i],
state_lookahead_tokens_count (states[i], default_reduction_only_for_accept);
default_reduction_only_for_accept);
/* Avoid having to special case 0. */ /* Avoid having to special case 0. */
if (!nLA) if (!nLA)
nLA = 1; nLA = 1;
bitsetv pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED); bitsetv pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
/* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions /* Initialize the members LOOKAHEADS for each state whose reductions
require lookahead tokens. */ require lookahead tokens. */
for (state_number i = 0; i < nstates; ++i) for (state_number i = 0; i < nstates; ++i)
{ {
int count = int count = state_lookaheads_count (states[i],
state_lookahead_tokens_count (states[i], default_reduction_only_for_accept);
default_reduction_only_for_accept);
if (count) if (count)
{ {
states[i]->reductions->lookahead_tokens = pLA; states[i]->reductions->lookaheads = pLA;
pLA += count; pLA += count;
} }
} }
@@ -521,7 +518,7 @@ initialize_LA (void)
`---------------------------------------------*/ `---------------------------------------------*/
static void static void
lookahead_tokens_print (FILE *out) lookaheads_print (FILE *out)
{ {
fputs ("Lookaheads:\n", out); fputs ("Lookaheads:\n", out);
for (state_number i = 0; i < nstates; ++i) for (state_number i = 0; i < nstates; ++i)
@@ -533,11 +530,11 @@ lookahead_tokens_print (FILE *out)
for (int j = 0; j < reds->num; ++j) for (int j = 0; j < reds->num; ++j)
{ {
fprintf (out, " rule %d:", reds->rules[j]->number); fprintf (out, " rule %d:", reds->rules[j]->number);
if (reds->lookahead_tokens) if (reds->lookaheads)
{ {
bitset_iterator iter; bitset_iterator iter;
int k; int k;
BITSET_FOR_EACH (iter, reds->lookahead_tokens[j], k, 0) BITSET_FOR_EACH (iter, reds->lookaheads[j], k, 0)
fprintf (out, " %s", symbols[k]->tag); fprintf (out, " %s", symbols[k]->tag);
} }
fputc ('\n', out); fputc ('\n', out);
@@ -564,10 +561,10 @@ lalr (void)
lookback = xcalloc (nLA, sizeof *lookback); lookback = xcalloc (nLA, sizeof *lookback);
build_relations (); build_relations ();
compute_follows (); compute_follows ();
compute_lookahead_tokens (); compute_lookaheads ();
if (trace_flag & trace_sets) if (trace_flag & trace_sets)
lookahead_tokens_print (stderr); lookaheads_print (stderr);
if (trace_flag & trace_automaton) if (trace_flag & trace_automaton)
{ {
begin_use_class ("trace0", stderr); begin_use_class ("trace0", stderr);
@@ -614,6 +611,6 @@ void
lalr_free (void) lalr_free (void)
{ {
for (state_number s = 0; s < nstates; ++s) for (state_number s = 0; s < nstates; ++s)
states[s]->reductions->lookahead_tokens = NULL; states[s]->reductions->lookaheads = NULL;
bitsetv_free (LA); bitsetv_free (LA);
} }

View File

@@ -96,7 +96,7 @@ print_core (struct obstack *oout, state *s)
obstack_sgrow (oout, " %empty"); obstack_sgrow (oout, " %empty");
/* Experimental feature: display the lookahead tokens. */ /* Experimental feature: display the lookahead tokens. */
if (report_flag & report_lookahead_tokens if (report_flag & report_lookaheads
&& item_number_is_rule_number (*sp1)) && item_number_is_rule_number (*sp1))
{ {
/* Find the reduction we are handling. */ /* Find the reduction we are handling. */
@@ -104,13 +104,13 @@ print_core (struct obstack *oout, state *s)
int redno = state_reduction_find (s, r); int redno = state_reduction_find (s, r);
/* Print them if there are. */ /* Print them if there are. */
if (reds->lookahead_tokens && redno != -1) if (reds->lookaheads && redno != -1)
{ {
bitset_iterator biter; bitset_iterator biter;
int k; int k;
char const *sep = ""; char const *sep = "";
obstack_sgrow (oout, " ["); obstack_sgrow (oout, " [");
BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0) BITSET_FOR_EACH (biter, reds->lookaheads[redno], k, 0)
{ {
obstack_sgrow (oout, sep); obstack_sgrow (oout, sep);
obstack_backslash (oout, symbols[k]->tag); obstack_backslash (oout, symbols[k]->tag);

View File

@@ -86,12 +86,12 @@ print_core (FILE *out, int level, state *s)
reductions *reds = s->reductions; reductions *reds = s->reductions;
int red = state_reduction_find (s, r); int red = state_reduction_find (s, r);
/* Print item with lookaheads if there are. */ /* Print item with lookaheads if there are. */
if (reds->lookahead_tokens && red != -1) if (reds->lookaheads && red != -1)
{ {
xml_printf (out, level + 1, xml_printf (out, level + 1,
"<item rule-number=\"%d\" dot=\"%d\">", "<item rule-number=\"%d\" dot=\"%d\">",
r->number, sp1 - sp); r->number, sp1 - sp);
state_rule_lookahead_tokens_print_xml (s, r, state_rule_lookaheads_print_xml (s, r,
out, level + 2); out, level + 2);
xml_puts (out, level + 1, "</item>"); xml_puts (out, level + 1, "</item>");
printed = true; printed = true;
@@ -203,25 +203,25 @@ print_errs (FILE *out, int level, state *s)
/*-------------------------------------------------------------------------. /*-------------------------------------------------------------------------.
| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default'). | | Report a reduction of RULE on LOOKAHEAD (which can be 'default'). |
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and | | If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
| R/R conflicts). | | R/R conflicts). |
`-------------------------------------------------------------------------*/ `-------------------------------------------------------------------------*/
static void static void
print_reduction (FILE *out, int level, char const *lookahead_token, print_reduction (FILE *out, int level, char const *lookahead,
rule *r, bool enabled) rule *r, bool enabled)
{ {
if (r->number) if (r->number)
xml_printf (out, level, xml_printf (out, level,
"<reduction symbol=\"%s\" rule=\"%d\" enabled=\"%s\"/>", "<reduction symbol=\"%s\" rule=\"%d\" enabled=\"%s\"/>",
xml_escape (lookahead_token), xml_escape (lookahead),
r->number, r->number,
enabled ? "true" : "false"); enabled ? "true" : "false");
else else
xml_printf (out, level, xml_printf (out, level,
"<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>", "<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>",
xml_escape (lookahead_token), xml_escape (lookahead),
enabled ? "true" : "false"); enabled ? "true" : "false");
} }
@@ -258,13 +258,13 @@ print_reductions (FILE *out, int level, state *s)
if (default_reduction) if (default_reduction)
report = true; report = true;
if (reds->lookahead_tokens) if (reds->lookaheads)
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
{ {
bool count = bitset_test (no_reduce_set, i); bool count = bitset_test (no_reduce_set, i);
for (j = 0; j < reds->num; ++j) for (j = 0; j < reds->num; ++j)
if (bitset_test (reds->lookahead_tokens[j], i)) if (bitset_test (reds->lookaheads[j], i))
{ {
if (! count) if (! count)
{ {
@@ -289,14 +289,14 @@ print_reductions (FILE *out, int level, state *s)
xml_puts (out, level, "<reductions>"); xml_puts (out, level, "<reductions>");
/* Report lookahead tokens (or $default) and reductions. */ /* Report lookahead tokens (or $default) and reductions. */
if (reds->lookahead_tokens) if (reds->lookaheads)
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
{ {
bool defaulted = false; bool defaulted = false;
bool count = bitset_test (no_reduce_set, i); bool count = bitset_test (no_reduce_set, i);
for (j = 0; j < reds->num; ++j) for (j = 0; j < reds->num; ++j)
if (bitset_test (reds->lookahead_tokens[j], i)) if (bitset_test (reds->lookaheads[j], i))
{ {
if (! count) if (! count)
{ {

View File

@@ -90,9 +90,9 @@ print_core (FILE *out, const state *s)
previous_rule = r; previous_rule = r;
/* Display the lookahead tokens? */ /* Display the lookahead tokens? */
if (report_flag & report_lookahead_tokens if (report_flag & report_lookaheads
&& item_number_is_rule_number (*sp1)) && item_number_is_rule_number (*sp1))
state_rule_lookahead_tokens_print (s, r, out); state_rule_lookaheads_print (s, r, out);
fputc ('\n', out); fputc ('\n', out);
} }
} }
@@ -181,18 +181,18 @@ print_errs (FILE *out, const state *s)
/*-------------------------------------------------------------------------. /*-------------------------------------------------------------------------.
| Report a reduction of RULE on LOOKAHEAD_TOKEN (which can be 'default'). | | Report a reduction of RULE on LOOKAHEAD (which can be 'default'). |
| If not ENABLED, the rule is masked by a shift or a reduce (S/R and | | If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
| R/R conflicts). | | R/R conflicts). |
`-------------------------------------------------------------------------*/ `-------------------------------------------------------------------------*/
static void static void
print_reduction (FILE *out, size_t width, print_reduction (FILE *out, size_t width,
const char *lookahead_token, const char *lookahead,
rule *r, bool enabled) rule *r, bool enabled)
{ {
fprintf (out, " %s", lookahead_token); fprintf (out, " %s", lookahead);
for (int j = width - mbswidth (lookahead_token, 0); j > 0; --j) for (int j = width - mbswidth (lookahead, 0); j > 0; --j)
fputc (' ', out); fputc (' ', out);
if (!enabled) if (!enabled)
fputc ('[', out); fputc ('[', out);
@@ -239,13 +239,13 @@ print_reductions (FILE *out, const state *s)
if (default_reduction) if (default_reduction)
width = mbswidth (_("$default"), 0); width = mbswidth (_("$default"), 0);
if (reds->lookahead_tokens) if (reds->lookaheads)
for (int i = 0; i < ntokens; i++) for (int i = 0; i < ntokens; i++)
{ {
bool count = bitset_test (no_reduce_set, i); bool count = bitset_test (no_reduce_set, i);
for (int j = 0; j < reds->num; ++j) for (int j = 0; j < reds->num; ++j)
if (bitset_test (reds->lookahead_tokens[j], i)) if (bitset_test (reds->lookaheads[j], i))
{ {
if (! count) if (! count)
{ {
@@ -268,7 +268,7 @@ print_reductions (FILE *out, const state *s)
bool default_reduction_only = true; bool default_reduction_only = true;
/* Report lookahead tokens (or $default) and reductions. */ /* Report lookahead tokens (or $default) and reductions. */
if (reds->lookahead_tokens) if (reds->lookaheads)
for (int i = 0; i < ntokens; i++) for (int i = 0; i < ntokens; i++)
{ {
bool defaulted = false; bool defaulted = false;
@@ -277,7 +277,7 @@ print_reductions (FILE *out, const state *s)
default_reduction_only = false; default_reduction_only = false;
for (int j = 0; j < reds->num; ++j) for (int j = 0; j < reds->num; ++j)
if (bitset_test (reds->lookahead_tokens[j], i)) if (bitset_test (reds->lookaheads[j], i))
{ {
if (! count) if (! count)
{ {

View File

@@ -150,7 +150,7 @@ init_state_items (void)
++rule_search_idx; ++rule_search_idx;
if (rule_search_idx < red->num && r == red->rules[rule_search_idx]) if (rule_search_idx < red->num && r == red->rules[rule_search_idx])
{ {
bitsetv lookahead = red->lookahead_tokens; bitsetv lookahead = red->lookaheads;
if (lookahead) if (lookahead)
si->lookahead = lookahead[rule_search_idx]; si->lookahead = lookahead[rule_search_idx];
} }
@@ -163,7 +163,7 @@ init_state_items (void)
state_item_set (sidx, s, off); state_item_set (sidx, s, off);
if (item_number_is_rule_number (ritem[off])) if (item_number_is_rule_number (ritem[off]))
{ {
bitsetv lookahead = red->lookahead_tokens; bitsetv lookahead = red->lookaheads;
if (lookahead) if (lookahead)
state_items[sidx].lookahead = lookahead[rule_search_idx]; state_items[sidx].lookahead = lookahead[rule_search_idx];
++rule_search_idx; ++rule_search_idx;

View File

@@ -101,7 +101,7 @@ reductions_new (int num, rule **reds)
size_t rules_size = num * sizeof *reds; size_t rules_size = num * sizeof *reds;
reductions *res = xmalloc (offsetof (reductions, rules) + rules_size); reductions *res = xmalloc (offsetof (reductions, rules) + rules_size);
res->num = num; res->num = num;
res->lookahead_tokens = NULL; res->lookaheads = NULL;
memcpy (res->rules, reds, rules_size); memcpy (res->rules, reds, rules_size);
return res; return res;
} }
@@ -260,20 +260,20 @@ state_errs_set (state *s, int num, symbol **tokens)
`--------------------------------------------------*/ `--------------------------------------------------*/
void void
state_rule_lookahead_tokens_print (state const *s, rule const *r, FILE *out) state_rule_lookaheads_print (state const *s, rule const *r, FILE *out)
{ {
/* Find the reduction we are handling. */ /* Find the reduction we are handling. */
reductions *reds = s->reductions; reductions *reds = s->reductions;
int red = state_reduction_find (s, r); int red = state_reduction_find (s, r);
/* Print them if there are. */ /* Print them if there are. */
if (reds->lookahead_tokens && red != -1) if (reds->lookaheads && red != -1)
{ {
bitset_iterator biter; bitset_iterator biter;
int k; int k;
char const *sep = ""; char const *sep = "";
fprintf (out, " ["); fprintf (out, " [");
BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0) BITSET_FOR_EACH (biter, reds->lookaheads[red], k, 0)
{ {
fprintf (out, "%s%s", sep, symbols[k]->tag); fprintf (out, "%s%s", sep, symbols[k]->tag);
sep = ", "; sep = ", ";
@@ -283,7 +283,7 @@ state_rule_lookahead_tokens_print (state const *s, rule const *r, FILE *out)
} }
void void
state_rule_lookahead_tokens_print_xml (state const *s, rule const *r, state_rule_lookaheads_print_xml (state const *s, rule const *r,
FILE *out, int level) FILE *out, int level)
{ {
/* Find the reduction we are handling. */ /* Find the reduction we are handling. */
@@ -291,12 +291,12 @@ state_rule_lookahead_tokens_print_xml (state const *s, rule const *r,
int red = state_reduction_find (s, r); int red = state_reduction_find (s, r);
/* Print them if there are. */ /* Print them if there are. */
if (reds->lookahead_tokens && red != -1) if (reds->lookaheads && red != -1)
{ {
bitset_iterator biter; bitset_iterator biter;
int k; int k;
xml_puts (out, level, "<lookaheads>"); xml_puts (out, level, "<lookaheads>");
BITSET_FOR_EACH (biter, reds->lookahead_tokens[red], k, 0) BITSET_FOR_EACH (biter, reds->lookaheads[red], k, 0)
{ {
xml_printf (out, level + 1, "<symbol>%s</symbol>", xml_printf (out, level + 1, "<symbol>%s</symbol>",
xml_escape (symbols[k]->tag)); xml_escape (symbols[k]->tag));

View File

@@ -62,7 +62,7 @@
Each reductions structure describes the possible reductions at the Each reductions structure describes the possible reductions at the
state whose number is in the number field. rules is an array of state whose number is in the number field. rules is an array of
num rules. lookahead_tokens is an array of bitsets, one per rule. num rules. lookaheads is an array of bitsets, one per rule.
Conflict resolution can decide that certain tokens in certain Conflict resolution can decide that certain tokens in certain
states should explicitly be errors (for implementing %nonassoc). states should explicitly be errors (for implementing %nonassoc).
@@ -187,7 +187,7 @@ errs *errs_new (int num, symbol **tokens);
typedef struct typedef struct
{ {
int num; int num;
bitset *lookahead_tokens; bitset *lookaheads;
/* Sorted ascendingly on rule number. */ /* Sorted ascendingly on rule number. */
rule *rules[1]; rule *rules[1];
} reductions; } reductions;
@@ -254,9 +254,9 @@ void state_errs_set (state *s, int num, symbol **errors);
/* Print on OUT all the lookahead tokens such that this STATE wants to /* Print on OUT all the lookahead tokens such that this STATE wants to
reduce R. */ reduce R. */
void state_rule_lookahead_tokens_print (state const *s, rule const *r, FILE *out); void state_rule_lookaheads_print (state const *s, rule const *r, FILE *out);
void state_rule_lookahead_tokens_print_xml (state const *s, rule const *r, void state_rule_lookaheads_print_xml (state const *s, rule const *r,
FILE *out, int level); FILE *out, int level);
/* Create/destroy the states hash table. */ /* Create/destroy the states hash table. */
void state_hash_new (void); void state_hash_new (void);

View File

@@ -200,7 +200,7 @@ conflict_row (state *s)
/* Find all reductions for token J, and record all that do not /* Find all reductions for token J, and record all that do not
match ACTROW[J]. */ match ACTROW[J]. */
for (int i = 0; i < reds->num; i += 1) for (int i = 0; i < reds->num; i += 1)
if (bitset_test (reds->lookahead_tokens[i], j) if (bitset_test (reds->lookaheads[i], j)
&& (actrow[j] && (actrow[j]
!= rule_number_as_item_number (reds->rules[i]->number))) != rule_number_as_item_number (reds->rules[i]->number)))
{ {
@@ -247,7 +247,7 @@ action_row (state *s)
reductions *reds = s->reductions; reductions *reds = s->reductions;
bool conflicted = false; bool conflicted = false;
if (reds->lookahead_tokens) if (reds->lookaheads)
/* loop over all the rules available here which require /* loop over all the rules available here which require
lookahead (in reverse order to give precedence to the first lookahead (in reverse order to give precedence to the first
rule) */ rule) */
@@ -257,7 +257,7 @@ action_row (state *s)
{ {
bitset_iterator biter; bitset_iterator biter;
int j; int j;
BITSET_FOR_EACH (biter, reds->lookahead_tokens[i], j, 0) BITSET_FOR_EACH (biter, reds->lookaheads[i], j, 0)
{ {
/* and record this rule as the rule to use if that /* and record this rule as the rule to use if that
token follows. */ token follows. */
@@ -308,7 +308,7 @@ action_row (state *s)
} }
/* Turn off default reductions where requested by the user. See /* Turn off default reductions where requested by the user. See
state_lookahead_tokens_count in lalr.c to understand when states are state_lookaheads_count in lalr.c to understand when states are
labeled as consistent. */ labeled as consistent. */
{ {
char *default_reductions = char *default_reductions =

View File

@@ -283,11 +283,11 @@ m4_popdef([AT_TEST])
## Many lookahead tokens. ## ## Many lookahead tokens. ##
## ------------------------ ## ## ------------------------ ##
# AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR(FILE-NAME, SIZE) # AT_DATA_LOOKAHEADS_GRAMMAR(FILE-NAME, SIZE)
# -------------------------------------------------- # -------------------------------------------
# Create FILE-NAME, containing a self checking parser for a grammar # Create FILE-NAME, containing a self checking parser for a grammar
# requiring SIZE lookahead tokens. # requiring SIZE lookahead tokens.
m4_define([AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR], m4_define([AT_DATA_LOOKAHEADS_GRAMMAR],
[AT_BISON_OPTION_PUSHDEFS [AT_BISON_OPTION_PUSHDEFS
AT_DATA([[gengram.pl]], AT_DATA([[gengram.pl]],
[[#! /usr/bin/perl -w [[#! /usr/bin/perl -w
@@ -384,7 +384,7 @@ AT_BISON_OPTION_POPDEFS
AT_SETUP([Many lookahead tokens]) AT_SETUP([Many lookahead tokens])
AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR([input.y], [1000]) AT_DATA_LOOKAHEADS_GRAMMAR([input.y], [1000])
# GNU m4 requires about 70 MiB for this test on a 32-bit host. # GNU m4 requires about 70 MiB for this test on a 32-bit host.
# Ask for 200 MiB, which should be plenty even on a 64-bit host. # Ask for 200 MiB, which should be plenty even on a 64-bit host.