| 1 |
schorsch |
2.13 |
/* RCSid $Id: calcomp.h,v 2.12 2003/06/30 19:04:29 greg Exp $ */ |
| 2 |
greg |
1.1 |
/* |
| 3 |
|
|
* calcomp.h - header file for expression parser. |
| 4 |
greg |
2.6 |
*/ |
| 5 |
schorsch |
2.9 |
#ifndef _RAD_CALCOMP_H_ |
| 6 |
|
|
#define _RAD_CALCOMP_H_ |
| 7 |
|
|
#ifdef __cplusplus |
| 8 |
|
|
extern "C" { |
| 9 |
|
|
#endif |
| 10 |
greg |
2.7 |
|
| 11 |
greg |
2.2 |
#define VAR 1 |
| 12 |
|
|
#define NUM 2 |
| 13 |
|
|
#define UMINUS 3 |
| 14 |
|
|
#define CHAN 4 |
| 15 |
|
|
#define FUNC 5 |
| 16 |
|
|
#define ARG 6 |
| 17 |
|
|
#define TICK 7 |
| 18 |
|
|
#define SYM 8 |
| 19 |
greg |
1.4 |
/* also: '+', '-', '*', '/', '^', '=', ':' */ |
| 20 |
greg |
1.1 |
|
| 21 |
|
|
typedef struct { |
| 22 |
|
|
char *fname; /* function name */ |
| 23 |
greg |
1.5 |
short nargs; /* # of required arguments */ |
| 24 |
|
|
short atyp; /* assignment type (':' or '=') */ |
| 25 |
greg |
1.1 |
double (*f)(); /* pointer to function */ |
| 26 |
|
|
} LIBR; /* a library function */ |
| 27 |
|
|
|
| 28 |
|
|
typedef struct epnode { |
| 29 |
greg |
2.2 |
int type; /* node type */ |
| 30 |
greg |
1.1 |
struct epnode *sibling; /* next child this level */ |
| 31 |
|
|
union { |
| 32 |
|
|
struct epnode *kid; /* first child */ |
| 33 |
greg |
2.2 |
double num; /* number */ |
| 34 |
greg |
1.1 |
char *name; /* symbol name */ |
| 35 |
|
|
int chan; /* channel number */ |
| 36 |
greg |
2.4 |
unsigned long tick; /* timestamp */ |
| 37 |
greg |
1.1 |
struct vardef { |
| 38 |
|
|
char *name; /* variable name */ |
| 39 |
greg |
2.2 |
int nlinks; /* number of references */ |
| 40 |
greg |
1.1 |
struct epnode *def; /* definition */ |
| 41 |
|
|
LIBR *lib; /* library definition */ |
| 42 |
|
|
struct vardef *next; /* next in hash list */ |
| 43 |
|
|
} *ln; /* link */ |
| 44 |
|
|
} v; /* value */ |
| 45 |
|
|
} EPNODE; /* an expression node */ |
| 46 |
|
|
|
| 47 |
|
|
typedef struct vardef VARDEF; /* a variable definition */ |
| 48 |
|
|
|
| 49 |
schorsch |
2.13 |
#define RMAXWORD 127 /* maximum word/id length */ |
| 50 |
greg |
2.2 |
#define CNTXMARK '`' /* context mark */ |
| 51 |
greg |
1.6 |
|
| 52 |
greg |
2.2 |
#define isid(c) (isalnum(c) || (c) == '_' || \ |
| 53 |
greg |
1.6 |
(c) == '.' || (c) == CNTXMARK) |
| 54 |
|
|
|
| 55 |
greg |
2.6 |
#define evalue(ep) (*eoper[(ep)->type])(ep) |
| 56 |
|
|
|
| 57 |
|
|
/* flags to set in esupport */ |
| 58 |
|
|
#define E_VARIABLE 001 |
| 59 |
|
|
#define E_FUNCTION 002 |
| 60 |
|
|
#define E_INCHAN 004 |
| 61 |
|
|
#define E_OUTCHAN 010 |
| 62 |
|
|
#define E_RCONST 020 |
| 63 |
|
|
#define E_REDEFW 040 |
| 64 |
|
|
|
| 65 |
greg |
1.1 |
extern double (*eoper[])(); |
| 66 |
greg |
2.4 |
extern unsigned long eclock; |
| 67 |
greg |
2.6 |
extern unsigned int esupport; |
| 68 |
|
|
extern EPNODE *curfunc; |
| 69 |
greg |
1.1 |
extern int nextc; |
| 70 |
|
|
|
| 71 |
greg |
2.6 |
/* defined in caldefn.c */ |
| 72 |
|
|
extern void fcompile(char *fname); |
| 73 |
|
|
extern void scompile(char *str, char *fname, int ln); |
| 74 |
|
|
extern double varvalue(char *vname); |
| 75 |
|
|
extern double evariable(EPNODE *ep); |
| 76 |
|
|
extern void varset(char *fname, int assign, double val); |
| 77 |
|
|
extern void dclear(char *name); |
| 78 |
|
|
extern void dremove(char *name); |
| 79 |
|
|
extern int vardefined(char *name); |
| 80 |
|
|
extern char *setcontext(char *ctx); |
| 81 |
|
|
extern char *pushcontext(char *ctx); |
| 82 |
|
|
extern char *popcontext(void); |
| 83 |
|
|
extern char *qualname(char *nam, int lvl); |
| 84 |
|
|
extern int incontext(char *qn); |
| 85 |
greg |
2.8 |
extern void chanout(void (*cs)(int n, double v)); |
| 86 |
greg |
2.6 |
extern void dcleanup(int lvl); |
| 87 |
|
|
extern EPNODE *dlookup(char *name); |
| 88 |
|
|
extern VARDEF *varlookup(char *name); |
| 89 |
|
|
extern VARDEF *varinsert(char *name); |
| 90 |
|
|
extern void varfree(VARDEF *ln); |
| 91 |
|
|
extern EPNODE *dfirst(void); |
| 92 |
|
|
extern EPNODE *dnext(void); |
| 93 |
|
|
extern EPNODE *dpop(char *name); |
| 94 |
|
|
extern void dpush(char *nm, EPNODE *ep); |
| 95 |
|
|
extern void addchan(EPNODE *sp); |
| 96 |
|
|
extern void getstatement(); |
| 97 |
|
|
extern EPNODE *getdefn(); |
| 98 |
|
|
extern EPNODE *getchan(); |
| 99 |
|
|
/* defined in calexpr.c */ |
| 100 |
|
|
extern EPNODE *eparse(char *expr); |
| 101 |
|
|
extern double eval(char *expr); |
| 102 |
|
|
extern int epcmp(EPNODE *ep1, EPNODE *ep2); |
| 103 |
|
|
extern void epfree(EPNODE *epar); |
| 104 |
|
|
extern EPNODE *ekid(EPNODE *ep, int n); |
| 105 |
|
|
extern int nekids(EPNODE *ep); |
| 106 |
|
|
extern void initfile(FILE *fp, char *fn, int ln); |
| 107 |
|
|
extern void initstr(char *s, char *fn, int ln); |
| 108 |
|
|
extern void getscanpos(char **fnp, int *lnp, char **spp, FILE **fpp); |
| 109 |
|
|
extern int scan(void); |
| 110 |
|
|
extern char *long2ascii(long l); |
| 111 |
|
|
extern void syntax(char *err); |
| 112 |
|
|
extern void addekid(EPNODE *ep, EPNODE *ekid); |
| 113 |
|
|
extern char *getname(void); |
| 114 |
|
|
extern int getinum(void); |
| 115 |
|
|
extern double getnum(void); |
| 116 |
|
|
extern EPNODE *getE1(void); |
| 117 |
|
|
extern EPNODE *getE2(void); |
| 118 |
|
|
extern EPNODE *getE3(void); |
| 119 |
|
|
extern EPNODE *getE4(void); |
| 120 |
|
|
extern EPNODE *getE5(void); |
| 121 |
|
|
extern EPNODE *rconst(EPNODE *epar); |
| 122 |
|
|
extern int isconstvar(EPNODE *ep); |
| 123 |
|
|
extern int isconstfun(EPNODE *ep); |
| 124 |
|
|
/* defined in calfunc.c */ |
| 125 |
|
|
extern int fundefined(char *fname); |
| 126 |
|
|
extern double funvalue(char *fname, int n, double *a); |
| 127 |
|
|
extern void funset(char *fname, int nargs, int assign, double (*fptr)()); |
| 128 |
|
|
extern int nargum(void); |
| 129 |
|
|
extern double argument(int n); |
| 130 |
|
|
extern VARDEF *argf(int n); |
| 131 |
|
|
extern char *argfun(int n); |
| 132 |
|
|
extern double efunc(EPNODE *ep); |
| 133 |
|
|
extern LIBR *liblookup(char *fname); |
| 134 |
|
|
extern void libupdate(char *fn); |
| 135 |
|
|
/* defined in calprnt.c */ |
| 136 |
|
|
extern void eprint(EPNODE *ep, FILE *fp); |
| 137 |
|
|
extern void dprint(char *name, FILE *fp); |
| 138 |
|
|
/* defined in savestr.c */ |
| 139 |
|
|
extern char *savestr(char *str); |
| 140 |
|
|
extern void freestr(char *s); |
| 141 |
|
|
extern int shash(char *s); |
| 142 |
|
|
/* defined in ealloc.c */ |
| 143 |
|
|
extern char *emalloc(unsigned int n); |
| 144 |
|
|
extern char *ecalloc(unsigned int ne, unsigned int es); |
| 145 |
|
|
extern char *erealloc(char *cp, unsigned int n); |
| 146 |
|
|
extern void efree(char *cp); |
| 147 |
|
|
/* miscellaneous */ |
| 148 |
|
|
extern void eputs(char *s); |
| 149 |
|
|
extern void wputs(char *s); |
| 150 |
|
|
extern void quit(int code); |
| 151 |
|
|
/* defined by client */ |
| 152 |
|
|
extern double chanvalue(int n); |
| 153 |
|
|
|
| 154 |
schorsch |
2.9 |
|
| 155 |
|
|
#ifdef __cplusplus |
| 156 |
|
|
} |
| 157 |
greg |
2.6 |
#endif |
| 158 |
schorsch |
2.9 |
#endif /* _RAD_CALCOMP_H_ */ |
| 159 |
|
|
|