Annotation of researchv8dc/cmd/hoc/init.c, revision 1.1.1.1

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(), integer();
                      6: 
                      7: static struct {                /* Keywords */
                      8:        char    *name;
                      9:        int     kval;
                     10: } keywords[] = {
                     11:        "proc",         PROC,
                     12:        "func",         FUNC,
                     13:        "return",       RETURN,
                     14:        "if",           IF,
                     15:        "else",         ELSE,
                     16:        "while",        WHILE,
                     17:        "for",          FOR,
                     18:        "print",        PRINT,
                     19:        "read",         READ,
                     20:        0,              0,
                     21: };
                     22: 
                     23: static struct {                /* Constants */
                     24:        char *name;
                     25:        double cval;
                     26: } consts[] = {
                     27:        "PI",    3.14159265358979323846,
                     28:        "E",     2.71828182845904523536,
                     29:        "GAMMA", 0.57721566490153286060,  /* Euler */
                     30:        "DEG",  57.29577951308232087680,  /* deg/radian */
                     31:        "PHI",   1.61803398874989484820,  /* golden ratio */
                     32:        0,       0
                     33: };
                     34: 
                     35: static struct {                /* Built-ins */
                     36:        char *name;
                     37:        double  (*func)();
                     38: } builtins[] = {
                     39:        "sin",  sin,
                     40:        "cos",  cos,
                     41:        "atan", atan,
                     42:        "log",  Log,    /* checks range */
                     43:        "log10", Log10, /* checks range */
                     44:        "exp",  Exp,    /* checks range */
                     45:        "sqrt", Sqrt,   /* checks range */
                     46:        "gamma", Gamma, /* checks range */
                     47:        "int",  integer,
                     48:        "abs",  fabs,
                     49:        0,      0
                     50: };
                     51: 
                     52: init() /* install constants and built-ins in table */
                     53: {
                     54:        int i;
                     55:        Symbol *s;
                     56:        for (i = 0; keywords[i].name; i++)
                     57:                install(keywords[i].name, keywords[i].kval, 0.0);
                     58:        for (i = 0; consts[i].name; i++)
                     59:                install(consts[i].name, VAR, consts[i].cval);
                     60:        for (i = 0; builtins[i].name; i++) {
                     61:                s = install(builtins[i].name, BLTIN, 0.0);
                     62:                s->u.ptr = builtins[i].func;
                     63:        }
                     64: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.