211 |
|
} |
212 |
|
|
213 |
|
|
214 |
< |
void |
214 |
> |
static void |
215 |
|
epflatten( /* flatten hierarchies for '+', '*' */ |
216 |
|
EPNODE *epar |
217 |
|
) |
218 |
|
{ |
219 |
|
EPNODE *ep; |
220 |
|
|
221 |
< |
if (epar->nkids < 0) /* don't really handle this properly */ |
222 |
< |
epar->nkids *= -1; |
223 |
< |
|
221 |
> |
if (epar->nkids < 0) { |
222 |
> |
eputs("Cannot flatten EPNODE array\n"); |
223 |
> |
quit(1); |
224 |
> |
} |
225 |
|
for (ep = epar->v.kid; ep != NULL; ep = ep->sibling) |
226 |
|
while (ep->type == epar->type) { |
227 |
|
EPNODE *ep1 = ep->v.kid; |
237 |
|
|
238 |
|
|
239 |
|
void |
240 |
< |
epoptimize( /* flatten operations and lists -> arrays */ |
240 |
> |
epoptimize( /* flatten operations, lists -> arrays */ |
241 |
|
EPNODE *epar |
242 |
|
) |
243 |
|
{ |
244 |
|
EPNODE *ep; |
245 |
|
|
246 |
< |
if ((epar->type == '+') | (epar->type == '*')) |
247 |
< |
epflatten(epar); /* commutative & associative */ |
246 |
> |
if ((epar->type == '+') | (epar->type == '*')) |
247 |
> |
epflatten(epar); /* flatten associative operations */ |
248 |
|
|
249 |
< |
if (epar->nkids) /* do children if any */ |
249 |
> |
if (epar->nkids) /* do children if any */ |
250 |
|
for (ep = epar->v.kid; ep != NULL; ep = ep->sibling) |
251 |
|
epoptimize(ep); |
252 |
|
|
350 |
|
EPNODE *ep2 = ep1->sibling; |
351 |
|
double d; |
352 |
|
|
353 |
< |
d = envalue(ep2); |
353 |
> |
d = evalue(ep2); |
354 |
|
if (d == 0.0) { |
355 |
|
wputs("Division by zero\n"); |
356 |
|
errno = ERANGE; |
563 |
|
EPNODE *ek |
564 |
|
) |
565 |
|
{ |
566 |
< |
if (ep->nkids < 0) /* we don't really handle this properly */ |
567 |
< |
ep->nkids *= -1; |
566 |
> |
if (ep->nkids < 0) { |
567 |
> |
eputs("Cannot add kid to EPNODE array\n"); |
568 |
> |
quit(1); |
569 |
> |
} |
570 |
|
ep->nkids++; |
571 |
|
if (ep->v.kid == NULL) |
572 |
|
ep->v.kid = ek; |