Back to index

radiance  4R0+20100331
calcomp.h
Go to the documentation of this file.
00001 /* RCSid $Id: calcomp.h,v 2.22 2008/05/01 16:42:05 greg Exp $ */
00002 /*
00003  *  calcomp.h - header file for expression parser.
00004  */
00005 #ifndef _RAD_CALCOMP_H_
00006 #define _RAD_CALCOMP_H_
00007 
00008 #include <stdio.h>
00009 
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013 
00014 #define        VAR          1
00015 #define        NUM          2
00016 #define        UMINUS              3
00017 #define        CHAN         4
00018 #define        FUNC         5
00019 #define        ARG          6
00020 #define        CLKT         7
00021 #define        SYM          8
00022                             /* also: '+', '-', '*', '/', '^', '=', ':' */
00023 
00024 typedef struct {
00025     char  *fname;           /* function name */
00026     short  nargs;           /* # of required arguments */
00027     short  atyp;            /* assignment type (':' or '=') */
00028     double  (*f)(char *);   /* pointer to function */
00029 }  LIBR;             /* a library function */
00030 
00031 typedef struct epnode {
00032     union {
00033        struct epnode  *kid; /* first child */
00034        double num;          /* number */
00035        char  *name;         /* symbol name */
00036        int  chan;           /* channel number */
00037        unsigned long  tick; /* timestamp */
00038        struct vardef {
00039            char  *name;            /* variable name */
00040            int        nlinks;             /* number of references */
00041            struct epnode  *def;    /* definition */
00042            LIBR  *lib;                    /* library definition */
00043            struct vardef  *next;   /* next in hash list */
00044        }  *ln;                     /* link */
00045     } v;             /* value */
00046     struct epnode  *sibling;       /* next child this level */
00047     int        type;               /* node type */
00048 }  EPNODE;    /* an expression node */
00049 
00050 typedef struct vardef  VARDEF;     /* a variable definition */
00051 
00052 #define        RMAXWORD     127           /* maximum word/id length */
00053 #define        CNTXMARK     '`'           /* context mark */
00054 
00055 #define        isid(c)      (isalnum(c) || (c) == '_' || \
00056                      (c) == '.' || (c) == CNTXMARK)
00057 
00058 #define        evalue(ep)   (*eoper[(ep)->type])(ep)
00059 
00060                                    /* flags to set in esupport */
00061 #define  E_VARIABLE  001
00062 #define  E_FUNCTION  002
00063 #define  E_INCHAN    004
00064 #define  E_OUTCHAN   010
00065 #define  E_RCONST    020
00066 #define  E_REDEFW    040
00067 
00068 extern double  (*eoper[])(EPNODE *);
00069 extern unsigned long  eclock;
00070 extern unsigned int  esupport;
00071 extern EPNODE *curfunc;
00072 extern int  nextc;
00073 extern int  eofc;
00074 
00075                                    /* defined in biggerlib.c */
00076 extern void biggerlib(void);
00077 
00078                                    /* defined in caldefn.c */
00079 extern void   fcompile(char *fname);
00080 extern void   scompile(char *str, char *fname, int ln);
00081 extern double varvalue(char *vname);
00082 extern double evariable(EPNODE *ep);
00083 extern void   varset(char *vname, int assign, double val);
00084 extern void   dclear(char *name);
00085 extern void   dremove(char *name);
00086 extern int    vardefined(char *name);
00087 extern char   *setcontext(char *ctx);
00088 extern char   *pushcontext(char *ctx);
00089 extern char   *popcontext(void);
00090 extern char   *qualname(char *nam, int lvl);
00091 extern int    incontext(char *qn);
00092 extern void   chanout(void (*cs)(int n, double v));
00093 extern void   dcleanup(int lvl);
00094 extern EPNODE *dlookup(char *name);
00095 extern VARDEF *varlookup(char *name);
00096 extern VARDEF *varinsert(char *name);
00097 extern void   varfree(VARDEF *ln);
00098 extern EPNODE *dfirst(void);
00099 extern EPNODE *dnext(void);
00100 extern EPNODE *dpop(char *name);
00101 extern void   dpush(char *nm, EPNODE *ep);
00102 extern void   addchan(EPNODE *sp);
00103 extern void   getstatement(void);
00104 extern EPNODE *getdefn(void);
00105 extern EPNODE *getchan(void);
00106                                    /* defined in calexpr.c */
00107 extern EPNODE *eparse(char *expr);
00108 extern double eval(char *expr);
00109 extern int    epcmp(EPNODE *ep1, EPNODE *ep2);
00110 extern void   epfree(EPNODE *epar);
00111 extern EPNODE *ekid(EPNODE *ep, int n);
00112 extern int    nekids(EPNODE *ep);
00113 extern void   initfile(FILE *fp, char *fn, int ln);
00114 extern void   initstr(char *s, char *fn, int ln);
00115 extern void   getscanpos(char **fnp, int *lnp, char **spp, FILE **fpp);
00116 extern int    scan(void);
00117 extern char   *long2ascii(long l);
00118 extern void   syntax(char *err);
00119 extern void   addekid(EPNODE *ep, EPNODE *ekid);
00120 extern char   *getname(void);
00121 extern int    getinum(void);
00122 extern double getnum(void);
00123 extern EPNODE *getE1(void);
00124 extern EPNODE *getE2(void);
00125 extern EPNODE *getE3(void);
00126 extern EPNODE *getE4(void);
00127 extern EPNODE *getE5(void);
00128 extern EPNODE *rconst(EPNODE *epar);
00129 extern int    isconstvar(EPNODE *ep);
00130 extern int    isconstfun(EPNODE *ep);
00131                                    /* defined in calfunc.c */
00132 extern int    fundefined(char *fname);
00133 extern double funvalue(char *fname, int n, double *a);
00134 extern void   funset(char *fname, int nargs, int assign,
00135                             double (*fptr)(char *));
00136 extern int    nargum(void);
00137 extern double argument(int n);
00138 extern VARDEF *argf(int n);
00139 extern char   *argfun(int n);
00140 extern double efunc(EPNODE *ep);
00141 extern LIBR   *liblookup(char *fname);
00142 extern void   libupdate(char *fn);
00143                                    /* defined in calprnt.c */
00144 extern void   eprint(EPNODE *ep, FILE *fp);
00145 extern void   dprint(char *name, FILE *fp);
00146                                    /* defined by client */
00147 extern double chanvalue(int n);
00148 
00149 
00150 #ifdef __cplusplus
00151 }
00152 #endif
00153 #endif /* _RAD_CALCOMP_H_ */
00154