57 |
static void |
static void |
58 |
flush_shift (int state, int token) |
flush_shift (int state, int token) |
59 |
{ |
{ |
60 |
shifts *shiftp; |
shifts *shiftp = state_table[state].shift_table; |
61 |
int k, i; |
int i; |
|
|
|
|
shiftp = state_table[state].shift_table; |
|
62 |
|
|
63 |
if (shiftp) |
if (shiftp) |
64 |
{ |
for (i = 0; i < shiftp->nshifts; i++) |
65 |
k = shiftp->nshifts; |
if (shiftp->shifts[i] && SHIFT_SYMBOL (shiftp, i) == token) |
66 |
for (i = 0; i < k; i++) |
shiftp->shifts[i] = 0; |
|
{ |
|
|
if (shiftp->shifts[i] |
|
|
&& token == state_table[shiftp->shifts[i]].accessing_symbol) |
|
|
(shiftp->shifts[i]) = 0; |
|
|
} |
|
|
} |
|
67 |
} |
} |
68 |
|
|
69 |
|
|
78 |
resolve_sr_conflict (int state, int lookaheadnum) |
resolve_sr_conflict (int state, int lookaheadnum) |
79 |
{ |
{ |
80 |
int i; |
int i; |
81 |
int mask; |
/* find the rule to reduce by to get precedence of reduction */ |
82 |
unsigned *fp1; |
int redprec = rule_table[LAruleno[lookaheadnum]].prec; |
|
unsigned *fp2; |
|
|
int redprec; |
|
83 |
errs *errp = ERRS_ALLOC (ntokens + 1); |
errs *errp = ERRS_ALLOC (ntokens + 1); |
84 |
short *errtokens = errp->errs; |
short *errtokens = errp->errs; |
85 |
|
|
|
/* find the rule to reduce by to get precedence of reduction */ |
|
|
redprec = rule_table[LAruleno[lookaheadnum]].prec; |
|
|
|
|
|
mask = 1; |
|
|
fp1 = LA (lookaheadnum); |
|
|
fp2 = lookaheadset; |
|
86 |
for (i = 0; i < ntokens; i++) |
for (i = 0; i < ntokens; i++) |
87 |
{ |
{ |
88 |
if ((mask & *fp2 & *fp1) && sprec[i]) |
if (BITISSET (LA (lookaheadnum), i) |
89 |
|
&& BITISSET (lookaheadset, i) |
90 |
|
&& sprec[i]) |
91 |
/* Shift-reduce conflict occurs for token number i |
/* Shift-reduce conflict occurs for token number i |
92 |
and it has a precedence. |
and it has a precedence. |
93 |
The precedence of shifting is that of token i. */ |
The precedence of shifting is that of token i. */ |
95 |
if (sprec[i] < redprec) |
if (sprec[i] < redprec) |
96 |
{ |
{ |
97 |
log_resolution (state, lookaheadnum, i, _("reduce")); |
log_resolution (state, lookaheadnum, i, _("reduce")); |
98 |
*fp2 &= ~mask; /* flush the shift for this token */ |
/* flush the shift for this token */ |
99 |
|
RESETBIT (lookaheadset, i); |
100 |
flush_shift (state, i); |
flush_shift (state, i); |
101 |
} |
} |
102 |
else if (sprec[i] > redprec) |
else if (sprec[i] > redprec) |
103 |
{ |
{ |
104 |
log_resolution (state, lookaheadnum, i, _("shift")); |
log_resolution (state, lookaheadnum, i, _("shift")); |
105 |
*fp1 &= ~mask; /* flush the reduce for this token */ |
/* flush the reduce for this token */ |
106 |
|
RESETBIT (LA (lookaheadnum), i); |
107 |
} |
} |
108 |
else |
else |
109 |
{ |
{ |
129 |
|
|
130 |
if (sassoc[i] != right_assoc) |
if (sassoc[i] != right_assoc) |
131 |
{ |
{ |
132 |
*fp2 &= ~mask; /* flush the shift for this token */ |
/* flush the shift for this token */ |
133 |
|
RESETBIT (lookaheadset, i); |
134 |
flush_shift (state, i); |
flush_shift (state, i); |
135 |
} |
} |
136 |
if (sassoc[i] != left_assoc) |
if (sassoc[i] != left_assoc) |
137 |
{ |
{ |
138 |
*fp1 &= ~mask; /* flush the reduce for this token */ |
/* flush the reduce for this token */ |
139 |
|
RESETBIT (LA (lookaheadnum), i); |
140 |
} |
} |
141 |
if (sassoc[i] == non_assoc) |
if (sassoc[i] == non_assoc) |
142 |
{ |
{ |
145 |
} |
} |
146 |
} |
} |
147 |
} |
} |
|
|
|
|
mask <<= 1; |
|
|
if (mask == 0) |
|
|
{ |
|
|
mask = 1; |
|
|
fp2++; |
|
|
fp1++; |
|
|
} |
|
148 |
} |
} |
149 |
errp->nerrs = errtokens - errp->errs; |
errp->nerrs = errtokens - errp->errs; |
150 |
if (errp->nerrs) |
if (errp->nerrs) |