--- ray/src/common/calexpr.c 1991/08/08 11:22:04 1.12 +++ ray/src/common/calexpr.c 1992/05/07 22:30:41 2.3 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -32,7 +32,10 @@ static char SCCSid[] = "$SunId$ LBL"; #define isdecimal(c) (isdigit(c) || (c) == '.') -extern double atof(), pow(); +#ifndef atof +extern double atof(); +#endif +extern double pow(); extern char *fgets(), *savestr(); extern char *emalloc(), *ecalloc(); extern EPNODE *curfunc; @@ -323,6 +326,19 @@ int ln; } +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 */ { @@ -431,6 +447,8 @@ getname() /* scan an identifier */ for (i = 0; i < MAXWORD && isid(lnext); i++, lnext = scan()) str[i] = lnext; str[i] = '\0'; + while (isid(lnext)) /* skip rest of name */ + lnext = scan(); return(str); } @@ -571,6 +589,10 @@ getE4() /* E4 -> ADDOP E5 */ ep2->v.num = -ep2->v.num; return(ep2); } + if (ep2->type == UMINUS) { /* don't generate -(-E5) */ + efree((char *)ep2); + return(ep2->v.kid); + } ep1 = newnode(); ep1->type = UMINUS; addekid(ep1, ep2); @@ -591,6 +613,7 @@ getE5() /* E5 -> (E1) */ /* ARG */ { int i; + char *nam; register EPNODE *ep1, *ep2; if (nextc == '(') { @@ -613,23 +636,26 @@ getE5() /* E5 -> (E1) */ #endif #if defined(VARIABLE) || defined(FUNCTION) - if (isalpha(nextc)) { - ep1 = newnode(); - ep1->type = VAR; - ep1->v.ln = varinsert(getname()); - + if (isalpha(nextc) || nextc == CNTXMARK) { + 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(); @@ -727,14 +753,11 @@ register EPNODE *ep; 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); + if ((dp = ep->v.ln->def) != NULL && dp->v.kid->type == FUNC) + return(dp->type == ':'); + if ((lp = liblookup(ep->v.ln->name)) != NULL) + return(lp->atyp == ':'); + return(0); } #endif #endif