pci: don't do sanity check for missing pci bus, the check can misfire.
[minix.git] / commands / byacc / closure.c
blob7c8f9579154c8a1147b11e8c51481619c8328b77
1 #include "defs.h"
3 short *itemset;
4 short *itemsetend;
5 unsigned *ruleset;
7 static unsigned *first_derives;
8 static unsigned *EFF;
11 set_EFF()
13 register unsigned *row;
14 register int symbol;
15 register short *sp;
16 register int rowsize;
17 register int i;
18 register int rule;
20 rowsize = WORDSIZE(nvars);
21 EFF = NEW2(nvars * rowsize, unsigned);
23 row = EFF;
24 for (i = start_symbol; i < nsyms; i++)
26 sp = derives[i];
27 for (rule = *sp; rule > 0; rule = *++sp)
29 symbol = ritem[rrhs[rule]];
30 if (ISVAR(symbol))
32 symbol -= start_symbol;
33 SETBIT(row, symbol);
36 row += rowsize;
39 reflexive_transitive_closure(EFF, nvars);
41 #ifdef DEBUG
42 print_EFF();
43 #endif
47 set_first_derives()
49 register unsigned *rrow;
50 register unsigned *vrow;
51 register int j;
52 register unsigned k;
53 register unsigned cword;
54 register short *rp;
56 int rule;
57 int i;
58 int rulesetsize;
59 int varsetsize;
61 rulesetsize = WORDSIZE(nrules);
62 varsetsize = WORDSIZE(nvars);
63 first_derives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
65 set_EFF();
67 rrow = first_derives + ntokens * rulesetsize;
68 for (i = start_symbol; i < nsyms; i++)
70 vrow = EFF + ((i - ntokens) * varsetsize);
71 k = BITS_PER_WORD;
72 for (j = start_symbol; j < nsyms; k++, j++)
74 if (k >= BITS_PER_WORD)
76 cword = *vrow++;
77 k = 0;
80 if (cword & (1 << k))
82 rp = derives[j];
83 while ((rule = *rp++) >= 0)
85 SETBIT(rrow, rule);
90 vrow += varsetsize;
91 rrow += rulesetsize;
94 #ifdef DEBUG
95 print_first_derives();
96 #endif
98 FREE(EFF);
102 closure(nucleus, n)
103 short *nucleus;
104 int n;
106 register int ruleno;
107 register unsigned word;
108 register unsigned i;
109 register short *csp;
110 register unsigned *dsp;
111 register unsigned *rsp;
112 register int rulesetsize;
114 short *csend;
115 unsigned *rsend;
116 int symbol;
117 int itemno;
119 rulesetsize = WORDSIZE(nrules);
120 rsp = ruleset;
121 rsend = ruleset + rulesetsize;
122 for (rsp = ruleset; rsp < rsend; rsp++)
123 *rsp = 0;
125 csend = nucleus + n;
126 for (csp = nucleus; csp < csend; ++csp)
128 symbol = ritem[*csp];
129 if (ISVAR(symbol))
131 dsp = first_derives + symbol * rulesetsize;
132 rsp = ruleset;
133 while (rsp < rsend)
134 *rsp++ |= *dsp++;
138 ruleno = 0;
139 itemsetend = itemset;
140 csp = nucleus;
141 for (rsp = ruleset; rsp < rsend; ++rsp)
143 word = *rsp;
144 if (word)
146 for (i = 0; i < BITS_PER_WORD; ++i)
148 if (word & (1 << i))
150 itemno = rrhs[ruleno+i];
151 while (csp < csend && *csp < itemno)
152 *itemsetend++ = *csp++;
153 *itemsetend++ = itemno;
154 while (csp < csend && *csp == itemno)
155 ++csp;
159 ruleno += BITS_PER_WORD;
162 while (csp < csend)
163 *itemsetend++ = *csp++;
165 #ifdef DEBUG
166 print_closure(n);
167 #endif
172 finalize_closure()
174 FREE(itemset);
175 FREE(ruleset);
176 FREE(first_derives + ntokens * WORDSIZE(nrules));
180 #ifdef DEBUG
182 print_closure(n)
183 int n;
185 register short *isp;
187 printf("\n\nn = %d\n\n", n);
188 for (isp = itemset; isp < itemsetend; isp++)
189 printf(" %d\n", *isp);
193 print_EFF()
195 register int i, j;
196 register unsigned *rowp;
197 register unsigned word;
198 register unsigned k;
200 printf("\n\nEpsilon Free Firsts\n");
202 for (i = start_symbol; i < nsyms; i++)
204 printf("\n%s", symbol_name[i]);
205 rowp = EFF + ((i - start_symbol) * WORDSIZE(nvars));
206 word = *rowp++;
208 k = BITS_PER_WORD;
209 for (j = 0; j < nvars; k++, j++)
211 if (k >= BITS_PER_WORD)
213 word = *rowp++;
214 k = 0;
217 if (word & (1 << k))
218 printf(" %s", symbol_name[start_symbol + j]);
224 print_first_derives()
226 register int i;
227 register int j;
228 register unsigned *rp;
229 register unsigned cword;
230 register unsigned k;
232 printf("\n\n\nFirst Derives\n");
234 for (i = start_symbol; i < nsyms; i++)
236 printf("\n%s derives\n", symbol_name[i]);
237 rp = first_derives + i * WORDSIZE(nrules);
238 k = BITS_PER_WORD;
239 for (j = 0; j <= nrules; k++, j++)
241 if (k >= BITS_PER_WORD)
243 cword = *rp++;
244 k = 0;
247 if (cword & (1 << k))
248 printf(" %d\n", j);
252 fflush(stdout);
255 #endif