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
21 /* eqn.h, equation parsing and evaluation
25 #ifndef __EQUATIONS_H__
27 #define __EQUATIONS_H__
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 */
65 OPnorm
, /* a $ b == pow(pow(a,b),1/b) */
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", \
78 #define OPprecidence { 0, 0, 0, 0, \
86 #define OPtype { 0, 1, 1, 0, \
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
106 typedef struct eqntokenval_st
111 typedef struct eqntokenpval_st
116 typedef struct eqntoken_st
128 #define EQN_DELIM '\''
130 #define MAXEQNSTACK 512
131 typedef struct eqntop_st
138 eqntoken_t nodes
[MAXEQNSTACK
];
147 typedef struct eqneval_st
149 float stack
[MAXSTACK
];
156 typedef struct eqn_st
162 /* for named equations */
163 typedef struct eqndef_st
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
);