Литмир - Электронная Библиотека
Содержание  
A
A

 "PHI",   1.61803398874989484820, /* golden ratio */

 0,       0

};

static struct { /* Built-ins */

 char *name;

 double (*func)();

} builtins[] = {

 "sin",   sin,

 "cos",   cos,

 "atan",  atan,

 "log",   Log, /* checks range */

 "log10", Log10, /* checks range */

 "exp",   Exp, /* checks range */

 "sqrt",  Sqrt, /* checks range */

 "int",   integer,

 "abs",   fabs,

 0, 0

};

init() /* install constants and built-ins in table */

{

 int i;

 Symbol *s;

 for (i = 0; keywords[i].name; i++)

  install(keywords[i].name, keywords[i].kval, 0.0);

 for (i = 0; consts[i].name; i++)

  install(consts[i].name, VAR, consts[i].eval);

 for (i = 0; builtins[i].name; i++) {

  s = install(builtins[i].name, BLTIN, 0.0);

  s->u.ptr = builtins[i].func;

 }

}

3.7.16

makeapp

#!/bin/sh

cd hoc6

for i in hoc.y hoc.h symbol.c code.c init.c math.c makefile

do

 echo "

**** $i ***************************************

"

 sed 's/\\/\\e/g

 s/^$/.sp .5/' $i |

 awk '

                      { print }

  /(^ ;$)|(^})|(^%%)/ { print ".P3" }

 '

done

3.7.17

makefile

CC = lcc

YFLAGS = -d

OBJS = hoc.o code.o init.o math.o symbol.o

hoc6: $(OBJS)

      $(CC) $(CFLAGS) $(OBJS) -lm -o hoc6

hoc.o code.o init.o symbol.o: hoc.h

code.o init.o symbol.o: x.tab.h

x.tab.h: y.tab.h

      -cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h

pr: hoc.y hoc.h code.c init.c math.c symbol.c

      @pr $?

      @touch pr

clean:

      rm -f $(OBJS) [xy].tab.[ch]

3.7.18

math.c

#include <math.h>

#include <errno.h>

extern int errno;

double errcheck();

double Log(x)

 double x;

{

 return errcheck(log(x), "log");

}

double Log10(x)

 double x;

{

 return errcheck(log10(x), "log10");

}

double Sqrt(x)

 double x;

{

 return errcheck(sqrt(x), "sqrt");

}

double Exp(x)

 double x;

{

 return errcheck(exp(x), "exp");

}

double Pow(x, y)

 double x, y;

{

 return errcheck(pow(x,y), "exponentiation");

}

double integer(x)

 double x;

{

 return (double)(long)x;

}

double errcheck(d, s) /* check result of library call */

 double d;

 char *s;

{

 if (errno == EDOM) {

  errno = 0;

  execerror(s, "argument out of domain");

 } else if (errno == ERANGE) {

172
{"b":"248117","o":1}