Corrected a long-standing error in which ending text with a literal
[xcircuit.git] / spiceparser / equations.h
blob908e34099fecf1e93f16289931fcd2128c43f8b6
1 /********************
2 This file is part of the software library CADLIB written by Conrad Ziesler
3 Copyright 2003, Conrad Ziesler, all rights reserved.
5 *************************
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ******************/
21 /* eqn.h, equation parsing and evaluation
22 Conrad Ziesler
25 #ifndef __EQUATIONS_H__
27 #define __EQUATIONS_H__
32 #ifndef __LIST_H__
33 #include "list.h"
34 #endif
36 #ifndef __NAMES_H__
37 #include "names.h"
38 #endif
40 #ifndef __HASH_H__
41 #include "hash.h"
42 #endif
45 typedef enum itemop_e
47 OPeolist,
48 OPeol_const, /* special terminator, for constant (reduced memory usage) */
49 OPeol_valp, /* special terminator, for indirection (float *) */
50 OPeol_qty, /* for simplified decoding of eol */
52 OPlit,
53 OPlitm,
54 OPlitv, /* valp */
55 OPlitvm, /* -valp */
57 OPval,
58 OPvalm,
59 OPadd,
60 OPsub,
62 OPmul,
63 OPdiv,
64 OPexp,
65 OPnorm, /* a $ b == pow(pow(a,b),1/b) */
66 OPopen,
68 OPclose
69 }itemop_t;
71 #define OPsyms { "OPeolist", "OPeol_const", "OPeol_valp", "OPeol_qty", \
72 "OPlit", "OPlitm", "OPlitv", "OPlitvm", \
73 "OPval", "OPvalm", "OPadd", "OPsub", \
74 "OPmul", "OPdiv", "OPexp","OPnorm", "OPopen", \
75 "OPclose" \
78 #define OPprecidence { 0, 0, 0, 0, \
79 0, 0, 0, 0, \
80 0, 0, 1, 1, \
81 2, 2, 3, 3, 4, \
82 4 \
86 #define OPtype { 0, 1, 1, 0, \
87 1, -1, 1, -1, \
88 1, -1, 2, 2, \
89 2, 2, 2, 2, 4, \
90 4 \
93 #define OP_ISEV(a) (((a)>OPeolist) && ((a) < OPeol_qty) )
94 #define OP_ISV(a) (((a)>=OPlit) && ((a) <= OPvalm))
95 #define OP_ISEND(a) ( ((a)<=OPeol_qty) )
96 #define OP_ISANYV(a) (OP_ISV(a) || OP_ISEV(a))
100 typedef struct eqntokenlit_st
102 char *lit;
103 }eqntokenlit_t;
106 typedef struct eqntokenval_st
108 float x;
109 }eqntokenval_t;
111 typedef struct eqntokenpval_st
113 float *xp;
114 } eqntokenpval_t;
116 typedef struct eqntoken_st
118 itemop_t op;
119 union lit_val_un
121 eqntokenlit_t lit;
122 eqntokenval_t val;
123 eqntokenpval_t pval;
125 }eqntoken_t;
128 #define EQN_DELIM '\''
130 #define MAXEQNSTACK 512
131 typedef struct eqntop_st
133 char *str;
134 char unget[4];
135 int n_unget;
137 int errors;
138 eqntoken_t nodes[MAXEQNSTACK];
139 int nodep;
141 int litc;
142 int opc;
143 }eqntop_t;
146 #define MAXSTACK 512
147 typedef struct eqneval_st
149 float stack[MAXSTACK];
150 int stackp;
151 eqntoken_t *list;
153 }eqneval_t;
156 typedef struct eqn_st
158 float val;
159 eqntoken_t *eqn;
160 }eqn_t;
162 /* for named equations */
163 typedef struct eqndef_st
165 char *name;
166 eqn_t eqn;
167 }eqndef_t;
170 /* public interface */
171 eqn_t equation_parse(uchar *str);
172 int equation_depend(eqn_t eqn, float *(lookup)(void *user, char *str), void *user);
173 int equation_eval(eqn_t *peqn);
174 eqn_t equation_empty(eqn_t eqn);
175 void equation_debug(eqn_t eqn, void *fp);
176 #endif