- register int i;
- register int mask;
- register unsigned *fp1;
- register unsigned *fp2;
- register int redprec;
- errs *errp = (errs *) xmalloc (sizeof(errs) + ntokens * sizeof(short));
- short *errtokens = errp->errs;
-
- /* find the rule to reduce by to get precedence of reduction */
- redprec = rprec[LAruleno[lookaheadnum]];
-
- mask = 1;
- fp1 = LA + lookaheadnum * tokensetsize;
- fp2 = lookaheadset;
- for (i = 0; i < ntokens; i++)
- {
- if ((mask & *fp2 & *fp1) && sprec[i])
- /* Shift-reduce conflict occurs for token number i
- and it has a precedence.
- The precedence of shifting is that of token i. */
- {
- if (sprec[i] < redprec)
- {
- if (verboseflag) log_resolution(state, lookaheadnum, i, _("reduce"));
- *fp2 &= ~mask; /* flush the shift for this token */
- flush_shift(state, i);
- }
- else if (sprec[i] > redprec)
- {
- if (verboseflag) log_resolution(state, lookaheadnum, i, _("shift"));
- *fp1 &= ~mask; /* flush the reduce for this token */
- }
- else
- {
- /* Matching precedence levels.
- For left association, keep only the reduction.
- For right association, keep only the shift.
- For nonassociation, keep neither. */
-
- switch (sassoc[i])
- {
-
- case RIGHT_ASSOC:
- if (verboseflag) log_resolution(state, lookaheadnum, i, _("shift"));
- break;
-
- case LEFT_ASSOC:
- if (verboseflag) log_resolution(state, lookaheadnum, i, _("reduce"));
- break;
-
- case NON_ASSOC:
- if (verboseflag) log_resolution(state, lookaheadnum, i, _("an error"));
- break;
- }
-
- if (sassoc[i] != RIGHT_ASSOC)
- {
- *fp2 &= ~mask; /* flush the shift for this token */
- flush_shift(state, i);
- }
- if (sassoc[i] != LEFT_ASSOC)
- {
- *fp1 &= ~mask; /* flush the reduce for this token */
- }
- if (sassoc[i] == NON_ASSOC)
- {
- /* Record an explicit error for this token. */
- *errtokens++ = i;
- }
- }
- }
-
- mask <<= 1;
- if (mask == 0)
- {
- mask = 1;
- fp2++; fp1++;
- }
- }
- errp->nerrs = errtokens - errp->errs;
- if (errp->nerrs)
- {
- /* Some tokens have been explicitly made errors. Allocate
- a permanent errs structure for this state, to record them. */
- i = (char *) errtokens - (char *) errp;
- err_table[state] = (errs *) xmalloc ((unsigned int)i);
- bcopy (errp, err_table[state], i);
- }
- else
- err_table[state] = 0;
- free(errp);