--- ray/src/common/calexpr.c 1991/04/23 15:44:41 1.10 +++ ray/src/common/calexpr.c 1991/08/08 13:40:09 1.14 @@ -27,12 +27,9 @@ static char SCCSid[] = "$SunId$ LBL"; #include "calcomp.h" #define MAXLINE 256 /* maximum line length */ -#define MAXWORD 64 /* maximum word length */ #define newnode() (EPNODE *)ecalloc(1, sizeof(EPNODE)) -#define isid(c) (isalnum(c) || (c) == '_' || (c) == '.') - #define isdecimal(c) (isdigit(c) || (c) == '.') extern double atof(), pow(); @@ -326,8 +323,24 @@ int ln; } -scan() /* scan next character */ +getscanpos(fnp, lnp, spp, fpp) /* return current scan position */ +char **fnp; +int *lnp; +char **spp; +FILE **fpp; { + if (fnp != NULL) *fnp = infile; + if (lnp != NULL) *lnp = lineno; + if (spp != NULL) *spp = linbuf+linepos; + if (fpp != NULL) *fpp = infp; +} + + +int +scan() /* scan next character, return literal next */ +{ + register int lnext = 0; + do { if (linbuf[linepos] == '\0') if (infp == NULL || fgets(linbuf, MAXLINE, infp) == NULL) @@ -339,6 +352,8 @@ scan() /* scan next character */ } else nextc = linbuf[linepos++]; + if (!lnext) + lnext = nextc; if (nextc == '{') { scan(); while (nextc != '}') @@ -349,6 +364,7 @@ scan() /* scan next character */ scan(); } } while (isspace(nextc)); + return(lnext); } @@ -422,10 +438,11 @@ char * getname() /* scan an identifier */ { static char str[MAXWORD+1]; - register int i; + register int i, lnext; - for (i = 0; i < MAXWORD && isid(nextc); i++, scan()) - str[i] = nextc; + lnext = nextc; + for (i = 0; i < MAXWORD && isid(lnext); i++, lnext = scan()) + str[i] = lnext; str[i] = '\0'; return(str); @@ -435,12 +452,13 @@ getname() /* scan an identifier */ int getinum() /* scan a positive integer */ { - register int n; + register int n, lnext; n = 0; - while (isdigit(nextc)) { - n = n * 10 + nextc - '0'; - scan(); + lnext = nextc; + while (isdigit(lnext)) { + n = n * 10 + lnext - '0'; + lnext = scan(); } return(n); } @@ -449,32 +467,33 @@ getinum() /* scan a positive integer */ double getnum() /* scan a positive float */ { - register int i; + register int i, lnext; char str[MAXWORD+1]; i = 0; - while (isdigit(nextc) && i < MAXWORD) { - str[i++] = nextc; - scan(); + lnext = nextc; + while (isdigit(lnext) && i < MAXWORD) { + str[i++] = lnext; + lnext = scan(); } - if (nextc == '.' && i < MAXWORD) { - str[i++] = nextc; - scan(); - while (isdigit(nextc) && i < MAXWORD) { - str[i++] = nextc; - scan(); + if (lnext == '.' && i < MAXWORD) { + str[i++] = lnext; + lnext = scan(); + while (isdigit(lnext) && i < MAXWORD) { + str[i++] = lnext; + lnext = scan(); } } - if ((nextc == 'e' || nextc == 'E') && i < MAXWORD) { - str[i++] = nextc; - scan(); - if ((nextc == '-' || nextc == '+') && i < MAXWORD) { - str[i++] = nextc; - scan(); + if ((lnext == 'e' || lnext == 'E') && i < MAXWORD) { + str[i++] = lnext; + lnext = scan(); + if ((lnext == '-' || lnext == '+') && i < MAXWORD) { + str[i++] = lnext; + lnext = scan(); } - while (isdigit(nextc) && i < MAXWORD) { - str[i++] = nextc; - scan(); + while (isdigit(lnext) && i < MAXWORD) { + str[i++] = lnext; + lnext = scan(); } } str[i] = '\0'; @@ -585,6 +604,7 @@ getE5() /* E5 -> (E1) */ /* ARG */ { int i; + char *nam; register EPNODE *ep1, *ep2; if (nextc == '(') { @@ -608,22 +628,25 @@ getE5() /* E5 -> (E1) */ #if defined(VARIABLE) || defined(FUNCTION) if (isalpha(nextc)) { - ep1 = newnode(); - ep1->type = VAR; - ep1->v.ln = varinsert(getname()); - + nam = getname(); #if defined(VARIABLE) && defined(FUNCTION) + ep1 = NULL; if (curfunc != NULL) for (i = 1, ep2 = curfunc->v.kid->sibling; ep2 != NULL; i++, ep2 = ep2->sibling) - if (!strcmp(ep2->v.name, ep1->v.ln->name)) { - epfree(ep1); + if (!strcmp(ep2->v.name, nam)) { ep1 = newnode(); ep1->type = ARG; ep1->v.chan = i; break; } + if (ep1 == NULL) #endif + { + ep1 = newnode(); + ep1->type = VAR; + ep1->v.ln = varinsert(nam); + } #ifdef FUNCTION if (nextc == '(') { ep2 = newnode(); @@ -680,26 +703,18 @@ register EPNODE *epar; } -isconstvar(ep) /* is ep linked to a constant? */ +isconstvar(ep) /* is ep linked to a constant expression? */ register EPNODE *ep; { #ifdef VARIABLE register EPNODE *ep1; #ifdef FUNCTION - LIBR *lp; if (ep->type == FUNC) { - if (ep->v.kid->type != VAR) - return(0); - ep1 = ep->v.kid->v.ln->def; - if (ep1 != NULL && ep1->type != ':') - return(0); - if ((ep1 == NULL || ep1->v.kid->type != FUNC) - && ((lp = liblookup(ep->v.kid->v.ln->name)) == NULL - || lp->atyp != ':')) - return(0); + if (!isconstfun(ep->v.kid)) + return(0); for (ep1 = ep->v.kid->sibling; ep1 != NULL; ep1 = ep1->sibling) - if (ep1->type != NUM) + if (ep1->type != NUM && !isconstfun(ep1)) return(0); return(1); } @@ -718,4 +733,25 @@ register EPNODE *ep; return(ep->type == FUNC); #endif } + + +#if defined(FUNCTION) && defined(VARIABLE) +isconstfun(ep) /* is ep linked to a constant function? */ +register EPNODE *ep; +{ + register EPNODE *dp; + register LIBR *lp; + + if (ep->type != VAR) + return(0); + dp = ep->v.ln->def; + if (dp != NULL && dp->type != ':') + return(0); + if ((dp == NULL || dp->v.kid->type != FUNC) + && ((lp = liblookup(ep->v.ln->name)) == NULL + || lp->atyp != ':')) + return(0); + return(1); +} +#endif #endif