--- ray/src/common/calexpr.c 1992/09/21 12:01:54 2.6 +++ ray/src/common/calexpr.c 1995/02/16 09:49:29 2.16 @@ -24,6 +24,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#include + #include "calcomp.h" #define MAXLINE 256 /* maximum line length */ @@ -32,18 +34,21 @@ static char SCCSid[] = "$SunId$ LBL"; #define isdecimal(c) (isdigit(c) || (c) == '.') -#ifndef atof -extern double atof(); -#endif -extern double pow(); -extern char *fgets(), *savestr(); +extern char *savestr(); extern char *emalloc(), *ecalloc(); extern EPNODE *curfunc; extern double efunc(), evariable(); -static double euminus(), echannel(), eargument(), enumber(); +static double euminus(), eargument(), enumber(); +#ifdef INCHAN +static double echannel(); +#endif static double eadd(), esubtr(), emult(), edivi(), epow(); static double ebotch(); +#ifdef DCL_ATOF +extern double atof(); +#endif + int nextc; /* lookahead character */ double (*eoper[])() = { /* expression operations */ @@ -124,6 +129,53 @@ char *expr; } +epcmp(ep1, ep2) /* compare two expressions for equivalence */ +register EPNODE *ep1, *ep2; +{ + double d; + + if (ep1->type != ep2->type) + return(1); + + switch (ep1->type) { + + case VAR: + return(ep1->v.ln != ep2->v.ln); + + case NUM: + if (ep2->v.num == 0) + return(ep1->v.num != 0); + d = ep1->v.num / ep2->v.num; + return(d > 1.000000000001 | d < 0.999999999999); + + case CHAN: + case ARG: + return(ep1->v.chan != ep2->v.chan); + + case '=': + case ':': + return(epcmp(ep1->v.kid->sibling, ep2->v.kid->sibling)); + + case TICK: + case SYM: /* should never get this one */ + return(0); + + default: + ep1 = ep1->v.kid; + ep2 = ep2->v.kid; + while (ep1 != NULL) { + if (ep2 == NULL) + return(1); + if (epcmp(ep1, ep2)) + return(1); + ep1 = ep1->sibling; + ep2 = ep2->sibling; + } + return(ep2 != NULL); + } +} + + epfree(epar) /* free a parse tree */ register EPNODE *epar; { @@ -148,8 +200,10 @@ register EPNODE *epar; break; default: - for (ep = epar->v.kid; ep != NULL; ep = ep->sibling) + while ((ep = epar->v.kid) != NULL) { + epar->v.kid = ep->sibling; epfree(ep); + } break; } @@ -371,7 +425,7 @@ scan() /* scan next character, return literal next char * -ltoa(l) /* convert long to ascii */ +long2ascii(l) /* convert long to ascii */ long l; { static char buf[16]; @@ -405,9 +459,9 @@ char *err; if (infile != NULL) eputs(infile); if (lineno != 0) { eputs(infile != NULL ? ", line " : "line "); - eputs(ltoa((long)lineno)); + eputs(long2ascii((long)lineno)); } - eputs(": syntax error:\n"); + eputs(":\n"); } eputs(linbuf); if (linbuf[strlen(linbuf)-1] != '\n')