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

  1. /*
  2. *    icalc - complex-expression parser
  3. *
  4. *    Header for complex-number expression parser.
  5. *    Contains all global structure definitions.
  6. *
  7. *    (C) Martin W Scott, 1991.
  8. */
  9.  
  10. #include <stdio.h>
  11. #ifndef NULL
  12. #define NULL (0L)
  13. #endif
  14.  
  15. typedef struct complex {    /* our complex-number representation */
  16.     double    real,
  17.         imag;
  18. } Complex;
  19.  
  20. typedef struct symlist {    /* parameter-list for a user-function */
  21.     struct symbol    *sym;
  22.     struct symlist    *next;
  23. } SymList;
  24.  
  25. typedef struct arglist {    /* parameter-list for a user-function */
  26.     struct node    *node;        /* each node is tree expression of parameter */
  27.     struct arglist    *next;
  28. } ArgList;
  29.  
  30. typedef struct userfunction {
  31.     struct remember    *remkey;/* stores memory allocation list of tree */
  32.     struct node *tree;    /* the 'body' of the function */
  33.     struct symlist *params;    /* parameters to function */
  34. } UserFunc;
  35.  
  36. typedef struct symbol {        /* general symbol - numerous types */
  37.     char    *name;
  38.     short    type;        /* VAR, CONST, BLTIN etc */
  39.     union {
  40.         Complex    val;        /* if VAR or CONST */
  41.         Complex    (*cptr)();    /* C_BLTIN Complex-valued function */
  42.         Complex    (*sptr)();    /* pointer to complex-valued function */
  43.         void    (*vptr)();    /* COMMAND */
  44.         UserFunc ufunc;        /* USER FUNCTION */
  45.     } u;
  46.     struct Symbol    *left, *right;    /* children */
  47. } Symbol;
  48.  
  49.  
  50. typedef union {
  51.     Complex    val;        /* a complex number */
  52.     Symbol    *sym;        /* a symbol */
  53. } Contents;
  54.  
  55. typedef struct node {
  56.     int    type;            /* type of node */
  57.     Contents contents;        /* contents of node */
  58.     struct node *left, *right;    /* children */
  59. } Node;
  60.  
  61. /*
  62. *    Convention: if node type is a builtin or unary operator,
  63. *    the left child will hold the expression that is the
  64. *    argument to the function.
  65. */
  66.  
  67. #define    sqr(x)    (x)*(x)
  68. #define sign(x)    ((x) >= 0.0 ? '+' : '-')
  69.  
  70. /* Lattice-generated prototypes (some of them) */
  71.  
  72. /* Prototypes for functions defined in function.c */
  73. void cprin(FILE *, char *prefix, char *suffix, Complex z);
  74. Complex printres(Complex z);
  75. Complex precision(Complex z), cinteger(Complex z),
  76.     cceil(Complex z), cfloor(Complex z),
  77.     csign(Complex z), gettime(Complex lasttime);
  78.  
  79. /* Prototypes for functions defined in cmath.c */
  80. Complex    Re(Complex z), Im(Complex z),
  81.     arg(Complex z), norm(Complex z),
  82.     cabs(Complex z), cadd(Complex w, Complex z),
  83.     csub(Complex w, Complex z), cmul(Complex w, Complex z),
  84.     cdiv(Complex w, Complex z), cneg(Complex z),
  85.     csqr(Complex z), csqrt(Complex z),
  86.     conj(Complex z), cexp(Complex z),
  87.     clog(Complex z), cpow(Complex w, Complex z),
  88.     csin(Complex z), ccos(Complex z),
  89.     ctan(Complex z), casin(Complex z),
  90.     cacos(Complex z), catan(Complex z),
  91.     csinh(Complex z), ccosh(Complex z),
  92.     ctanh(Complex z)
  93.     ;
  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. ArgList *addarg(ArgList *al, Node *n);
  131. Complex eval_tree(Node *n);
  132. void delete_tree(Node *n);
  133.  
  134. /* Prototypes for functions defined in function.c */
  135. void clear_ufunc(UserFunc *func);
  136. SymList *addparam(SymList *sl, Symbol *s);
  137. void init_ufunc(UserFunc *func);
  138. Symbol *findsym(SymList *sl, char *s);
  139.  
  140. /* Prototypes for functions defined in special.c */
  141. Complex spec_sum(ArgList *al);
  142. Complex spec_prod(ArgList *al);
  143. Complex spec_every(ArgList *al);
  144. Complex spec_vevery(ArgList *al);
  145. Complex spec_multi(ArgList *al);
  146. Complex spec_max(ArgList *al);
  147. Complex spec_min(ArgList *al);
  148.