ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calexpr.c
(Generate patch)

Comparing ray/src/common/calexpr.c (file contents):
Revision 1.4 by greg, Thu Jun 29 09:44:33 1989 UTC vs.
Revision 1.9 by greg, Tue Apr 23 15:26:26 1991 UTC

# Line 39 | Line 39 | extern double  atof(), pow();
39   extern char  *fgets(), *savestr();
40   extern char  *emalloc(), *ecalloc();
41   extern EPNODE  *curfunc;
42 < extern double  efunc(), evariable(), enumber(), euminus(), echannel();
43 < extern double  eargument(), eadd(), esubtr(), emult(), edivi(), epow();
44 < extern double  ebotch();
42 > extern double  efunc(), evariable();
43 > static double  euminus(), echannel(), eargument(), enumber();
44 > static double  eadd(), esubtr(), emult(), edivi(), epow();
45 > static double  ebotch();
46   extern int  errno;
47  
48   int  nextc;                             /* lookahead character */
# Line 77 | Line 78 | double  (*eoper[])() = {               /* expression operations */
78          esubtr,
79          0,
80          edivi,
81 <        0,0,0,0,0,0,0,0,0,0,0,0,0,
81 >        0,0,0,0,0,0,0,0,0,0,
82          ebotch,
83 +        0,0,
84 +        ebotch,
85          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
86          0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
87          epow,
88   };
89  
87 static char  *infile;                   /* input file name */
90   static FILE  *infp;                     /* input file pointer */
91   static char  *linbuf;                   /* line buffer */
92 + static char  *infile;                   /* input file name */
93 + static int  lineno;                     /* input line number */
94   static int  linepos;                    /* position in buffer */
95  
96  
# Line 96 | Line 100 | char  *expr;
100   {
101      EPNODE  *ep;
102  
103 <    initstr(NULL, expr);
103 >    initstr(expr, NULL, 0);
104   #if  defined(VARIABLE) && defined(FUNCTION)
105      curfunc = NULL;
106   #endif
# Line 291 | Line 295 | register EPNODE  *ep;
295   }
296  
297  
298 < initfile(file, fp)              /* prepare input file */
295 < char  *file;
298 > initfile(fp, fn, ln)            /* prepare input file */
299   FILE  *fp;
300 + char  *fn;
301 + int  ln;
302   {
303      static char  inpbuf[MAXLINE];
304  
300    infile = file;
305      infp = fp;
306      linbuf = inpbuf;
307 +    infile = fn;
308 +    lineno = ln;
309      linepos = 0;
310      inpbuf[0] = '\0';
311      scan();
312   }
313  
314  
315 < initstr(file, s)                /* prepare input string */
310 < char  *file;
315 > initstr(s, fn, ln)              /* prepare input string */
316   char  *s;
317 + char  *fn;
318 + int  ln;
319   {
313    infile = file;
320      infp = NULL;
321 +    infile = fn;
322 +    lineno = ln;
323      linbuf = s;
324      linepos = 0;
325      scan();
# Line 326 | Line 334 | scan()                         /* scan next character */
334                  nextc = EOF;
335              else {
336                  nextc = linbuf[0];
337 +                lineno++;
338                  linepos = 1;
339              }
340          else
# Line 343 | Line 352 | scan()                         /* scan next character */
352   }
353  
354  
355 + char *
356 + ltoa(l)                         /* convert long to ascii */
357 + long  l;
358 + {
359 +    static char  buf[16];
360 +    register char  *cp;
361 +    int  neg = 0;
362 +
363 +    if (l == 0)
364 +        return("0");
365 +    if (l < 0) {
366 +        l = -l;
367 +        neg++;
368 +    }
369 +    cp = buf + sizeof(buf);
370 +    *--cp = '\0';
371 +    while (l) {
372 +        *--cp = l % 10 + '0';
373 +        l /= 10;
374 +    }
375 +    if (neg)
376 +        *--cp = '-';
377 +    return(cp);
378 + }
379 +
380 +
381   syntax(err)                     /* report syntax error and quit */
382   char  *err;
383   {
384      register int  i;
385  
386 +    if (infile != NULL || lineno != 0) {
387 +        if (infile != NULL) eputs(infile);
388 +        if (lineno != 0) {
389 +            eputs(infile != NULL ? ", line " : "line ");
390 +            eputs(ltoa((long)lineno));
391 +        }
392 +        eputs(": syntax error:\n");
393 +    }
394      eputs(linbuf);
395      if (linbuf[strlen(linbuf)-1] != '\n')
396          eputs("\n");
397      for (i = 0; i < linepos-1; i++)
398          eputs(linbuf[i] == '\t' ? "\t" : " ");
399      eputs("^ ");
357    if (infile != NULL) {
358        eputs(infile);
359        eputs(": ");
360    }
400      eputs(err);
401      eputs("\n");
402      quit(1);
# Line 491 | Line 530 | getE2()                                /* E2 -> E2 MULOP E3 */
530  
531  
532   EPNODE *
533 < getE3()                         /* E3 -> E3 ^ E4 */
533 > getE3()                         /* E3 -> E4 ^ E3 */
534                                  /*       E4 */
535   {
536      register EPNODE  *ep1, *ep2;
537  
538      ep1 = getE4();
539 <    while (nextc == '^') {
539 >    if (nextc == '^') {
540          ep2 = newnode();
541          ep2->type = nextc;
542          scan();
543          addekid(ep2, ep1);
544 <        addekid(ep2, getE4());
544 >        addekid(ep2, getE3());
545   #ifdef  RCONST
546          if (ep1->type == NUM && ep1->sibling->type == NUM)
547                  ep2 = rconst(ep2);
548   #endif
549 <        ep1 = ep2;
549 >        return(ep2);
550      }
551      return(ep1);
552   }
# Line 604 | Line 643 | getE5()                                /* E5 -> (E1) */
643              syntax("'(' expected");
644   #endif
645   #endif
646 + #ifdef  RCONST
647 +        if (isconstvar(ep1))
648 +            ep1 = rconst(ep1);
649 + #endif
650          return(ep1);
651      }
652   #endif
# Line 634 | Line 677 | register EPNODE  *epar;
677      epfree(epar);
678  
679      return(ep);
680 + }
681 +
682 +
683 + isconstvar(ep)                  /* is ep linked to a constant? */
684 + register EPNODE  *ep;
685 + {
686 + #ifdef  VARIABLE
687 +    register EPNODE  *ep1;
688 +    
689 + #ifdef  FUNCTION
690 +    if (ep->type == FUNC) {
691 +        if (ep->v.kid->type != VAR)
692 +            return(0);
693 +        ep1 = ep->v.kid->v.ln->def;
694 +        if (ep1 != NULL && ep1->type != ':')
695 +            return(0);
696 +        if ((ep1 == NULL || ep1->v.kid->type != FUNC)
697 +                && liblookup(ep->v.kid->v.ln->name) == NULL)
698 +            return(0);
699 +        for (ep1 = ep->v.kid->sibling; ep1 != NULL; ep1 = ep1->sibling)
700 +            if (ep1->type != NUM)
701 +                return(0);
702 +        return(1);
703 +    }
704 + #endif
705 +    if (ep->type != VAR)
706 +        return(0);
707 +    ep1 = ep->v.ln->def;
708 +    if (ep1 == NULL || ep1->type != ':')
709 +        return(0);
710 + #ifdef  FUNCTION
711 +    if (ep1->v.kid->type != SYM)
712 +        return(0);
713 + #endif
714 +    return(1);
715 + #else
716 +    return(ep->type == FUNC);
717 + #endif
718   }
719   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines