home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / misc / icalc.lzh / icalc / src / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-26  |  2.5 KB  |  132 lines

  1. /*
  2. *    icalc - complex-expression parser
  3. *
  4. *    Initial symbol-table setup for complex-number expression parser.
  5. *
  6. *    (C) Martin W Scott, 1991.
  7. */
  8. #include <math.h>
  9. #include "complex.h"
  10. #include "constant.h"
  11. #include "complex.tab.h"
  12.  
  13.  
  14. static struct {        /* keywords */
  15.     char    *name;
  16.     int    kval;
  17. } keywords[] = {
  18.     "func",    FUNCDEF,
  19.     NULL,    NULL
  20. };
  21.  
  22. static struct {        /* commands */
  23.     char    *name;
  24.     void    (*func)();
  25. } commands[] = {
  26.     "exit", quiticalc,
  27.     "quit", quiticalc,
  28.     "help",    help,
  29.     "vars",    vars,
  30.     "consts",consts,
  31.     "builtins",builtins,
  32.     "functions", userfuncs,
  33.     "silent", besilent,
  34.     "verbose", beverbose,
  35.     NULL,    NULL
  36. };
  37.  
  38. static struct {        /* constants */
  39.     char    *name;
  40.     Complex    cval;
  41. } constants[] = {
  42.     "ans",    {  0.0, 0.0 },
  43.     "PI",    {  PI, 0.0 },
  44.     "E",    {  2.71828182845904523536, 0.0 },
  45.     "GAMMA",{  0.57721566490153286060, 0.0 },
  46.     "DEG",    { 57.29577951308232087680, 0.0 },    
  47.     "PHI",    {  1.61803398874989484820, 0.0 },
  48.     "LOG10",{  2.30258509299404568402, 0.0 },
  49.     "LOG2",    {  0.69314718055994530942, 0.0 },
  50.     NULL,    {  0.0, 0.0 }
  51. };
  52.  
  53. static struct {        /* complex-valued functions */
  54.     char    *name;
  55.     Complex    (*func)();
  56. } c_builtins[] = {
  57.     "abs",    cabs,
  58.     "norm",    norm,
  59.     "arg",    arg,
  60.     "Re",    Re,
  61.     "Im",    Im,
  62.     "sin",    csin,
  63.     "cos",    ccos,
  64.     "tan",    ctan,
  65.     "asin",    casin,
  66.     "acos",    cacos,
  67.     "atan",    catan,
  68.     "sinh",    csinh,
  69.     "cosh",    ccosh,
  70.     "tanh",    ctanh,
  71.     "sqr",    csqr,
  72.     "sqrt",    csqrt,
  73.     "conj",    conj,
  74.     "ln",    clog,
  75.     "exp",    cexp,
  76.     "int",  cinteger,
  77.     "ceil", cceil,
  78.     "floor",cfloor,
  79.     "sgn",  csign,
  80.     "prec",    precision,
  81.     "print", printres,
  82.     "time", gettime,
  83.     NULL,    NULL
  84. };
  85.  
  86. static struct {        /* special functions */
  87.     char    *name;
  88.     Complex    (*func)();
  89. } s_functions[] = {
  90.     "Sum",    spec_sum,
  91.     "Prod",    spec_prod,
  92.     "every",spec_every,
  93.     "vevery",spec_vevery,
  94.     "multi",spec_multi,
  95.     "max",    spec_max,
  96.     "min",    spec_min,
  97.     NULL,    NULL
  98. };
  99.  
  100. void init()    /* install constants and built-ins in table */
  101. {
  102.     extern Symbol *ans, *multi;
  103.     unsigned short i;
  104.     Symbol *s;
  105.  
  106.     for (i = 0; keywords[i].name; i++)
  107.         install(keywords[i].name, keywords[i].kval, zero);
  108.  
  109.     for (i = 0; commands[i].name; i++)
  110.     {
  111.         s = install(commands[i].name, COMMAND, zero);
  112.         s->u.vptr = commands[i].func;
  113.     }
  114.  
  115.     for (i = 0; constants[i].name; i++)
  116.         install(constants[i].name, CONST, constants[i].cval);
  117.     ans = lookup("ans");    /* previous answer */
  118.  
  119.     for (i = 0; c_builtins[i].name; i++)
  120.     {
  121.         s = install(c_builtins[i].name, C_BLTIN, zero);
  122.         s->u.cptr = c_builtins[i].func;
  123.     }
  124.  
  125.     for (i = 0; s_functions[i].name; i++)
  126.     {
  127.         s = install(s_functions[i].name, SFUNC, zero);
  128.         s->u.sptr = s_functions[i].func;
  129.     }
  130.     multi = lookup("multi");    /* multi-expression special function */
  131. }
  132.