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 */ |
85 |
|
epow, |
86 |
|
}; |
87 |
|
|
87 |
– |
static char *infile; /* input file name */ |
88 |
|
static FILE *infp; /* input file pointer */ |
89 |
|
static char *linbuf; /* line buffer */ |
90 |
+ |
static char *infile; /* input file name */ |
91 |
+ |
static int lineno; /* input line number */ |
92 |
|
static int linepos; /* position in buffer */ |
93 |
|
|
94 |
|
|
98 |
|
{ |
99 |
|
EPNODE *ep; |
100 |
|
|
101 |
< |
initstr(NULL, expr); |
101 |
> |
initstr(expr, NULL, 0); |
102 |
|
#if defined(VARIABLE) && defined(FUNCTION) |
103 |
|
curfunc = NULL; |
104 |
|
#endif |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
< |
initfile(file, fp) /* prepare input file */ |
295 |
< |
char *file; |
296 |
> |
initfile(fp, fn, ln) /* prepare input file */ |
297 |
|
FILE *fp; |
298 |
+ |
char *fn; |
299 |
+ |
int ln; |
300 |
|
{ |
301 |
|
static char inpbuf[MAXLINE]; |
302 |
|
|
300 |
– |
infile = file; |
303 |
|
infp = fp; |
304 |
|
linbuf = inpbuf; |
305 |
+ |
infile = fn; |
306 |
+ |
lineno = ln; |
307 |
|
linepos = 0; |
308 |
|
inpbuf[0] = '\0'; |
309 |
|
scan(); |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
< |
initstr(file, s) /* prepare input string */ |
310 |
< |
char *file; |
313 |
> |
initstr(s, fn, ln) /* prepare input string */ |
314 |
|
char *s; |
315 |
+ |
char *fn; |
316 |
+ |
int ln; |
317 |
|
{ |
313 |
– |
infile = file; |
318 |
|
infp = NULL; |
319 |
+ |
infile = fn; |
320 |
+ |
lineno = ln; |
321 |
|
linbuf = s; |
322 |
|
linepos = 0; |
323 |
|
scan(); |
332 |
|
nextc = EOF; |
333 |
|
else { |
334 |
|
nextc = linbuf[0]; |
335 |
+ |
lineno++; |
336 |
|
linepos = 1; |
337 |
|
} |
338 |
|
else |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
+ |
char * |
354 |
+ |
ltoa(l) /* convert long to ascii */ |
355 |
+ |
long l; |
356 |
+ |
{ |
357 |
+ |
static char buf[16]; |
358 |
+ |
register char *cp; |
359 |
+ |
int neg = 0; |
360 |
+ |
|
361 |
+ |
if (l == 0) |
362 |
+ |
return("0"); |
363 |
+ |
if (l < 0) { |
364 |
+ |
l = -l; |
365 |
+ |
neg++; |
366 |
+ |
} |
367 |
+ |
cp = buf + sizeof(buf); |
368 |
+ |
*--cp = '\0'; |
369 |
+ |
while (l) { |
370 |
+ |
*--cp = l % 10 + '0'; |
371 |
+ |
l /= 10; |
372 |
+ |
} |
373 |
+ |
if (neg) |
374 |
+ |
*--cp = '-'; |
375 |
+ |
return(cp); |
376 |
+ |
} |
377 |
+ |
|
378 |
+ |
|
379 |
|
syntax(err) /* report syntax error and quit */ |
380 |
|
char *err; |
381 |
|
{ |
382 |
|
register int i; |
383 |
|
|
384 |
+ |
if (infile != NULL || lineno != 0) { |
385 |
+ |
if (infile != NULL) eputs(infile); |
386 |
+ |
if (lineno != 0) { |
387 |
+ |
eputs(infile != NULL ? ", line " : "line "); |
388 |
+ |
eputs(ltoa((long)lineno)); |
389 |
+ |
} |
390 |
+ |
eputs(": syntax error:\n"); |
391 |
+ |
} |
392 |
|
eputs(linbuf); |
393 |
< |
if (linbuf[0] == '\0' || linbuf[strlen(linbuf)-1] != '\n') |
393 |
> |
if (linbuf[strlen(linbuf)-1] != '\n') |
394 |
|
eputs("\n"); |
395 |
|
for (i = 0; i < linepos-1; i++) |
396 |
|
eputs(linbuf[i] == '\t' ? "\t" : " "); |
397 |
|
eputs("^ "); |
357 |
– |
if (infile != NULL) { |
358 |
– |
eputs(infile); |
359 |
– |
eputs(": "); |
360 |
– |
} |
398 |
|
eputs(err); |
399 |
|
eputs("\n"); |
400 |
|
quit(1); |
554 |
|
getE4() /* E4 -> ADDOP E5 */ |
555 |
|
/* E5 */ |
556 |
|
{ |
557 |
< |
register EPNODE *ep1; |
557 |
> |
register EPNODE *ep1, *ep2; |
558 |
|
|
559 |
|
if (nextc == '-') { |
560 |
|
scan(); |
561 |
< |
ep1 = newnode(); |
562 |
< |
#ifndef RCONST |
563 |
< |
if (isdecimal(nextc)) { |
564 |
< |
ep1->type = NUM; |
528 |
< |
ep1->v.num = -getnum(); |
529 |
< |
return(ep1); |
561 |
> |
ep2 = getE5(); |
562 |
> |
if (ep2->type == NUM) { |
563 |
> |
ep2->v.num = -ep2->v.num; |
564 |
> |
return(ep2); |
565 |
|
} |
566 |
< |
#endif |
566 |
> |
ep1 = newnode(); |
567 |
|
ep1->type = UMINUS; |
568 |
< |
addekid(ep1, getE5()); |
534 |
< |
#ifdef RCONST |
535 |
< |
if (ep1->v.kid->type == NUM) |
536 |
< |
ep1 = rconst(ep1); |
537 |
< |
#endif |
568 |
> |
addekid(ep1, ep2); |
569 |
|
return(ep1); |
570 |
|
} |
571 |
|
if (nextc == '+') |