[2510] | 1 | #include <stdlib.h>
|
---|
| 2 | #include <stdio.h>
|
---|
| 3 | #include <ctype.h>
|
---|
| 4 | #include <string.h>
|
---|
| 5 | #include "cexpre.h"
|
---|
| 6 | #include <stack>
|
---|
| 7 | #include <math.h>
|
---|
| 8 |
|
---|
| 9 | namespace SOPHYA {
|
---|
| 10 |
|
---|
| 11 | long CExprBase::totnexp_create = 0;
|
---|
| 12 | long CExprBase::totnexp_delete = 0;
|
---|
| 13 | CExprBase::CExprBase()
|
---|
| 14 | {
|
---|
| 15 | totnexp_create++;
|
---|
| 16 | // cout << "CExprBase::CExprBase()-Creation " << hex << this << dec << endl;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | CExprBase::~CExprBase()
|
---|
| 20 | {
|
---|
| 21 | totnexp_delete++;
|
---|
| 22 | // cout << "CExprBase::~CExprBase() " << hex << this << dec << endl;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | void CExprBase::CheckThrow(const char * msg) const
|
---|
| 26 | {
|
---|
| 27 | string errmsg;
|
---|
| 28 | bool ok = CheckE(errmsg);
|
---|
| 29 | if (ok) return;
|
---|
| 30 | else {
|
---|
| 31 | errmsg += msg;
|
---|
| 32 | throw CExprException(errmsg);
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | //---------------------------------------------------------
|
---|
| 37 | class CE_NumberExp : public CExprBase {
|
---|
| 38 | public:
|
---|
| 39 | CE_NumberExp(double v) { _val = v; }
|
---|
| 40 | CE_NumberExp(string const & s);
|
---|
| 41 | virtual ~CE_NumberExp() {}
|
---|
| 42 | virtual double Evaluate() const { return _val; }
|
---|
| 43 | virtual void Print(ostream& os) const { os << _val; }
|
---|
| 44 | protected:
|
---|
| 45 | double _val;
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 | CE_NumberExp::CE_NumberExp(string const & s)
|
---|
| 49 | {
|
---|
| 50 | size_t l = s.length();
|
---|
| 51 | if (l < 1) {
|
---|
| 52 | string errmsg = "CE_NumberExp::CE_NumberExp() Empty expression";
|
---|
| 53 | throw CExprException(errmsg);
|
---|
| 54 | }
|
---|
| 55 | if (s == "Pi") _val = M_PI;
|
---|
| 56 | else if (s == "E") _val = M_E;
|
---|
| 57 | else {
|
---|
| 58 | string errmsg = "CE_NumberExp::CE_NumberExp() Bad numerical constant: ";
|
---|
| 59 | errmsg += s;
|
---|
| 60 |
|
---|
[2518] | 61 | char* lcc;
|
---|
| 62 | _val = strtod(s.c_str(), &lcc);
|
---|
| 63 | if (*lcc != '\0') throw CExprException(errmsg);
|
---|
[2510] | 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | //---------------------------------------------------------
|
---|
| 69 | class CE_BinExp : public CExprBase {
|
---|
| 70 | public:
|
---|
| 71 | explicit CE_BinExp(char op, int prior);
|
---|
| 72 | virtual ~CE_BinExp() { if (_e1) delete _e1; if (_e2) delete _e2; }
|
---|
| 73 | inline void SetE1(CExprBase * e) { _e1 = e; }
|
---|
| 74 | inline void SetE2(CExprBase * e) { _e2 = e; }
|
---|
| 75 | virtual bool CheckE(string& errmsg) const;
|
---|
| 76 | virtual void Print(ostream& os) const;
|
---|
| 77 | inline char BOpC() const { return _bop; }
|
---|
| 78 | inline int Priority() const { return _priority; }
|
---|
| 79 | protected:
|
---|
| 80 | CExprBase * _e1;
|
---|
| 81 | CExprBase * _e2;
|
---|
| 82 | char _bop; // Caractere identificateur d'operation (+,-,*,/ ...)
|
---|
| 83 | int _priority; // Niveau de priorite: 1= +,- 2: *,/ 3: ^...
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | CE_BinExp::CE_BinExp(char op, int prior)
|
---|
| 87 | {
|
---|
| 88 | _e1 = NULL; _e2 = NULL;
|
---|
| 89 | _bop = op;
|
---|
| 90 | _priority = prior;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | bool CE_BinExp::CheckE(string& errmsg) const
|
---|
| 94 | {
|
---|
| 95 | if ((_e1 == NULL) || (_e2 == NULL)) {
|
---|
| 96 | errmsg += "CE_BinExp::CheckE: Binary expression-missing argument ";
|
---|
| 97 | return false;
|
---|
| 98 | }
|
---|
| 99 | return true;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | void CE_BinExp::Print(ostream& os) const
|
---|
| 103 | {
|
---|
| 104 | os << "(" << (*_e1) << _bop << (*_e2) << ")" ;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | //---------------------------------------------------------
|
---|
| 108 | class CE_AddExp : public CE_BinExp {
|
---|
| 109 | public:
|
---|
| 110 | CE_AddExp() : CE_BinExp('+',1) {}
|
---|
| 111 | virtual double Evaluate() const { CheckThrow("CE_AddExp::Evaluate"); return _e1->Evaluate()+_e2->Evaluate();
|
---|
| 112 | }
|
---|
| 113 | };
|
---|
| 114 | class CE_MulExp : public CE_BinExp {
|
---|
| 115 | public:
|
---|
| 116 | CE_MulExp() : CE_BinExp('*',2) {}
|
---|
| 117 | virtual double Evaluate() const { CheckThrow("CE_MulExp::Evaluate"); return _e1->Evaluate()*_e2->Evaluate(); }
|
---|
| 118 | };
|
---|
| 119 | class CE_SubExp : public CE_BinExp {
|
---|
| 120 | public:
|
---|
| 121 | CE_SubExp() : CE_BinExp('-',1) {}
|
---|
| 122 | virtual double Evaluate() const { CheckThrow("CE_SubExp::Evaluate"); return _e1->Evaluate()-_e2->Evaluate(); }
|
---|
| 123 | };
|
---|
| 124 | class CE_DivExp : public CE_BinExp {
|
---|
| 125 | public:
|
---|
| 126 | CE_DivExp() : CE_BinExp('/',2) {}
|
---|
| 127 | virtual double Evaluate() const { CheckThrow("CE_DivExp::Evaluate"); return _e1->Evaluate()/_e2->Evaluate(); }
|
---|
| 128 | };
|
---|
| 129 |
|
---|
| 130 | //---------------------------------------------------------
|
---|
| 131 | typedef double (* f0exp) ();
|
---|
| 132 | typedef double (* f1exp) (double x);
|
---|
| 133 | typedef double (* f2exp) (double x, double y);
|
---|
| 134 | typedef double (* f3exp) (double x, double y, double z);
|
---|
| 135 |
|
---|
| 136 | //---------------------------------------------------------
|
---|
| 137 | #define FMXARG 3
|
---|
| 138 | class CE_FuncExp : public CExprBase {
|
---|
| 139 | public:
|
---|
| 140 | CE_FuncExp(string const & func);
|
---|
| 141 | virtual ~CE_FuncExp();
|
---|
| 142 | virtual double Evaluate() const ;
|
---|
| 143 | inline void AddArg(CExprBase * e);
|
---|
| 144 | virtual bool CheckE(string& errmsg) const;
|
---|
| 145 | virtual void Print(ostream& os) const;
|
---|
| 146 | protected:
|
---|
| 147 | f0exp _f0;
|
---|
| 148 | f1exp _f1;
|
---|
| 149 | f2exp _f2;
|
---|
| 150 | f3exp _f3;
|
---|
| 151 | int _ne, _maxne;
|
---|
| 152 | CExprBase * _e[FMXARG];
|
---|
| 153 | string _fname;
|
---|
| 154 | };
|
---|
| 155 |
|
---|
| 156 | //---------------------------------------------------------
|
---|
| 157 | CE_FuncExp::CE_FuncExp(string const & func)
|
---|
| 158 | {
|
---|
| 159 | _ne = 0; _maxne = -1;
|
---|
| 160 | for(int k=0; k<FMXARG; k++) _e[k] = NULL;
|
---|
| 161 | _f0 = NULL;
|
---|
| 162 | _f1 = NULL;
|
---|
| 163 | _f2 = NULL;
|
---|
| 164 | _f3 = NULL;
|
---|
| 165 | if (func == "sin") _f1 = sin;
|
---|
| 166 | else if (func == "cos") _f1 = cos;
|
---|
| 167 | else if (func == "tan") _f1 = tan;
|
---|
| 168 | else if (func == "asin") _f1 = asin;
|
---|
| 169 | else if (func == "acos") _f1 = acos;
|
---|
| 170 | else if (func == "atan") _f1 = atan;
|
---|
| 171 | else if (func == "atan2") _f2 = atan2;
|
---|
[2518] | 172 | else if (func == "sqrt") _f1 = sqrt;
|
---|
| 173 | else if (func == "fabs") _f1 = fabs;
|
---|
| 174 | else if (func == "floor") _f1 = floor;
|
---|
[2510] | 175 | else if (func == "exp") _f1 = exp;
|
---|
| 176 | else if (func == "log") _f1 = log;
|
---|
| 177 | else if (func == "log10") _f1 = log10;
|
---|
| 178 | else if (func == "pow") _f2 = pow;
|
---|
[2518] | 179 | else if (func == "hypot") _f2 = hypot;
|
---|
| 180 | else if (func == "sinh") _f1 = sinh;
|
---|
| 181 | else if (func == "cosh") _f1 = cosh;
|
---|
| 182 | else if (func == "tanh") _f1 = tanh;
|
---|
[2510] | 183 | else {
|
---|
| 184 | string errmsg = "CE_FuncExp::CE_FuncExp() - Uknown function " ;
|
---|
| 185 | errmsg += func;
|
---|
| 186 | throw CExprException(errmsg);
|
---|
| 187 | }
|
---|
| 188 | if (_f0) _maxne = 0;
|
---|
| 189 | else if (_f1) _maxne = 1;
|
---|
| 190 | else if (_f2) _maxne = 2;
|
---|
| 191 | else if (_f3) _maxne = 3;
|
---|
| 192 | _fname = func;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | CE_FuncExp::~CE_FuncExp()
|
---|
| 197 | {
|
---|
| 198 | for(int k=0; k<FMXARG; k++) if (_e[k]) delete _e[k];
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | void CE_FuncExp::AddArg(CExprBase * e)
|
---|
| 202 | {
|
---|
| 203 | if ((e != NULL) && (_ne < _maxne)) { _e[_ne] = e; _ne++; }
|
---|
| 204 | else throw CExprException("CE_FuncExp::AddArg() e=NULL or too many arguments ");
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | double CE_FuncExp::Evaluate() const
|
---|
| 208 | {
|
---|
| 209 | if ((_ne != _maxne) || (_maxne < 1) ) {
|
---|
| 210 | throw CExprException("CE_FuncExp::Evaluate() - Wrong argument number ");
|
---|
| 211 | }
|
---|
| 212 | if (_ne == 1) return _f1(_e[0]->Evaluate());
|
---|
| 213 | else if (_ne == 2) return _f2(_e[0]->Evaluate(), _e[1]->Evaluate());
|
---|
| 214 | else if (_ne == 3) return _f3(_e[0]->Evaluate(), _e[1]->Evaluate(),
|
---|
| 215 | _e[2]->Evaluate());
|
---|
| 216 | else return 0.;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | bool CE_FuncExp::CheckE(string& errmsg) const
|
---|
| 220 | {
|
---|
| 221 | if ((_ne != _maxne) || (_maxne < 0) ) {
|
---|
| 222 | char buff[128];
|
---|
| 223 | sprintf(buff, "CE_FuncExp::CheckE() %s - Wrong argument number - ne=%d maxne=%d ",
|
---|
| 224 | _fname.c_str(), _ne, _maxne);
|
---|
| 225 | errmsg += buff;
|
---|
| 226 | return false;
|
---|
| 227 | }
|
---|
| 228 | return true;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | void CE_FuncExp::Print(ostream& os) const
|
---|
| 232 | {
|
---|
| 233 | if ((_ne != _maxne) || (_maxne < 1) )
|
---|
| 234 | os << _fname << "(ArgError)" ;
|
---|
| 235 | else {
|
---|
| 236 | if (_ne == 1) os << _fname << "(" << *(_e[0]) << ")";
|
---|
| 237 | else if (_ne == 2) os << _fname << "(" << *(_e[0]) << "," << *(_e[1]) << ")";
|
---|
| 238 | else if (_ne == 3) os << _fname << "(" << *(_e[0])
|
---|
| 239 | << "," << *(_e[1]) << "," << *(_e[2]) << ")";
|
---|
| 240 | }
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | //---------------------------------------------------------
|
---|
| 244 | CExpressionEvaluator::CExpressionEvaluator(string const & sex)
|
---|
| 245 | {
|
---|
| 246 | _exp = NULL;
|
---|
| 247 | size_t off=0,stop=0;
|
---|
| 248 | string fname = "";
|
---|
| 249 | string errmsg;
|
---|
| 250 | _exp= ParseString(0,fname,sex,off,stop,errmsg);
|
---|
| 251 | if (_exp == NULL) throw CExprException(errmsg);
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | CExpressionEvaluator::~CExpressionEvaluator()
|
---|
| 255 | {
|
---|
| 256 | if (_exp) delete _exp;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | double CExpressionEvaluator::Evaluate() const
|
---|
| 260 | {
|
---|
| 261 | if (_exp) return _exp->Evaluate();
|
---|
| 262 | else return 0.;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | void CExpressionEvaluator::Print(ostream& os) const
|
---|
| 266 | {
|
---|
| 267 | if (_exp) _exp->Print(os);
|
---|
| 268 | else os << "CExpressionEvaluator ???";
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | // cette fonction rearrange le stack des operations binaires en attente
|
---|
| 272 | CExprBase* Arrange_CE_BinExpStack(stack<CE_BinExp* >& sbx, CExprBase* cex, CE_BinExp* nbx)
|
---|
| 273 | {
|
---|
| 274 | while ( !sbx.empty() && (nbx->Priority() <= sbx.top()->Priority()) ) {
|
---|
| 275 | sbx.top()->SetE2(cex);
|
---|
| 276 | cex = sbx.top(); sbx.pop();
|
---|
| 277 | }
|
---|
| 278 | nbx->SetE1(cex);
|
---|
| 279 | sbx.push(nbx);
|
---|
| 280 | return NULL;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | // cette fonction rearrange le stack des operations binaires en attente
|
---|
| 284 | CExprBase* Arrange_CE_BinExpStack(stack<CE_BinExp* >& sbx, CExprBase* cex)
|
---|
| 285 | {
|
---|
| 286 | if (sbx.empty()) return cex;
|
---|
| 287 | while ( !sbx.empty() ) {
|
---|
| 288 | sbx.top()->SetE2(cex);
|
---|
| 289 | cex = sbx.top(); sbx.pop();
|
---|
| 290 | }
|
---|
| 291 | return cex;
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 | CExprBase* CExpressionEvaluator::ParseString(int extype, string fname, string const & sex,
|
---|
| 296 | size_t off, size_t& stop, string& errmsg)
|
---|
| 297 | {
|
---|
| 298 | size_t len = sex.length();
|
---|
| 299 | if (len < 1) {
|
---|
| 300 | string errmsg = "CExpressionEvaluator::ParseString() Empty expression";
|
---|
| 301 | throw CExprException(errmsg);
|
---|
| 302 | }
|
---|
[2515] | 303 | errmsg = "";
|
---|
[2510] | 304 | CExprBase* rx = NULL; // Expression resultat
|
---|
| 305 | stack< CE_BinExp* > sbx; // Stack des expressions binaires
|
---|
| 306 | CE_FuncExp* fx = NULL; // Expression fonction
|
---|
| 307 | CExprBase* cx = NULL; // Element d'expression (courante)
|
---|
| 308 |
|
---|
| 309 | if (extype == 2) fx = new CE_FuncExp(fname);
|
---|
| 310 |
|
---|
| 311 | size_t p=0, q=0;
|
---|
| 312 | char lastopc=0, opc=0; // Last/current operation sign (+,-,*,/,...)
|
---|
[2520] | 313 | int osn = 0;
|
---|
[2510] | 314 | bool finok = false;
|
---|
| 315 | bool fgcont = true;
|
---|
| 316 | bool checkok = true;
|
---|
| 317 | // cout << " DBG-ParseString off= " << off << " sex[off]= " << sex[off]
|
---|
| 318 | // << " extype= " << extype << endl;
|
---|
| 319 | p = stop = off;
|
---|
| 320 | while ((p < len) && (fgcont) && (checkok) ) {
|
---|
| 321 | // cout << " DBG-2-ParseString p=" << p << " q=" << q << endl;
|
---|
| 322 |
|
---|
| 323 | cx = NULL;
|
---|
| 324 | q = sex.find_first_of("+-*/(),",p);
|
---|
| 325 | if (q < len) { // operateur trouve
|
---|
| 326 | opc = sex[q]; // signe operateur courant
|
---|
| 327 | switch (opc) {
|
---|
| 328 | case '(' :
|
---|
| 329 | if (q == p) {
|
---|
| 330 | string fname = "";
|
---|
| 331 | cx = ParseString(1, fname, sex, q+1, stop, errmsg);
|
---|
| 332 | }
|
---|
| 333 | else cx = ParseString(2, sex.substr(p,q-p), sex, q+1, stop, errmsg);
|
---|
| 334 | if (!cx) { checkok = false; p = stop+1; }
|
---|
| 335 | else {
|
---|
| 336 | if (rx) {
|
---|
| 337 | checkok = false; p = stop+1; fgcont = false;
|
---|
| 338 | delete cx;
|
---|
| 339 | errmsg = "CExpressionEvaluator::ParseString()/ Syntax Error - rx&&cx (A)";
|
---|
| 340 | }
|
---|
| 341 | else {
|
---|
| 342 | if (stop == len-1) {
|
---|
| 343 | rx = Arrange_CE_BinExpStack(sbx, cx);
|
---|
| 344 | finok = true;
|
---|
| 345 | }
|
---|
| 346 | else rx = cx;
|
---|
[2520] | 347 | p = stop+1; osn = 0; lastopc = opc;
|
---|
[2510] | 348 | }
|
---|
| 349 | }
|
---|
| 350 | break;
|
---|
| 351 |
|
---|
| 352 | case ')' :
|
---|
| 353 | case ',' :
|
---|
| 354 | if (extype == 0) {
|
---|
| 355 | checkok = false; p = q; fgcont = false;
|
---|
| 356 | errmsg = "CExpressionEvaluator::ParseString() Unexpected ) or ,";
|
---|
| 357 | }
|
---|
| 358 | if ( (extype == 1) && (opc == ',')) {
|
---|
| 359 | checkok = false; p = q; fgcont = false;
|
---|
| 360 | errmsg = "CExpressionEvaluator::ParseString() Unexpected ,";
|
---|
| 361 | }
|
---|
| 362 | if ((q > p) && (rx)) {
|
---|
| 363 | checkok = false; p = q; fgcont = false;
|
---|
| 364 | errmsg = "CExpressionEvaluator::ParseString()/ Syntax Error - rx&&cx (B)";
|
---|
| 365 | }
|
---|
[2520] | 366 | if (q > p) cx = new CE_NumberExp(sex.substr(p-osn,q-p+osn));
|
---|
[2510] | 367 | else cx = rx;
|
---|
| 368 |
|
---|
| 369 | if (!cx) {
|
---|
| 370 | checkok = false; p = q; fgcont = false;
|
---|
| 371 | errmsg = "CExpressionEvaluator::ParseString()/ Syntax Error - farg=NULL (BB)";
|
---|
| 372 | }
|
---|
| 373 | else {
|
---|
| 374 | rx = Arrange_CE_BinExpStack(sbx, cx);
|
---|
| 375 | if (extype == 2) {
|
---|
| 376 | // cout << " DBG-ParseString-AddArg " << *(cx) << endl;
|
---|
| 377 | fx->AddArg(rx); rx = NULL;
|
---|
| 378 | }
|
---|
| 379 | if (opc == ')') { // Signe de fin de traitement d'une portion d'expression
|
---|
| 380 | if (extype == 2) { rx = fx; fx = NULL; }
|
---|
[2520] | 381 | stop = q; osn = 0; lastopc = opc;
|
---|
[2510] | 382 | fgcont = false;
|
---|
| 383 | finok = true;
|
---|
| 384 | }
|
---|
| 385 | else {
|
---|
| 386 | if (q == (len-1)) finok = true;
|
---|
[2520] | 387 | p = q+1; osn = 0; lastopc = opc;
|
---|
[2510] | 388 | }
|
---|
| 389 | }
|
---|
| 390 | break;
|
---|
| 391 |
|
---|
| 392 | case '+' :
|
---|
| 393 | case '-' :
|
---|
| 394 | case '*' :
|
---|
| 395 | case '/' :
|
---|
[2520] | 396 | if (!( ((opc=='+')||(opc=='-')) && ( (q==off) || ( (q==p) && lastopc != '(') ) ) ) {
|
---|
[2510] | 397 | CE_BinExp* nbx;
|
---|
[2515] | 398 | if (opc == '+') nbx = new CE_AddExp;
|
---|
| 399 | else if (opc == '-') nbx = new CE_SubExp;
|
---|
| 400 | else if (opc == '*') nbx = new CE_MulExp;
|
---|
| 401 | else nbx = new CE_DivExp;
|
---|
[2510] | 402 | if ((p == q) && (rx == NULL)) {
|
---|
[2520] | 403 | checkok = false; p = q; osn = 0; fgcont = false;
|
---|
[2510] | 404 | delete nbx;
|
---|
| 405 | errmsg = "CExpressionEvaluator::ParseString() Syntax Error - rx==NULL (C)";
|
---|
| 406 | }
|
---|
| 407 | else {
|
---|
| 408 | if (p == q) cx = rx;
|
---|
[2520] | 409 | else cx = new CE_NumberExp(sex.substr(p-osn,q-p+osn));
|
---|
[2510] | 410 | rx = Arrange_CE_BinExpStack(sbx, cx, nbx);
|
---|
[2520] | 411 | p = q+1; osn = 0; lastopc = opc;
|
---|
[2510] | 412 | }
|
---|
| 413 | }
|
---|
[2520] | 414 | else {
|
---|
| 415 | // Traitement des signes +/- qui pourrait faire partie d'une constante numerique
|
---|
| 416 | p = q+1; osn++;
|
---|
| 417 | continue;
|
---|
| 418 | }
|
---|
[2510] | 419 | break;
|
---|
| 420 | default:
|
---|
| 421 | throw CExprException("CExpressionEvaluator::ParseString() BUG-BUG-BUG");
|
---|
| 422 | break;
|
---|
| 423 | } // Fin de switch
|
---|
| 424 | }
|
---|
| 425 | else { // dernier element
|
---|
| 426 | if ( (p<len) && (rx != NULL)) {
|
---|
| 427 | checkok = false; p = len-1; fgcont = false;
|
---|
| 428 | errmsg = "CExpressionEvaluator::ParseString() Syntax Error - rx!=NULL at end (D)";
|
---|
| 429 | }
|
---|
| 430 | else {
|
---|
[2520] | 431 | if (p<len) cx = new CE_NumberExp(sex.substr(p-osn));
|
---|
[2510] | 432 | else cx = rx;
|
---|
| 433 | rx = Arrange_CE_BinExpStack(sbx, cx);
|
---|
| 434 | stop = p = len; fgcont = false;
|
---|
| 435 | finok = true;
|
---|
| 436 | }
|
---|
| 437 | }
|
---|
| 438 | }
|
---|
| 439 | // cout << " DBG-ParseString-out stop= " << stop << " sex[stop]= " << sex[stop] << endl;
|
---|
| 440 | if (finok && checkok) {
|
---|
| 441 | if( !sbx.empty() ) {
|
---|
| 442 | checkok = false;
|
---|
| 443 | errmsg = "CExpressionEvaluator::ParseString() !sbx.empty() at the end (E)";
|
---|
| 444 | }
|
---|
| 445 | else {
|
---|
| 446 | checkok = rx->CheckE(errmsg);
|
---|
| 447 | }
|
---|
| 448 | }
|
---|
| 449 | if (!finok || !checkok || !rx) {
|
---|
| 450 | char buff[128];
|
---|
| 451 | if (errmsg.length() < 1) {
|
---|
| 452 | errmsg = "CExpressionEvaluator::ParseString() Error - " ;
|
---|
| 453 | if (!finok) errmsg += " !finok " ;
|
---|
| 454 | if (!checkok) errmsg += " !checkok " ;
|
---|
| 455 | if (!rx) errmsg += " !rx " ;
|
---|
| 456 | errmsg += " (F)";
|
---|
| 457 | }
|
---|
| 458 | sprintf(buff,"\n CExprError... S=[%s] (p=%ld , len=%ld)", sex.c_str(), (long)p,(long)len);
|
---|
| 459 | errmsg += buff;
|
---|
| 460 | if (rx) delete rx;
|
---|
| 461 | rx = NULL;
|
---|
| 462 | while (!sbx.empty()) {
|
---|
| 463 | delete sbx.top();
|
---|
| 464 | sbx.pop();
|
---|
| 465 | }
|
---|
| 466 | }
|
---|
| 467 | if (fx) delete fx;
|
---|
| 468 | return rx;
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | } // End of namespace SOPHYA
|
---|
| 472 |
|
---|