+/*----------------------------------------------------.
+| Compute LA, NLA, and the lookahead_tokens members. |
+`----------------------------------------------------*/
+
+static void
+initialize_LA (void)
+{
+ state_number i;
+ bitsetv pLA;
+
+ /* Compute the total number of reductions requiring a lookahead. */
+ nLA = 0;
+ for (i = 0; i < nstates; i++)
+ nLA += state_lookahead_tokens_count (states[i]);
+ /* Avoid having to special case 0. */
+ if (!nLA)
+ nLA = 1;
+
+ pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
+ lookback = xcalloc (nLA, sizeof *lookback);
+
+ /* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions
+ require lookahead tokens. */
+ for (i = 0; i < nstates; i++)
+ {
+ int count = state_lookahead_tokens_count (states[i]);
+ if (count)
+ {
+ states[i]->reductions->lookahead_tokens = pLA;
+ pLA += count;
+ }
+ }
+}
+
+
+/*---------------------------------------------.
+| Output the lookahead tokens for each state. |
+`---------------------------------------------*/
+
+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)
+ {
+ reductions *reds = states[i]->reductions;
+ bitset_iterator iter;
+ int n_lookahead_tokens = 0;
+
+ if (reds->lookahead_tokens)
+ for (k = 0; k < reds->num; ++k)
+ if (reds->lookahead_tokens[k])
+ ++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);
+ };
+ }
+ fprintf (out, "Lookahead tokens: END\n");
+}
+