home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD2.img / d4xx / d472 / icalc / src / init.c < prev    next >
C/C++ Source or Header  |  1991-04-17  |  2KB  |  116 lines

  1. /*
  2. *    initial symbol-table setup for complex-number expression parser.
  3. *    MWS, March 17, 1991.
  4. */
  5. #include <math.h>
  6. #include "complex.h"
  7. #include "complex.tab.h"
  8.  
  9. extern const Complex zero, eye;
  10.  
  11. static struct {        /* keywords */
  12.     char    *name;
  13.     int    kval;
  14. } keywords[] = {
  15.     "func",    FUNCDEF,
  16.     "prec",    PRECISION,
  17.     "repeat", REPEAT,
  18.     NULL,    NULL
  19. };
  20.  
  21. static struct {        /* commands */
  22.     char    *name;
  23.     void    (*func)();
  24. } commands[] = {
  25.     "exit", quiticalc,
  26.     "quit", quiticalc,
  27.     "help",    help,
  28.     "vars",    vars,
  29.     "consts",consts,
  30.     "builtins",builtins,
  31.     "functions", userfuncs,
  32.     "silent", besilent,
  33.     "verbose", beverbose,
  34.     NULL,    NULL
  35. };
  36.  
  37. static struct {        /* constants */
  38.     char    *name;
  39.     Complex    cval;
  40. } constants[] = {
  41.     "ans",    {  0.0, 0.0 },
  42.     "PI",    {  PI, 0.0 },
  43.     "E",    {  2.71828182845904523536, 0.0 },
  44.     "GAMMA",{  0.57721566490153286060, 0.0 },
  45.     "DEG",    { 57.29577951308232087680, 0.0 },    
  46.     "PHI",    {  1.61803398874989484820, 0.0 },
  47.     "LOG10",{  2.30258509299404568402, 0.0 },
  48.     "LOG2",    {  0.69314718055994530942, 0.0 },
  49.     NULL,    {  0.0, 0.0 }
  50. };
  51.  
  52. static struct {        /* complex-valued functions */
  53.     char    *name;
  54.     Complex    (*func)();
  55. } c_builtins[] = {
  56.     "sin",    csin,
  57.     "cos",    ccos,
  58.     "tan",    ctan,
  59.     "asin",    casin,
  60.     "acos",    cacos,
  61.     "atan",    catan,
  62.     "sinh",    csinh,
  63.     "cosh",    ccosh,
  64.     "tanh",    ctanh,
  65.     "sqr",    csqr,
  66.     "sqrt",    csqrt,
  67.     "conj",    conj,
  68.     "ln",    clog,
  69.     "exp",    cexp,
  70.     NULL,    NULL
  71. };
  72.  
  73. static struct {        /* real-valued functions */
  74.     char    *name;
  75.     double    (*func)();
  76. } r_builtins[] = {
  77.     "abs",    cabs,
  78.     "norm",    norm,
  79.     "arg",    arg,
  80.     "Re",    Re,
  81.     "Im",    Im,
  82.     NULL,    NULL
  83. };
  84.  
  85. void init()    /* install constants and built-ins in table */
  86. {
  87.     extern Symbol *ans;
  88.     unsigned short i;
  89.     Symbol *s;
  90.  
  91.     for (i = 0; keywords[i].name; i++)
  92.         install(keywords[i].name, keywords[i].kval, zero);
  93.  
  94.     for (i = 0; commands[i].name; i++)
  95.     {
  96.         s = install(commands[i].name, COMMAND, zero);
  97.         s->u.vptr = commands[i].func;
  98.     }
  99.  
  100.     for (i = 0; constants[i].name; i++)
  101.         install(constants[i].name, CONST, constants[i].cval);
  102.     ans = lookup("ans");    /* previous answer */
  103.  
  104.     for (i = 0; c_builtins[i].name; i++)
  105.     {
  106.         s = install(c_builtins[i].name, C_BLTIN, zero);
  107.         s->u.cptr = c_builtins[i].func;
  108.     }
  109.     for (i = 0; r_builtins[i].name; i++)
  110.     {
  111.         s = install(r_builtins[i].name, R_BLTIN, zero);
  112.         s->u.rptr = r_builtins[i].func;
  113.     }
  114. }
  115.  
  116.