home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / p / p064 / 3.ddi / EXPRS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-01  |  5.6 KB  |  200 lines

  1. /****************************************************************************/
  2. /*        Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991                  */
  3. /*          By MicroSim Corporation, All Rights Reserved                    */
  4. /****************************************************************************/
  5. /* exprs.h
  6.  *   $Revision:   1.10  $
  7.  *   $Author:   sv  $
  8.  *   $Date:   11 Apr 1991 15:10:52  $ */
  9.  
  10. /******************* USERS OF DEVICE EQUATIONS OPTION ***********************/
  11. /********         Do not change this file           **********/
  12.  
  13. /* Expression definitions */
  14.  
  15. struct expcnst {        /* constant struct */
  16.   int        type;        /* type: CNSTRING, CNFLOAT */
  17. #define CNSTRING    1
  18. #define CNFLOAT     2
  19.   union        {
  20.     char    *str;
  21.     double    flt;
  22.     }
  23.         data;          /* Data value */
  24.   };
  25.  
  26. struct SP_ExpDef {
  27.   int        EXtype;     /* EXCNST, EXPRM, or EXSRC */
  28.   char        *EXtext;    /* Text of expression */
  29.   int        EXnrvp;     /* Length of rvp */
  30.   int        *EXrvp;     /* Reverse polish expression */
  31.   int        EXncnst;    /* Number of constants */
  32.   struct expcnst *EXcnst;    /* Constants used by expression */
  33.   };
  34. typedef struct SP_ExpDef EXPR;
  35.  
  36. #define EXCNST    1        /* has: constants only */
  37. #define EXPRM    2        /* has: global symbols, constants */
  38. #define EXLAPL    3        /* has: "s", global symbols, constants */
  39. #define EXSRC    4        /* has: variables, globals, constants */
  40. #define EXSTRING 5        /* string (TEXT) value expression */
  41. #define EXSTRCNST 6        /* string expression -- constants only */
  42.  
  43. /* Generalized value definitions */
  44.  
  45. typedef struct value {
  46.   union        {
  47.     char        *str;
  48.     double        flt;
  49.     }
  50.             val;        /* use this if expr is NULL */
  51.   struct SP_ExpDef    *expr;        /* pre-parsed stuff to evaluate */
  52.   } VALUE;                /* or NULL if constant */
  53.  
  54. /* For type punning in readin, etc: */
  55. /* dvalue has double, then expr ptr */
  56. /* mvalue has MDLPARM, then expr ptr */
  57.  
  58. struct dvalue {
  59.   double        val;
  60.   struct SP_ExpDef    *expr;
  61.   };
  62.  
  63. struct mvalue {
  64.   MDLPARM        val;
  65.   struct SP_ExpDef    *expr;
  66.   };
  67.  
  68. struct svalue {         /* string value */
  69.   char            *val;
  70.   struct SP_ExpDef    *expr;
  71.   };
  72.  
  73. /* declarator macros for (double,expr) and (modelpar,expr) pairs */
  74. #define DXPR(d,e)    double d;  EXPR *e
  75. #define MXPR(m,e)    MDLPARM m; EXPR *e
  76. #define SXPR(s,e)    char *s;   EXPR *e
  77.  
  78. /* Definitions for stack(s) used during expression evaluation */
  79.  
  80. #define EXMSTK    40        /* Max. size of stack */
  81.  
  82. /* Expression operators */
  83.  
  84. #define EXEND    -1
  85. #define EXNOOP    -2
  86. #define EXADD    -3
  87. #define EXSUB    -4
  88. #define EXMLT    -5
  89. #define EXDVD    -6
  90. #define EXABS    -7
  91. #define EXMNS    -8
  92. #define EXPLS    -9
  93. #define EXCNS    -10
  94.  
  95. #define EXPARAM -11
  96. #define EXTIME    -12
  97. #define EXS    -13
  98.  
  99. #define EXEXP    -19
  100. #define EXLOG    -20
  101. #define EXLOG10 -21
  102. #define EXPWR    -22
  103. #define EXPWRS    -23
  104. #define EXPWR2    -24
  105. #define EXSQRT    -25
  106. #define EXSIN    -26
  107. #define EXCOS    -27
  108. #define EXTAN    -28
  109. #define EXATAN    -29
  110.  
  111. #define EXSTRPARM -30    /* string type parm */
  112. #define EXCONCAT  -31    /* string concatenation */
  113. #define EXSTRINT  -32    /* string value of flt */
  114. #define EXSTRCNS  -33    /* string constant value */
  115. #define EXSTREND  -34    /* string end */
  116.  
  117. /* table of predefined identifiers (for behavioral modelling) */
  118. GLOBAL struct {
  119.   char *iname;
  120.   char itype;      /* function or sweepvar */
  121. #define IDFUNC 0
  122. #define IDSVAR 1
  123. #define IDRSVD 2  /* reserved, will be global params later */
  124. #define IDSTRFUNC 3 /* string value function */
  125.   int  iargs;      /* # args */
  126.   int  iopcode;   /* RPN opcode */
  127.   int  arg1type;  /* type of arg 1: ARGFLOAT or ARGSTRING */
  128.   int  arg2type;  /* type of arg 2 and up: ARGFLOAT or ARGSTRING */
  129. #define ARGFLOAT    1
  130. #define ARGSTRING    2
  131. #define ARGNONE     0
  132.   } Builtins[]
  133. #ifdef Main_Pgm
  134. =
  135. {
  136.     {"EXP",     IDFUNC,    1,        EXEXP,    ARGFLOAT, ARGNONE},
  137.     {"LOG",     IDFUNC,    1,        EXLOG,    ARGFLOAT, ARGNONE},
  138.     {"LOG10",     IDFUNC,    1,        EXLOG10,    ARGFLOAT, ARGNONE},
  139.     {"PWR",     IDFUNC,    2,        EXPWR,    ARGFLOAT, ARGFLOAT},
  140.     {"PWRS",     IDFUNC,    2,        EXPWRS,    ARGFLOAT, ARGFLOAT},
  141.     {"SQRT",     IDFUNC,    1,        EXSQRT,    ARGFLOAT, ARGNONE},
  142.     {"SIN",     IDFUNC,    1,        EXSIN,    ARGFLOAT, ARGNONE},
  143.     {"COS",     IDFUNC,    1,        EXCOS,    ARGFLOAT, ARGNONE},
  144.     {"TAN",     IDFUNC,    1,        EXTAN,    ARGFLOAT, ARGNONE},
  145.     {"ATAN",     IDFUNC,    1,        EXATAN,    ARGFLOAT, ARGNONE},
  146.     {"ARCTAN",     IDFUNC,    1,        EXATAN,    ARGFLOAT, ARGNONE},
  147.     {"ABS",     IDFUNC,    1,        EXABS,    ARGFLOAT, ARGNONE},
  148.     {"TIME",     IDSVAR,    0,        EXTIME,    ARGNONE,  ARGNONE},
  149.     {"S",     IDSVAR,    0,        EXS,    ARGNONE,  ARGNONE},
  150.     {" TEMP",     IDRSVD,    0,        0,        ARGNONE,  ARGNONE},
  151.     {" VT",     IDRSVD,    0,        0,        ARGNONE,  ARGNONE},
  152.     {"TEXTINT",  IDSTRFUNC, 1,        EXSTRINT,    ARGFLOAT, ARGNONE}
  153. }
  154. #endif
  155.   ;
  156.  
  157. GLOBAL int NBuiltins
  158. #ifdef Main_Pgm
  159. = (sizeof Builtins)/(sizeof(Builtins[0]))
  160. #endif
  161.   ;
  162.  
  163. /* parameter-related definitions: */
  164.  
  165. /* used in par_type field in ParDef */
  166. #define PARGLOB     0
  167. #define PARLOC        1
  168. #define PARANY        2
  169. #define PARSTRGLOB    3
  170. #define PARSTRLOC    4
  171. #define PARSTRANY    5
  172.  
  173. /* ParDef is returned by AddParam, used for Globals params */
  174. struct ParDef {
  175.   struct ParDef *par_next;
  176.     struct SymTabE *stp;
  177.     int par_index;
  178.     int par_type;
  179.     int freeable;    /* if OK to free expr part of value */
  180.     struct value par_value;
  181. };
  182.  
  183. /* ParLocDef is used by .subckt and x_dev to maintain lists of locals */
  184. struct ParLocDef {
  185.   struct ParLocDef *parloc_next;
  186.   struct SymTabE *stlp;
  187.   int marked;
  188.   int type;    /* float or string: PARLOC or PARSTRLOC */
  189.   struct value parloc_value;
  190. };
  191.  
  192. /* YES if want to save expression text
  193.    NO if do not save */
  194. GLOBAL int    SP_ExprSaveText
  195. #ifdef Main_Pgm
  196. = NO
  197. #endif
  198. ;
  199.  
  200.