| 218 |
|
EPNODE *epar |
| 219 |
|
) |
| 220 |
|
{ |
| 221 |
< |
EPNODE *ep; |
| 221 |
> |
EPNODE *ep, *ep1; |
| 222 |
> |
double combined; |
| 223 |
|
|
| 224 |
< |
if (epar->nkids < 0) /* can't handle array allocations */ |
| 224 |
> |
if (epar->nkids <= 0) /* can't handle array allocations */ |
| 225 |
|
return; |
| 226 |
|
|
| 227 |
|
for (ep = epar->v.kid; ep != NULL; ep = ep->sibling) |
| 228 |
< |
while (ep->type == epar->type && ep->nkids > 0) { |
| 229 |
< |
EPNODE *ep1 = ep->v.kid; |
| 228 |
> |
while ((ep->type == epar->type) & (ep->nkids > 0)) { |
| 229 |
> |
ep1 = ep->v.kid; |
| 230 |
|
while (ep1->sibling != NULL) |
| 231 |
|
ep1 = ep1->sibling; |
| 232 |
|
ep1->sibling = ep->sibling; |
| 235 |
|
*ep = *ep1; |
| 236 |
|
efree(ep1); /* not epfree()! */ |
| 237 |
|
} |
| 238 |
+ |
if ((epar->nkids <= 2) | !(esupport & E_RCONST)) |
| 239 |
+ |
return; |
| 240 |
+ |
ep1 = NULL; /* combine constants in sum/product */ |
| 241 |
+ |
for (ep = epar->v.kid; ep != NULL; ep = ep->sibling) |
| 242 |
+ |
if (ep->type == NUM) { |
| 243 |
+ |
if (ep1 == NULL) combined = (ep1 = ep)->v.num; |
| 244 |
+ |
else if (epar->type == '+') combined += ep->v.num; |
| 245 |
+ |
else /* epar->type=='*' */ combined *= ep->v.num; |
| 246 |
+ |
} |
| 247 |
+ |
if (ep1 == NULL) |
| 248 |
+ |
return; |
| 249 |
+ |
ep1->v.num = combined; /* drop following constants */ |
| 250 |
+ |
while (ep1->sibling != NULL) |
| 251 |
+ |
if (ep1->sibling->type == NUM) { |
| 252 |
+ |
ep = ep1->sibling; |
| 253 |
+ |
ep1->sibling = ep->sibling; |
| 254 |
+ |
efree(ep); |
| 255 |
+ |
} else |
| 256 |
+ |
ep1 = ep1->sibling; |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
|