342 |
in the map means it was useless and is being eliminated. */ |
in the map means it was useless and is being eliminated. */ |
343 |
|
|
344 |
short *nontermmap = XCALLOC (short, nvars) - ntokens; |
short *nontermmap = XCALLOC (short, nvars) - ntokens; |
|
for (i = ntokens; i < nsyms; i++) |
|
|
nontermmap[i] = -1; |
|
|
|
|
345 |
n = ntokens; |
n = ntokens; |
346 |
for (i = ntokens; i < nsyms; i++) |
for (i = ntokens; i < nsyms; i++) |
347 |
if (BITISSET (V, i)) |
if (BITISSET (V, i)) |
348 |
nontermmap[i] = n++; |
nontermmap[i] = n++; |
349 |
|
for (i = ntokens; i < nsyms; i++) |
350 |
|
if (!BITISSET (V, i)) |
351 |
|
nontermmap[i] = n++; |
352 |
|
|
|
/* Shuffle elements of tables indexed by symbol number. */ |
|
353 |
|
|
354 |
for (i = ntokens; i < nsyms; i++) |
/* Shuffle elements of tables indexed by symbol number. */ |
355 |
{ |
{ |
356 |
n = nontermmap[i]; |
short *sassoc_sorted = XMALLOC (short, nvars) - ntokens; |
357 |
if (n >= 0) |
short *sprec_sorted = XMALLOC (short, nvars) - ntokens; |
358 |
{ |
char **tags_sorted = XMALLOC (char *, nvars) - ntokens; |
359 |
sassoc[n] = sassoc[i]; |
|
360 |
sprec[n] = sprec[i]; |
for (i = ntokens; i < nsyms; i++) |
361 |
tags[n] = tags[i]; |
{ |
362 |
} |
n = nontermmap[i]; |
363 |
} |
sassoc_sorted[n] = sassoc[i]; |
364 |
|
sprec_sorted[n] = sprec[i]; |
365 |
|
tags_sorted[n] = tags[i]; |
366 |
|
} |
367 |
|
for (i = ntokens; i < nsyms; i++) |
368 |
|
{ |
369 |
|
sassoc[i] = sassoc_sorted[i]; |
370 |
|
sprec[i] = sprec_sorted[i]; |
371 |
|
tags[i] = tags_sorted[i]; |
372 |
|
} |
373 |
|
free (sassoc_sorted + ntokens); |
374 |
|
free (sprec_sorted + ntokens); |
375 |
|
free (tags_sorted + ntokens); |
376 |
|
} |
377 |
|
|
378 |
/* Replace all symbol numbers in valid data structures. */ |
/* Replace all symbol numbers in valid data structures. */ |
379 |
|
|
415 |
{ |
{ |
416 |
fprintf (out, _("Useless nonterminals:")); |
fprintf (out, _("Useless nonterminals:")); |
417 |
fprintf (out, "\n\n"); |
fprintf (out, "\n\n"); |
418 |
for (i = ntokens; i < nsyms; i++) |
for (i = 0; i < nuseless_nonterminals; ++i) |
419 |
if (!BITISSET (V, i)) |
fprintf (out, " %s\n", tags[nsyms + i]); |
|
fprintf (out, " %s\n", tags[i]); |
|
420 |
} |
} |
421 |
b = FALSE; |
b = FALSE; |
422 |
for (i = 0; i < ntokens; i++) |
for (i = 0; i < ntokens; i++) |