1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California.  All rights reserved.
4 Authors: 1987 Wayne A. Christopher
5          1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8 /*
9  * These definitions specify the format of the parse tree parameter type.
10  * The first four are the elements of IFparseTree, defined in IFsim.h.
11  */
12 
13 #include "ifsim.h"
14 
15 #ifndef INP_PARSE
16 #define INP_PARSE
17 
18 
19 /* This is the parameter value passed to the device routines.  To get the
20  * value of the function, where tree is a pointer to the INPparseTree,
21  * result is a pointer to where you want the result, derivs is a pointer to
22  * an vector of numVars doubles, and vals is a pointer to the selected
23  * elements from the RHS, do
24  *  tree->p.IFeval(&tree, result, vals, derivs)
25  * This routine will return either OK, E_PARMVAL, or E_PANIC.  If an error
26  * is reported the eval function will have printed something to standard
27  * out before returning.
28  */
29 
30 typedef struct INPparseTree {
31     IFparseTree p;
32     struct INPparseNode *tree;    /* The real stuff. */
33     struct INPparseNode **derivs; /* The derivative parse trees. */
34 } INPparseTree;
35 
36 /* This is what is passed as the actual parameter value.  The fields will all
37  * be filled in as needed.
38  *
39  * Values with names like v(something) and i(something) are treated specially.
40  * They are considered voltages at nodes and branch currents through
41  * voltage sources, respectively.  The corresponding parameters will be of
42  * type IF_NODE and IF_INSTANCE, respectively.
43  */
44 
45 typedef struct INPparseNode {
46     int type;                   /* One of PT_*, below. */
47     struct INPparseNode *left;  /* Left operand, or single operand. */
48     struct INPparseNode *right; /* Right operand, if there is one. */
49     double constant;            /* If INP_CONSTANT. */
50     int valueIndex;             /* If INP_VAR, index into vars array. */
51     char *funcname;             /* If INP_FUNCTION, name of function, */
52     int funcnum;                /* ... one of PTF_*, */
53     int (*evfunc)();            /* called during evaluation */
54     double (*function)();       /* ... and pointer to the function. */
55     double *trancoeffs;         /* tran function parameters (as input). */
56     double *tranparms;          /* tran function run time parameters. */
57     double *trancache;          /* cached stuff for tran evaluation. */
58     int numtrancoeffs;          /* number of tran parameters input. */
59     int pwlindex;               /* index into pwl tran func array. */
60     int new_deriv;              /* nonzero if created after parse. */
61 } INPparseNode;
62 
63 /* These are the possible types of nodes we can have in the parse tree.  The
64  * numbers for the ops 1 - 5 have to be the same as the token numbers,
65  * below.
66  */
67 
68 #define PT_PLACEHOLDER  0       /* For i(something) ... */
69 #define PT_PLUS     1
70 #define PT_MINUS    2
71 #define PT_TIMES    3
72 #define PT_DIVIDE   4
73 #define PT_POWER    5
74 #define PT_FUNCTION 6
75 #define PT_CONSTANT 7
76 #define PT_VAR      8
77 #define PT_PARAM    9
78 #define PT_COMMA    10
79 #define PT_TFUNC    11
80 #define PT_TABLE    12
81 
82 /* These are the functions that we support. */
83 
84 #define PTF_ACOS    0
85 #define PTF_ACOSH   1
86 #define PTF_ASIN    2
87 #define PTF_ASINH   3
88 #define PTF_ATAN    4
89 #define PTF_ATANH   5
90 #define PTF_COS     6
91 #define PTF_COSH    7
92 #define PTF_EXP     8
93 #define PTF_LN      9
94 #define PTF_LOG     10
95 #define PTF_SIN     11
96 #define PTF_SINH    12
97 #define PTF_SQRT    13
98 #define PTF_TAN     14
99 #define PTF_TANH    15
100 #define PTF_UMINUS  16
101 #define PTF_ABS     17
102 #define PTF_SGN     18
103 
104 /* These are the tran functions that we support. */
105 
106 #define PTF_tPULSE  1
107 #define PTF_tPWL    2
108 #define PTF_tSIN    3
109 #define PTF_tSPULSE 4
110 #define PTF_tEXP    5
111 #define PTF_tSFFM   6
112 
113 /* The following things are used by the parser --
114  * these are the token types the
115  * lexer returns.
116  */
117 
118 #define TOK_END         0
119 #define TOK_PLUS        1
120 #define TOK_MINUS       2
121 #define TOK_TIMES       3
122 #define TOK_DIVIDE      4
123 #define TOK_POWER       5
124 #define TOK_UMINUS      6
125 #define TOK_LPAREN      7
126 #define TOK_RPAREN      8
127 #define TOK_VALUE       9
128 #define TOK_COMMA       10
129 
130 /* And the types for value tokens... */
131 
132 #define TYP_NUM         0
133 #define TYP_STRING      1
134 #define TYP_PNODE       2
135 
136 /* A parser stack element. */
137 
138 typedef struct PTelement {
139     int token;
140     int type;
141     union {
142         char *string;
143         double real;
144         INPparseNode *pnode;
145     } value;
146 } PTelement ;
147 
148 #define PT_STACKSIZE 200
149 
150 struct sPTfunc {
151     char *name;
152     int number;
153     double (*funcptr)();
154 };
155 extern struct sPTfunc PTfuncs[];
156 extern struct sPTfunc PTtFuncs[];
157 
158 struct sPTop {
159     int number;
160     char *name;
161     double (*funcptr)();
162 };
163 extern struct sPTop PTops[];
164 
165 #ifdef __STDC__
166 extern int IFinit(IFparseTree *, double, double);
167 extern int IFeval(IFparseTree *, double, double*, double*, double*, double*);
168 extern void IFfree(IFparseTree *);
169 #else /* stdc */
170 extern int IFinit();
171 extern int IFeval();
172 extern void IFfree();
173 #endif /* stdc */
174 
175 #endif
176 
177