20 |
|
#include "copyright.h" |
21 |
|
|
22 |
|
#include <stdio.h> |
23 |
< |
|
23 |
> |
#include <string.h> |
24 |
|
#include <ctype.h> |
25 |
– |
|
25 |
|
#include <errno.h> |
27 |
– |
|
26 |
|
#include <math.h> |
29 |
– |
|
27 |
|
#include <stdlib.h> |
28 |
|
|
29 |
|
#include "calcomp.h" |
292 |
|
{ |
293 |
|
eputs("Bad expression!\n"); |
294 |
|
quit(1); |
295 |
+ |
return 0.0; /* pro forma return */ |
296 |
|
} |
297 |
|
|
298 |
|
|
646 |
|
/* FUNC(E1,..) */ |
647 |
|
/* ARG */ |
648 |
|
{ |
649 |
< |
int i; |
650 |
< |
char *nam; |
651 |
< |
register EPNODE *ep1, *ep2; |
649 |
> |
int i; |
650 |
> |
char *nam; |
651 |
> |
register EPNODE *ep1, *ep2; |
652 |
|
|
653 |
< |
if (nextc == '(') { |
654 |
< |
scan(); |
655 |
< |
ep1 = getE1(); |
656 |
< |
if (nextc != ')') |
657 |
< |
syntax("')' expected"); |
658 |
< |
scan(); |
659 |
< |
return(ep1); |
660 |
< |
} |
653 |
> |
if (nextc == '(') { |
654 |
> |
scan(); |
655 |
> |
ep1 = getE1(); |
656 |
> |
if (nextc != ')') |
657 |
> |
syntax("')' expected"); |
658 |
> |
scan(); |
659 |
> |
return(ep1); |
660 |
> |
} |
661 |
|
|
662 |
< |
if (esupport&E_INCHAN && nextc == '$') { |
663 |
< |
scan(); |
664 |
< |
ep1 = newnode(); |
665 |
< |
ep1->type = CHAN; |
666 |
< |
ep1->v.chan = getinum(); |
667 |
< |
return(ep1); |
668 |
< |
} |
662 |
> |
if (esupport&E_INCHAN && nextc == '$') { |
663 |
> |
scan(); |
664 |
> |
ep1 = newnode(); |
665 |
> |
ep1->type = CHAN; |
666 |
> |
ep1->v.chan = getinum(); |
667 |
> |
return(ep1); |
668 |
> |
} |
669 |
|
|
670 |
< |
if (esupport&(E_VARIABLE|E_FUNCTION) && |
671 |
< |
(isalpha(nextc) || nextc == CNTXMARK)) { |
672 |
< |
nam = getname(); |
673 |
< |
ep1 = NULL; |
674 |
< |
if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION) |
675 |
< |
&& curfunc != NULL) |
676 |
< |
for (i = 1, ep2 = curfunc->v.kid->sibling; |
677 |
< |
ep2 != NULL; i++, ep2 = ep2->sibling) |
678 |
< |
if (!strcmp(ep2->v.name, nam)) { |
679 |
< |
ep1 = newnode(); |
680 |
< |
ep1->type = ARG; |
681 |
< |
ep1->v.chan = i; |
682 |
< |
break; |
670 |
> |
if (esupport&(E_VARIABLE|E_FUNCTION) && |
671 |
> |
(isalpha(nextc) || nextc == CNTXMARK)) { |
672 |
> |
nam = getname(); |
673 |
> |
ep1 = NULL; |
674 |
> |
if ((esupport&(E_VARIABLE|E_FUNCTION)) == (E_VARIABLE|E_FUNCTION) |
675 |
> |
&& curfunc != NULL) |
676 |
> |
for (i = 1, ep2 = curfunc->v.kid->sibling; |
677 |
> |
ep2 != NULL; i++, ep2 = ep2->sibling) |
678 |
> |
if (!strcmp(ep2->v.name, nam)) { |
679 |
> |
ep1 = newnode(); |
680 |
> |
ep1->type = ARG; |
681 |
> |
ep1->v.chan = i; |
682 |
> |
break; |
683 |
> |
} |
684 |
> |
if (ep1 == NULL) { |
685 |
> |
ep1 = newnode(); |
686 |
> |
ep1->type = VAR; |
687 |
> |
ep1->v.ln = varinsert(nam); |
688 |
|
} |
689 |
< |
if (ep1 == NULL) { |
690 |
< |
ep1 = newnode(); |
691 |
< |
ep1->type = VAR; |
692 |
< |
ep1->v.ln = varinsert(nam); |
689 |
> |
if (esupport&E_FUNCTION && nextc == '(') { |
690 |
> |
ep2 = newnode(); |
691 |
> |
ep2->type = FUNC; |
692 |
> |
addekid(ep2, ep1); |
693 |
> |
ep1 = ep2; |
694 |
> |
do { |
695 |
> |
scan(); |
696 |
> |
addekid(ep1, getE1()); |
697 |
> |
} while (nextc == ','); |
698 |
> |
if (nextc != ')') |
699 |
> |
syntax("')' expected"); |
700 |
> |
scan(); |
701 |
> |
} else if (!(esupport&E_VARIABLE)) |
702 |
> |
syntax("'(' expected"); |
703 |
> |
if (esupport&E_RCONST && isconstvar(ep1)) |
704 |
> |
ep1 = rconst(ep1); |
705 |
> |
return(ep1); |
706 |
|
} |
691 |
– |
if (esupport&E_FUNCTION && nextc == '(') { |
692 |
– |
ep2 = newnode(); |
693 |
– |
ep2->type = FUNC; |
694 |
– |
addekid(ep2, ep1); |
695 |
– |
ep1 = ep2; |
696 |
– |
do { |
697 |
– |
scan(); |
698 |
– |
addekid(ep1, getE1()); |
699 |
– |
} while (nextc == ','); |
700 |
– |
if (nextc != ')') |
701 |
– |
syntax("')' expected"); |
702 |
– |
scan(); |
703 |
– |
} else if (!(esupport&E_VARIABLE)) |
704 |
– |
syntax("'(' expected"); |
705 |
– |
if (esupport&E_RCONST && isconstvar(ep1)) |
706 |
– |
ep1 = rconst(ep1); |
707 |
– |
return(ep1); |
708 |
– |
} |
707 |
|
|
708 |
< |
if (isdecimal(nextc)) { |
709 |
< |
ep1 = newnode(); |
710 |
< |
ep1->type = NUM; |
711 |
< |
ep1->v.num = getnum(); |
712 |
< |
return(ep1); |
713 |
< |
} |
714 |
< |
syntax("unexpected character"); |
708 |
> |
if (isdecimal(nextc)) { |
709 |
> |
ep1 = newnode(); |
710 |
> |
ep1->type = NUM; |
711 |
> |
ep1->v.num = getnum(); |
712 |
> |
return(ep1); |
713 |
> |
} |
714 |
> |
syntax("unexpected character"); |
715 |
> |
return NULL; /* pro forma return */ |
716 |
|
} |
717 |
|
|
718 |
|
|