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 |
|
|
473 |
|
char * |
474 |
|
getname() /* scan an identifier */ |
475 |
|
{ |
476 |
< |
static char str[MAXWORD+1]; |
476 |
> |
static char str[RMAXWORD+1]; |
477 |
|
register int i, lnext; |
478 |
|
|
479 |
|
lnext = nextc; |
480 |
< |
for (i = 0; i < MAXWORD && isid(lnext); i++, lnext = scan()) |
480 |
> |
for (i = 0; i < RMAXWORD && isid(lnext); i++, lnext = scan()) |
481 |
|
str[i] = lnext; |
482 |
|
str[i] = '\0'; |
483 |
|
while (isid(lnext)) /* skip rest of name */ |
506 |
|
getnum() /* scan a positive float */ |
507 |
|
{ |
508 |
|
register int i, lnext; |
509 |
< |
char str[MAXWORD+1]; |
509 |
> |
char str[RMAXWORD+1]; |
510 |
|
|
511 |
|
i = 0; |
512 |
|
lnext = nextc; |
513 |
< |
while (isdigit(lnext) && i < MAXWORD) { |
513 |
> |
while (isdigit(lnext) && i < RMAXWORD) { |
514 |
|
str[i++] = lnext; |
515 |
|
lnext = scan(); |
516 |
|
} |
517 |
< |
if (lnext == '.' && i < MAXWORD) { |
517 |
> |
if (lnext == '.' && i < RMAXWORD) { |
518 |
|
str[i++] = lnext; |
519 |
|
lnext = scan(); |
520 |
|
if (i == 1 && !isdigit(lnext)) |
521 |
|
syntax("badly formed number"); |
522 |
< |
while (isdigit(lnext) && i < MAXWORD) { |
522 |
> |
while (isdigit(lnext) && i < RMAXWORD) { |
523 |
|
str[i++] = lnext; |
524 |
|
lnext = scan(); |
525 |
|
} |
526 |
|
} |
527 |
< |
if ((lnext == 'e' | lnext == 'E') && i < MAXWORD) { |
527 |
> |
if ((lnext == 'e' | lnext == 'E') && i < RMAXWORD) { |
528 |
|
str[i++] = lnext; |
529 |
|
lnext = scan(); |
530 |
< |
if ((lnext == '-' | lnext == '+') && i < MAXWORD) { |
530 |
> |
if ((lnext == '-' | lnext == '+') && i < RMAXWORD) { |
531 |
|
str[i++] = lnext; |
532 |
|
lnext = scan(); |
533 |
|
} |
534 |
|
if (!isdigit(lnext)) |
535 |
|
syntax("missing exponent"); |
536 |
< |
while (isdigit(lnext) && i < MAXWORD) { |
536 |
> |
while (isdigit(lnext) && i < RMAXWORD) { |
537 |
|
str[i++] = lnext; |
538 |
|
lnext = scan(); |
539 |
|
} |
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 |
|
|