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

  1. /*
  2. *    header for complex-number expression parser.
  3. *    MWS, March 17, 1991.
  4. */
  5.  
  6. #ifndef NULL
  7. #define NULL (0L)
  8. #endif
  9.  
  10. typedef struct complex {    /* our complex-number representation */
  11.     double    real,
  12.         imag;
  13. } Complex;
  14.  
  15. typedef struct symlist {    /* parameter-list for a user-function */
  16.     struct symbol    *sym;
  17.     struct symlist    *next;
  18. } SymList;
  19.  
  20. typedef struct userfunction {
  21.     struct remember    *remkey;/* stores memory allocation list of tree */
  22.     struct symbol *param;    /* parameter to function */
  23.     struct node *tree;    /* the 'body' of the function */
  24. } UserFunc;
  25.  
  26. typedef struct symbol {        /* general symbol - numerous types */
  27.     char    *name;
  28.     short    type;        /* VAR, CONST, BLTIN */
  29.     union {
  30.         Complex    val;        /* if VAR or CONST */
  31.         Complex    (*cptr)();    /* C_BLTIN (function) */
  32.         double    (*rptr)();    /* R_BLTIN (function) */
  33.         void    (*vptr)();    /* COMMAND */
  34.         UserFunc ufunc;        /* USER FUNCTION */
  35.     } u;
  36.     struct Symbol    *left, *right;    /* children */
  37. } Symbol;
  38.  
  39.  
  40. typedef union {
  41.     Complex    val;        /* a complex number */
  42.     Symbol    *sym;        /* a symbol */
  43. } Contents;
  44.  
  45. typedef struct node {
  46.     int    type;            /* type of node */
  47.     Contents contents;        /* contents of node */
  48.     struct node *left, *right;    /* children */
  49. } Node;
  50.  
  51. /*
  52. *    Convention: if node type is a builtin or unary operator,
  53. *    the left child will hold the expression that is the
  54. *    argument to the function.
  55. */
  56.  
  57. #define    sqr(x)    (x)*(x)
  58. #define sign(x)    ((x) >= 0.0 ? '+' : '-')
  59.  
  60. /* Lattice-generated prototypes (some of them) */
  61. /* Prototypes for functions defined in cmath.c */
  62. Complex cadd(Complex w, Complex z);
  63. Complex csub(Complex w, Complex z);
  64. Complex cmul(Complex w, Complex z);
  65. Complex cdiv(Complex w, Complex z);
  66. Complex cneg(Complex z);
  67. Complex csqr(Complex z);
  68. Complex csqrt(Complex z);
  69. Complex conj(Complex z);
  70. Complex cexp(Complex z);
  71. Complex clog(Complex z);
  72. Complex cpow(Complex w, Complex z);
  73. Complex csin(Complex z);
  74. Complex ccos(Complex z);
  75. Complex ctan(Complex z);
  76. Complex casin(Complex z);
  77. Complex cacos(Complex z);
  78. Complex catan(Complex z);
  79. Complex csinh(Complex z);
  80. Complex ccosh(Complex z);
  81. Complex ctanh(Complex z);
  82.  
  83. double Re(Complex z), Im(Complex z);
  84. double arg(Complex z);
  85. double norm(Complex z);
  86. double cabs(Complex z);
  87.  
  88. /* Prototypes for functions defined in math.c */
  89. double    Sqrt(double),
  90.     Log(double),
  91.     Asin(double),
  92.     Acos(double),
  93.     errcheck(double, char *);
  94.  
  95. /* Prototypes for functions defined in complex.y */
  96. int    yylex(void);
  97. void    warning(char *, char *),
  98.     yyerror(char *),
  99.     execerror(char *, char *),
  100.     welcome(void),
  101.     prompt(void),
  102.     main(int, char **);
  103.  
  104. /* Prototypes for functions defined in symbol.c */
  105. Symbol *lookup(char *s);
  106. Symbol *allocsym(char *s, int t);
  107. Symbol *install(char *s, int t, Complex cval);
  108. void printlist(int type);
  109.  
  110. /* Prototypes for functions defined in init.c */
  111. void init(void);
  112.  
  113. /* Prototypes for functions defined in command.c */
  114. void    besilent(),
  115.     beverbose(),
  116.     quiticalc(),
  117.     builtins(void),
  118.     userfuncs(void),
  119.     consts(void),
  120.     vars(void),
  121.     help(void);
  122.  
  123. /* Prototypes for functions defined in tree.c */
  124. Node *n_asgn(Symbol *sym, Node *arg);
  125. Node *n_binop(int op, Node *left, Node *right);
  126. Node *n_unop(int op, Node *arg); 
  127. Node *n_func(int type, Symbol *sym, Node *arg);
  128. Node *n_symbol(int type, Symbol *sym);
  129. Node *n_number(double real, double imag);
  130. Complex eval_tree(Node *n);
  131. void delete_tree(Node *n);
  132.  
  133. /* Prototypes for functions defined in function.c */
  134. void clear_ufunc(UserFunc *func);
  135.