|
|
1.1 ! root 1: #include "hoc.h" ! 2: #include "y.tab.h" ! 3: #include <math.h> ! 4: ! 5: extern double Log(), Log10(), Gamma(), Sqrt(), Exp(); ! 6: extern double Asin(), Acos(), Sinh(), Cosh(), integer(); ! 7: ! 8: static struct { /* Keywords */ ! 9: char *name; ! 10: int kval; ! 11: } keywords[] = { ! 12: "proc", PROC, ! 13: "func", FUNC, ! 14: "return", RETURN, ! 15: "if", IF, ! 16: "else", ELSE, ! 17: "while", WHILE, ! 18: "for", FOR, ! 19: "print", PRINT, ! 20: "read", READ, ! 21: 0, 0, ! 22: }; ! 23: ! 24: static struct { /* Constants */ ! 25: char *name; ! 26: double cval; ! 27: } consts[] = { ! 28: "PI", 3.14159265358979323846, ! 29: "E", 2.71828182845904523536, ! 30: "GAMMA", 0.57721566490153286060, /* Euler */ ! 31: "DEG", 57.29577951308232087680, /* deg/radian */ ! 32: "PHI", 1.61803398874989484820, /* golden ratio */ ! 33: "PREC", 15, /* output precision */ ! 34: 0, 0 ! 35: }; ! 36: ! 37: static struct { /* Built-ins */ ! 38: char *name; ! 39: double (*func)(); ! 40: } builtins[] = { ! 41: "sin", sin, ! 42: "cos", cos, ! 43: "tan", tan, ! 44: "atan", atan, ! 45: "asin", Asin, /* checks range */ ! 46: "acos", Acos, /* checks range */ ! 47: "sinh", Sinh, /* checks range */ ! 48: "cosh", Cosh, /* checks range */ ! 49: "tanh", tanh, ! 50: "log", Log, /* checks range */ ! 51: "log10", Log10, /* checks range */ ! 52: "exp", Exp, /* checks range */ ! 53: "sqrt", Sqrt, /* checks range */ ! 54: "gamma", Gamma, /* checks range */ ! 55: "int", integer, ! 56: "abs", fabs, ! 57: "erf", erf, ! 58: "erfc", erfc, ! 59: 0, 0 ! 60: }; ! 61: ! 62: init() /* install constants and built-ins in table */ ! 63: { ! 64: int i; ! 65: Symbol *s; ! 66: for (i = 0; keywords[i].name; i++) ! 67: install(keywords[i].name, keywords[i].kval, 0.0); ! 68: for (i = 0; consts[i].name; i++) ! 69: install(consts[i].name, VAR, consts[i].cval); ! 70: for (i = 0; builtins[i].name; i++) { ! 71: s = install(builtins[i].name, BLTIN, 0.0); ! 72: s->u.ptr = builtins[i].func; ! 73: } ! 74: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.