SNAP Library 2.3, Developer Reference  2014-06-16 11:58:46
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TExp Class Reference

#include <exp.h>

Collaboration diagram for TExp:

Public Member Functions

 TExp (const TExpType &_ExpType=etUndef)
 
 TExp (const TExpOp &_ExpOp, const PExp &Exp1, const PExp &Exp2=NULL, const PExp &Exp3=NULL)
 
 TExp (const PExpVal &_ExpVal)
 
 TExp (const TStr &_VarNm)
 
 TExp (const TStr &_FuncNm, const TExpV &_ArgExpV)
 
 ~TExp ()
 
 TExp (TSIn &SIn)
 
void Save (TSOut &SOut) const
 
TExpoperator= (const TExp &)
 
bool operator== (const TExp &) const
 
void SaveTxt (TOLx &Lx) const
 
void SaveTxt (const PSOut &SOut) const
 
TStr GetStr () const
 
TStr GetTopObjNm () const
 
int GetArgExps () const
 
TStr GetArgExpStr (const int &ArgExpN) const
 
PExpVal Eval (bool &Ok, TStr &MsgStr, const bool &DbgP, TStr &DbgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
 
PExpVal Eval (const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
 
PExpVal Eval (bool &Ok, TStr &MsgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
 
PExpVal Eval (const PExpEnv &ExpEnv, const bool &DbgP, TStr &DbgStr)
 

Static Public Member Functions

static PExp Load (TSIn &SIn)
 
static bool IsExpStrOk (const TStr &ExpStr, TStr &MsgStr)
 
static PExp LoadTxt (const PSIn &SIn, bool &Ok, TStr &MsgStr, const TFSet &Expect=TFSet()|syEof)
 
static PExp LoadTxt (const TStr &ExpStr, bool &Ok, TStr &MsgStr)
 
static PExp LoadTxt (const TStr &ExpStr)
 
static PExpVal LoadAndEvalExpL (const TStr &ExpLStr, bool &Ok, TStr &MsgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
 
static TStr GetExpTypeStr (const TExpType &ExpType)
 
static TStr GetExpOpStr (const TExpOp &ExpOp)
 
static void GetBiDescV (TStrPrV &BiDescV)
 

Private Member Functions

void SaveTxtOp (TOLx &Lx) const
 
PExpVal EvalExpOp (const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA)
 
PExpVal EvalExp (const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA)
 

Static Private Member Functions

static TExpOp GetExpOpFromLxSym (const TLxSym &LxSym)
 
static TLxSym GetLxSymFromExpOp (const TExpOp &ExpOp)
 
static PExp LoadTxtFact (TILx &Lx, const TFSet &Expect)
 
static PExp LoadTxtMulExp (TILx &Lx, const TFSet &Expect)
 
static PExp LoadTxtAddExp (TILx &Lx, const TFSet &Expect)
 
static PExp LoadTxtRelExp (TILx &Lx, const TFSet &Expect)
 
static PExp LoadTxtExp (TILx &Lx, const TFSet &Expect)
 

Private Attributes

TCRef CRef
 
TInt ExpType
 
TBool IsParen
 
PExpVal ExpVal
 
TStr ExpNm
 
TInt ExpOp
 
TInt ExpBiId
 
TExpV ArgExpV
 

Static Private Attributes

static TExpBi ExpBi
 
static const TFSet MulOpSymSet
 
static const TFSet UAddOpSymSet
 
static const TFSet AddOpSymSet
 
static const TFSet RelOpSymSet
 
static const TFSet FactExpExpect
 
static const TFSet MulExpExpect
 
static const TFSet AddExpExpect
 
static const TFSet RelExpExpect
 
static const TFSet ExpExpect
 

Friends

class TPt< TExp >
 

Detailed Description

Definition at line 186 of file exp.h.

Constructor & Destructor Documentation

TExp::TExp ( const TExpType _ExpType = etUndef)
inline

Definition at line 213 of file exp.h.

Referenced by LoadAndEvalExpL(), LoadTxt(), LoadTxtAddExp(), LoadTxtExp(), LoadTxtFact(), LoadTxtMulExp(), and LoadTxtRelExp().

213  :
214  ExpType(_ExpType), IsParen(false),
215  ExpVal(), ExpNm(), ExpOp(), ExpBiId(), ArgExpV(){}
TInt ExpBiId
Definition: exp.h:194
TBool IsParen
Definition: exp.h:190
TInt ExpType
Definition: exp.h:189
TInt ExpOp
Definition: exp.h:193
PExpVal ExpVal
Definition: exp.h:191
TStr ExpNm
Definition: exp.h:192
TExpV ArgExpV
Definition: exp.h:195

Here is the caller graph for this function:

TExp::TExp ( const TExpOp _ExpOp,
const PExp Exp1,
const PExp Exp2 = NULL,
const PExp Exp3 = NULL 
)

Definition at line 771 of file exp.cpp.

References TVec< TVal, TSizeTy >::Add(), ArgExpV, and TPt< TRec >::Empty().

772  :
773  ExpType(etOp), IsParen(false),
774  ExpVal(), ExpNm(), ExpOp(_ExpOp), ExpBiId(), ArgExpV(){
775  ArgExpV.Add(Exp1);
776  if (!Exp2.Empty()){ArgExpV.Add(Exp2);}
777  if (!Exp3.Empty()){ArgExpV.Add(Exp3);}
778 }
bool Empty() const
Definition: bd.h:501
TInt ExpBiId
Definition: exp.h:194
TBool IsParen
Definition: exp.h:190
Definition: exp.h:171
TInt ExpType
Definition: exp.h:189
TInt ExpOp
Definition: exp.h:193
PExpVal ExpVal
Definition: exp.h:191
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TStr ExpNm
Definition: exp.h:192
TExpV ArgExpV
Definition: exp.h:195

Here is the call graph for this function:

TExp::TExp ( const PExpVal _ExpVal)

Definition at line 780 of file exp.cpp.

780  :
781  ExpType(etVal), IsParen(false),
782  ExpVal(_ExpVal), ExpNm(), ExpOp(), ExpBiId(), ArgExpV(){}
TInt ExpBiId
Definition: exp.h:194
TBool IsParen
Definition: exp.h:190
TInt ExpType
Definition: exp.h:189
TInt ExpOp
Definition: exp.h:193
PExpVal ExpVal
Definition: exp.h:191
Definition: exp.h:170
TStr ExpNm
Definition: exp.h:192
TExpV ArgExpV
Definition: exp.h:195
TExp::TExp ( const TStr _VarNm)

Definition at line 784 of file exp.cpp.

References etBiConst, etVar, ExpBi, ExpBiId, ExpNm, ExpType, and TExpBi::IsExpBiId().

784  :
785  ExpType(), IsParen(false),
786  ExpVal(), ExpNm(_VarNm), ExpOp(), ExpBiId(), ArgExpV(){
787  TExpBiId _ExpBiId;
788  if (ExpBi.IsExpBiId(ExpNm, _ExpBiId)){
790  ExpBiId=TInt(int(_ExpBiId));
791  } else {
792  ExpType=etVar;
793  }
794 }
TInt ExpBiId
Definition: exp.h:194
TBool IsParen
Definition: exp.h:190
TExpBiId
Definition: exp.h:110
bool IsExpBiId(const TStr &ExpBiNm, TExpBiId &ExpBiId)
Definition: exp.cpp:241
Definition: dt.h:1041
TInt ExpType
Definition: exp.h:189
TInt ExpOp
Definition: exp.h:193
PExpVal ExpVal
Definition: exp.h:191
Definition: exp.h:171
static TExpBi ExpBi
Definition: exp.h:188
TStr ExpNm
Definition: exp.h:192
TExpV ArgExpV
Definition: exp.h:195
Definition: exp.h:171

Here is the call graph for this function:

TExp::TExp ( const TStr _FuncNm,
const TExpV _ArgExpV 
)

Definition at line 796 of file exp.cpp.

References etBiFunc, etFunc, ExpBi, ExpBiId, ExpNm, ExpType, and TExpBi::IsExpBiId().

796  :
797  ExpType(), IsParen(false),
798  ExpVal(), ExpNm(_FuncNm), ExpOp(), ExpBiId(), ArgExpV(_ArgExpV){
799  TExpBiId _ExpBiId;
800  if (ExpBi.IsExpBiId(ExpNm, _ExpBiId)){
802  ExpBiId=TInt(int(_ExpBiId));
803  } else {
804  ExpType=etFunc;
805  }
806 }
Definition: exp.h:171
TInt ExpBiId
Definition: exp.h:194
TBool IsParen
Definition: exp.h:190
TExpBiId
Definition: exp.h:110
bool IsExpBiId(const TStr &ExpBiNm, TExpBiId &ExpBiId)
Definition: exp.cpp:241
Definition: dt.h:1041
TInt ExpType
Definition: exp.h:189
TInt ExpOp
Definition: exp.h:193
PExpVal ExpVal
Definition: exp.h:191
Definition: exp.h:171
static TExpBi ExpBi
Definition: exp.h:188
TStr ExpNm
Definition: exp.h:192
TExpV ArgExpV
Definition: exp.h:195

Here is the call graph for this function:

TExp::~TExp ( )
inline

Definition at line 221 of file exp.h.

221 {}
TExp::TExp ( TSIn SIn)
inline

Definition at line 222 of file exp.h.

222  :
223  ExpType(SIn), IsParen(SIn),
224  ExpVal(SIn), ExpNm(SIn), ExpOp(SIn), ExpBiId(SIn), ArgExpV(SIn){}
TInt ExpBiId
Definition: exp.h:194
TBool IsParen
Definition: exp.h:190
TInt ExpType
Definition: exp.h:189
TInt ExpOp
Definition: exp.h:193
PExpVal ExpVal
Definition: exp.h:191
TStr ExpNm
Definition: exp.h:192
TExpV ArgExpV
Definition: exp.h:195

Member Function Documentation

PExpVal TExp::Eval ( bool &  Ok,
TStr MsgStr,
const bool &  DbgP,
TStr DbgStr,
const PExpEnv ExpEnv = TExpEnv::DfExpEnv 
)

Definition at line 898 of file exp.cpp.

References EvalExp(), ExpVal, TExpVal::GetStr(), GetStr(), and TExpVal::GetUndefExpVal().

899  {
900  Ok=true; MsgStr="Ok";
901  PExpVal ExpVal; TChA DbgChA;
902  if (DbgP){DbgChA+="Debug Expression: ";}
903  try {
904  ExpVal=EvalExp(ExpEnv, DbgP, DbgChA);
905  }
906  catch (PExcept E){
907  Ok=false; MsgStr=E->GetMsgStr();
908  }
909  if (!Ok){return TExpVal::GetUndefExpVal();}
910  if (DbgP){
911  DbgChA+='['; DbgChA+=GetStr(); DbgChA+=" -> ";
912  DbgChA+=ExpVal->GetStr(); DbgChA+="] "; DbgChA+=MsgStr;
913  DbgStr=DbgChA;
914  }
915  return ExpVal;
916 }
TStr GetStr() const
Definition: exp.cpp:865
static PExpVal GetUndefExpVal()
Definition: exp.cpp:123
TStr GetStr() const
Definition: exp.cpp:99
PExpVal EvalExp(const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA)
Definition: exp.cpp:517
Definition: dt.h:201
PExpVal ExpVal
Definition: exp.h:191

Here is the call graph for this function:

PExpVal TExp::Eval ( const PExpEnv ExpEnv = TExpEnv::DfExpEnv)
inline

Definition at line 253 of file exp.h.

253  {
254  bool Ok; TStr MsgStr; TStr DbgStr;
255  return Eval(Ok, MsgStr, false, DbgStr, ExpEnv);}
PExpVal Eval(bool &Ok, TStr &MsgStr, const bool &DbgP, TStr &DbgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
Definition: exp.cpp:898
Definition: dt.h:412
PExpVal TExp::Eval ( bool &  Ok,
TStr MsgStr,
const PExpEnv ExpEnv = TExpEnv::DfExpEnv 
)
inline

Definition at line 256 of file exp.h.

256  {
257  TStr DbgStr; return Eval(Ok, MsgStr, false, DbgStr, ExpEnv);}
PExpVal Eval(bool &Ok, TStr &MsgStr, const bool &DbgP, TStr &DbgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
Definition: exp.cpp:898
Definition: dt.h:412
PExpVal TExp::Eval ( const PExpEnv ExpEnv,
const bool &  DbgP,
TStr DbgStr 
)
inline

Definition at line 258 of file exp.h.

258  {
259  bool Ok; TStr MsgStr; return Eval(Ok, MsgStr, DbgP, DbgStr, ExpEnv);}
PExpVal Eval(bool &Ok, TStr &MsgStr, const bool &DbgP, TStr &DbgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
Definition: exp.cpp:898
Definition: dt.h:412
PExpVal TExp::EvalExp ( const PExpEnv ExpEnv,
const bool &  DbgP,
TChA DbgChA 
)
private

Definition at line 517 of file exp.cpp.

References TExpVal::AddToLst(), TExpVal::AddToVec(), ArgExpV, etBiConst, etBiFunc, etFunc, etLst, etOp, etUndef, etVal, etVar, etVec, EvalExpOp(), evtLst, evtVec, ExpBi, ExpBiId, ExpNm, ExpType, ExpVal, Fail, TExpBi::GetBiConstVal(), TExpBi::GetBiFuncVal(), GetExpTypeStr(), TExpVal::GetStr(), TStr::GetUc(), TExpVal::GetUndefExpVal(), TVec< TVal, TSizeTy >::Len(), TExpVal::New(), and TExcept::Throw().

Referenced by Eval().

518  {
519  PExpVal OutExpVal;
520  TExpType _ExpType=TExpType(int(ExpType));
521  switch (_ExpType){
522  case etUndef:
523  OutExpVal=TExpVal::GetUndefExpVal();
524  break;
525  case etVal:
526  OutExpVal=ExpVal;
527  break;
528  case etVec:{
530  for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
531  PExpVal ArgExpVal=
532  PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
533  ExpVal->AddToVec(ArgExpVal);
534  }
535  OutExpVal=ExpVal;
536  break;}
537  case etLst:{
538  PExpVal ExpVal=TExpVal::New(evtLst);
539  for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
540  PExpVal ArgExpVal=
541  PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
542  ExpVal->AddToLst(ArgExpVal);
543  }
544  OutExpVal=ExpVal;
545  break;}
546  case etOp:
547  OutExpVal=EvalExpOp(ExpEnv, DbgP, DbgChA); break;
548  case etVar:{
549  bool IsVar=false;
550  PExpVal ExpVal=ExpEnv->GetVarVal(ExpNm.GetUc(), IsVar);
551  if (!IsVar){TExcept::Throw(TStr("Variable not defined (")+ExpNm+").");}
552  OutExpVal=ExpVal;
553  break;}
554  case etBiConst:
555  OutExpVal=ExpBi.GetBiConstVal(TExpBiId(int(ExpBiId)));
556  break;
557  case etFunc:
558  case etBiFunc:{
559  TExpValV ArgExpValV(ArgExpV.Len(), 0);
560  for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
561  PExpVal ArgExpVal=
562  PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
563  ArgExpValV.Add(ArgExpVal);
564  }
565  switch (_ExpType){
566  case etFunc:{
567  bool IsFunc=false;
568  PExpVal ExpVal=ExpEnv->GetFuncVal(ExpNm.GetUc(), ArgExpValV, IsFunc);
569  if (!IsFunc){
570  TExcept::Throw(TStr("Function not defined (")+ExpNm+").");}
571  OutExpVal=ExpVal;
572  break;}
573  case etBiFunc:
574  OutExpVal=ExpBi.GetBiFuncVal(TExpBiId(int(ExpBiId)), ArgExpValV, ExpEnv);
575  break;
576  default: Fail; OutExpVal=NULL;
577  }
578  break;}
579  default: Fail; OutExpVal=NULL;
580  }
581  if (DbgP){
582  switch (_ExpType){
583  case etVal:
584  case etOp:
585  break;
586  case etUndef:
587  case etVec:
588  case etLst:{
589  TStr ExpTypeStr=TExp::GetExpTypeStr(_ExpType);
590  DbgChA+='['; DbgChA+=ExpTypeStr; DbgChA+='=';
591  DbgChA+=OutExpVal->GetStr(); DbgChA+="] ";
592  break;}
593  case etVar:
594  case etBiConst:
595  case etFunc:
596  case etBiFunc:
597  DbgChA+='['; DbgChA+=ExpNm; DbgChA+='=';
598  DbgChA+=OutExpVal->GetStr(); DbgChA+="] ";
599  break;
600  default: Fail;
601  }
602  }
603  return OutExpVal;
604 }
Definition: exp.h:171
Definition: exp.h:5
Definition: exp.h:169
PExpVal GetBiConstVal(const TExpBiId &ExpBiId)
Definition: exp.cpp:268
Definition: exp.h:170
Definition: exp.h:5
static PExpVal GetUndefExpVal()
Definition: exp.cpp:123
#define Fail
Definition: bd.h:238
TStr GetUc() const
Definition: dt.h:493
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TStr GetStr() const
Definition: exp.cpp:99
TInt ExpBiId
Definition: exp.h:194
TPt< TExpVal > PExpVal
Definition: exp.h:9
PExpVal EvalExp(const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA)
Definition: exp.cpp:517
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
Definition: exp.h:170
Definition: exp.h:171
TExpBiId
Definition: exp.h:110
PExpVal GetBiFuncVal(const TExpBiId &ExpBiId, const TExpValV &ArgValV, const PExpEnv &ExpEnv)
Definition: exp.cpp:279
static PExpVal New(const TExpValType &ValType=evtUndef)
Definition: exp.h:23
void AddToVec(const PExpVal &ExpVal)
Definition: exp.h:40
TInt ExpType
Definition: exp.h:189
Definition: dt.h:412
PExpVal ExpVal
Definition: exp.h:191
PExpVal EvalExpOp(const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA)
Definition: exp.cpp:377
void AddToLst(const PExpVal &ExpVal)
Definition: exp.h:42
Definition: exp.h:170
static TStr GetExpTypeStr(const TExpType &ExpType)
Definition: exp.cpp:952
Definition: exp.h:171
Definition: exp.h:171
static TExpBi ExpBi
Definition: exp.h:188
TExpType
Definition: exp.h:168
TStr ExpNm
Definition: exp.h:192
TExpV ArgExpV
Definition: exp.h:195
Definition: exp.h:171

Here is the call graph for this function:

Here is the caller graph for this function:

PExpVal TExp::EvalExpOp ( const PExpEnv ExpEnv,
const bool &  DbgP,
TChA DbgChA 
)
private

Definition at line 377 of file exp.cpp.

References ArgExpV, eoAnd, eoDiv, eoEq, eoGEq, eoGtr, eoIDiv, eoIf, eoLEq, eoLss, eoMinus, eoMod, eoMul, eoNEq, eoNot, eoOr, eoPlus, eoUMinus, eoUPlus, evtFlt, evtStr, ExpOp, ExpVal, Fail, GetExpOpStr(), TExpVal::GetFltVal(), TExpVal::GetFltValAsInt(), TExpVal::GetStr(), TExpVal::GetStrVal(), TExpVal::GetValType(), TExpVal::GetZeroExpVal(), TExpVal::New(), and TExcept::Throw().

Referenced by EvalExp().

378  {
379  PExpVal OutExpVal;
380  TExpOp _ExpOp=TExpOp(int(ExpOp));
381  switch (_ExpOp){
382  case eoUPlus:
383  case eoUMinus:
384  case eoNot:{
385  PExpVal ExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
386  TExpValType ExpValType=ExpVal->GetValType();
387  if (ExpValType==evtFlt){
388  TFlt Flt;
389  switch (_ExpOp){
390  case eoUPlus: Flt=ExpVal->GetFltVal(); break;
391  case eoUMinus: Flt=-ExpVal->GetFltVal(); break;
392  case eoNot: Flt=double(ExpVal->GetFltValAsInt()==0);
393  default: Fail; Flt=0;
394  }
395  OutExpVal=TExpVal::New(Flt);
396  } else {
397  TExcept::Throw("Bad argument types.");
398  }
399  break;}
400  case eoPlus:
401  case eoMinus:
402  case eoMul:
403  case eoDiv:
404  case eoIDiv:
405  case eoMod:
406  case eoAnd:
407  case eoOr:{
408  PExpVal LExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
409  PExpVal RExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
410  TExpValType LExpValType=LExpVal->GetValType();
411  TExpValType RExpValType=RExpVal->GetValType();
412  if ((LExpValType==evtFlt)&&(RExpValType==evtFlt)){
413  // check left expression
414  double LVal=LExpVal->GetFltVal();
415  int LValExpon; frexp(LVal, &LValExpon);
416  if (LValExpon>150){LExpVal=TExpVal::GetZeroExpVal();}
417  // check right expression
418  double RVal=LExpVal->GetFltVal();
419  int RValExpon; frexp(RVal, &RValExpon);
420  if (RValExpon>150){RExpVal=TExpVal::GetZeroExpVal();}
421  // calculate
422  TFlt Flt;
423  switch (_ExpOp){
424  case eoPlus: Flt=LExpVal->GetFltVal()+RExpVal->GetFltVal(); break;
425  case eoMinus: Flt=LExpVal->GetFltVal()-RExpVal->GetFltVal(); break;
426  case eoMul: Flt=LExpVal->GetFltVal()*RExpVal->GetFltVal(); break;
427  case eoDiv:
428  if (RExpVal->GetFltVal()==0){TExcept::Throw("Division by zero.");}
429  else {Flt=LExpVal->GetFltVal()/RExpVal->GetFltVal();}
430  break;
431  case eoIDiv:
432  if (RExpVal->GetFltValAsInt()==0){TExcept::Throw("Division by zero.");}
433  else {Flt=LExpVal->GetFltValAsInt()/RExpVal->GetFltValAsInt();}
434  break;
435  case eoMod:
436  if (RExpVal->GetFltValAsInt()==0){TExcept::Throw("Division by zero.");}
437  else {Flt=LExpVal->GetFltValAsInt()%RExpVal->GetFltValAsInt();}
438  break;
439  case eoAnd:
440  Flt=(LExpVal->GetFltValAsInt()!=0)&&(RExpVal->GetFltValAsInt()!=0); break;
441  case eoOr:
442  Flt=(LExpVal->GetFltValAsInt()!=0)||(RExpVal->GetFltValAsInt()!=0); break;
443  default: Fail; Flt=0;
444  }
445  OutExpVal=TExpVal::New(Flt);
446  } else
447  if ((_ExpOp==eoPlus)&&(LExpValType==evtStr)&&(RExpValType==evtStr)){
448  TStr Str=LExpVal->GetStrVal()+RExpVal->GetStrVal();
449  OutExpVal=TExpVal::New(Str);
450  } else {
451  TExcept::Throw("Bad argument types.");
452  }
453  break;}
454  case eoEq:
455  case eoNEq:
456  case eoLss:
457  case eoGtr:
458  case eoLEq:
459  case eoGEq:{
460  PExpVal LExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
461  PExpVal RExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
462  TExpValType LExpValType=LExpVal->GetValType();
463  TExpValType RExpValType=RExpVal->GetValType();
464  if ((LExpValType==evtFlt)&&(RExpValType==evtFlt)){
465  TFlt Flt;
466  switch (_ExpOp){
467  case eoEq: Flt=double(LExpVal->GetFltVal()==RExpVal->GetFltVal()); break;
468  case eoNEq: Flt=double(LExpVal->GetFltVal()!=RExpVal->GetFltVal()); break;
469  case eoLss: Flt=double(LExpVal->GetFltVal()<RExpVal->GetFltVal()); break;
470  case eoGtr: Flt=double(LExpVal->GetFltVal()>RExpVal->GetFltVal()); break;
471  case eoLEq: Flt=double(LExpVal->GetFltVal()<=RExpVal->GetFltVal()); break;
472  case eoGEq: Flt=double(LExpVal->GetFltVal()>=RExpVal->GetFltVal()); break;
473  default: Fail; Flt=0;
474  }
475  OutExpVal=TExpVal::New(Flt);
476  } else
477  if ((LExpValType==evtStr)&&(RExpValType==evtStr)){
478  TFlt Flt;
479  switch (_ExpOp){
480  case eoEq: Flt=double(LExpVal->GetStrVal()==RExpVal->GetStrVal()); break;
481  case eoNEq: Flt=double(LExpVal->GetStrVal()!=RExpVal->GetStrVal()); break;
482  case eoLss: Flt=double(LExpVal->GetStrVal()<RExpVal->GetStrVal()); break;
483  case eoGtr: Flt=double(LExpVal->GetStrVal()>RExpVal->GetStrVal()); break;
484  case eoLEq: Flt=double(LExpVal->GetStrVal()<=RExpVal->GetStrVal()); break;
485  case eoGEq: Flt=double(LExpVal->GetStrVal()>=RExpVal->GetStrVal()); break;
486  default: Fail; Flt=0;
487  }
488  OutExpVal=TExpVal::New(Flt);
489  } else {
490  TExcept::Throw("Bad argument types.");
491  }
492  break;}
493  case eoIf:{
494  PExpVal CondExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
495  TExpValType CondExpValType=CondExpVal->GetValType();
496  if (CondExpValType==evtFlt){
497  PExpVal ExpVal;
498  if (CondExpVal->GetFltVal()!=0){
499  ExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
500  } else {
501  ExpVal=ArgExpV[2]->EvalExp(ExpEnv, DbgP, DbgChA);
502  }
503  OutExpVal=ExpVal;
504  } else {
505  TExcept::Throw("Bad argument types.");
506  }
507  break;}
508  default: Fail; OutExpVal=NULL;
509  }
510  if (DbgP){
511  DbgChA+="['"; DbgChA+=TExp::GetExpOpStr(_ExpOp);
512  DbgChA+="'='"; DbgChA+=OutExpVal->GetStr(); DbgChA+="'] ";
513  }
514  return OutExpVal;
515 }
Definition: exp.h:180
TExpOp
Definition: exp.h:175
Definition: exp.h:179
Definition: exp.h:180
#define Fail
Definition: bd.h:238
Definition: exp.h:180
static PExpVal GetZeroExpVal()
Definition: exp.cpp:129
TStr GetStr() const
Definition: exp.cpp:99
Definition: exp.h:178
Definition: exp.h:181
Definition: dt.h:1289
Definition: exp.h:178
Definition: exp.h:180
Definition: exp.h:179
Definition: exp.h:5
static TStr GetExpOpStr(const TExpOp &ExpOp)
Definition: exp.h:266
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
Definition: exp.h:180
TStr GetStrVal() const
Definition: exp.h:53
Definition: exp.h:178
Definition: exp.h:5
TExpValType GetValType() const
Definition: exp.h:45
Definition: exp.h:179
TExpValType
Definition: exp.h:5
Definition: exp.h:180
Definition: exp.h:178
double GetFltVal() const
Definition: exp.h:50
Definition: exp.h:177
static PExpVal New(const TExpValType &ValType=evtUndef)
Definition: exp.h:23
Definition: exp.h:178
TInt ExpOp
Definition: exp.h:193
Definition: dt.h:412
PExpVal ExpVal
Definition: exp.h:191
Definition: exp.h:177
int GetFltValAsInt(const bool &ThrowExceptP=true) const
Definition: exp.cpp:62
Definition: exp.h:178
TExpV ArgExpV
Definition: exp.h:195

Here is the call graph for this function:

Here is the caller graph for this function:

int TExp::GetArgExps ( ) const

Definition at line 890 of file exp.cpp.

References ArgExpV, and TVec< TVal, TSizeTy >::Len().

890  {
891  return ArgExpV.Len();
892 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TExpV ArgExpV
Definition: exp.h:195

Here is the call graph for this function:

TStr TExp::GetArgExpStr ( const int &  ArgExpN) const

Definition at line 894 of file exp.cpp.

References ArgExpV.

894  {
895  return ArgExpV[ArgExpN]->GetStr();
896 }
TExpV ArgExpV
Definition: exp.h:195
void TExp::GetBiDescV ( TStrPrV BiDescV)
static

Definition at line 967 of file exp.cpp.

References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Clr().

967  {
968  BiDescV.Clr();
969  // constants
970  BiDescV.Add(TStrPr("True", "Logical 'True' == 1."));
971  BiDescV.Add(TStrPr("False", "Logical 'False' == 0."));
972  BiDescV.Add(TStrPr("E", "Nat. logarithm basis (2.7182...)."));
973  BiDescV.Add(TStrPr("Pi", "Constant pi (3.1415...)."));
974 
975  // trigonometric funcions
976  BiDescV.Add(TStrPr("Sin(X)", "Sine of angle in radians."));
977  BiDescV.Add(TStrPr("Cos(X)", "Cosine of angle in radians."));
978  BiDescV.Add(TStrPr("Tan(X)", "Tangent of angle in radians."));
979  BiDescV.Add(TStrPr("ASin(X)", "Arc sine of (-1..+1)."));
980  BiDescV.Add(TStrPr("ACos(X)", "Arc cosine of (-1..+1)."));
981  BiDescV.Add(TStrPr("ATan(X)", "Arc tangent of (-inf..+inf)."));
982  BiDescV.Add(TStrPr("SinH(X)", "Hyperbolic sine."));
983  BiDescV.Add(TStrPr("CosH(X)", "Hyperbolic cosine."));
984  BiDescV.Add(TStrPr("TanH(X)", "Hyperbolic tangent."));
985 
986  // exponential functions
987  BiDescV.Add(TStrPr("Pow(X, Y)", "X to the power of Y."));
988  BiDescV.Add(TStrPr("Exp(X)", "Exponential E to the power of X."));
989  BiDescV.Add(TStrPr("Sqr(X)", "X squared."));
990  BiDescV.Add(TStrPr("Sqrt(X)", "Positive square root."));
991  BiDescV.Add(TStrPr("Log(X)", "Natural logarithm."));
992  BiDescV.Add(TStrPr("Log10(X)", "Base 10 logarithm."));
993 
994  // number manipulation functions
995  BiDescV.Add(TStrPr("Ceil(X)", "The smallest integer not less than X."));
996  BiDescV.Add(TStrPr("Floor(X)", "The largest integer not greater than X."));
997  BiDescV.Add(TStrPr("Int(X)", "Integer part of X."));
998  BiDescV.Add(TStrPr("Frac(X)", "Fractional part of X."));
999  BiDescV.Add(TStrPr("Abs(X)", "Absolute value of X."));
1000 
1001  // random deviates
1002  BiDescV.Add(TStrPr("UniDev()", "Uniform deviate (0..1)."));
1003  BiDescV.Add(TStrPr("NrmDev()", "Normal deviate (0, 1)."));
1004  BiDescV.Add(TStrPr("ExpDev()", "Exponential deviate."));
1005  BiDescV.Add(TStrPr("GamDev(Order)", "Gamma deviate of Order."));
1006  BiDescV.Add(TStrPr("PoiDev(Mean)", "Poisson deviate."));
1007  BiDescV.Add(TStrPr("BinDev(Prb, Trials)", "Binomial deviate."));
1008 
1009  // operators
1010  BiDescV.Add(TStrPr("+N", "Unary plus."));
1011  BiDescV.Add(TStrPr("-N", "Unary minus."));
1012  BiDescV.Add(TStrPr("!L", "Not."));
1013  BiDescV.Add(TStrPr("N1+N2", "Plus."));
1014  BiDescV.Add(TStrPr("N1-N2", "Minus."));
1015  BiDescV.Add(TStrPr("N1*N2", "Multiply."));
1016  BiDescV.Add(TStrPr("N1/N2", "Division."));
1017  BiDescV.Add(TStrPr("N1#N2", "Integer division."));
1018  BiDescV.Add(TStrPr("N1%N2", "Modulo."));
1019  BiDescV.Add(TStrPr("L1&L2", "And."));
1020  BiDescV.Add(TStrPr("L1|L2", "Or."));
1021  BiDescV.Add(TStrPr("E1=E2", "Equal."));
1022  BiDescV.Add(TStrPr("E1<>E2", "Not equal."));
1023  BiDescV.Add(TStrPr("E1<E2", "Less."));
1024  BiDescV.Add(TStrPr("E1>E2", "Greater."));
1025  BiDescV.Add(TStrPr("E1<=E2", "Less or equal."));
1026  BiDescV.Add(TStrPr("E1>=E2", "Greater or equal."));
1027  BiDescV.Add(TStrPr("L?E1:E2", "If L then return E1 else return E2."));
1028 }
TPair< TStr, TStr > TStrPr
Definition: ds.h:107
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559

Here is the call graph for this function:

TExpOp TExp::GetExpOpFromLxSym ( const TLxSym LxSym)
staticprivate

Definition at line 606 of file exp.cpp.

References eoAnd, eoDiv, eoEq, eoGEq, eoGtr, eoIDiv, eoIf, eoLEq, eoLss, eoMinus, eoMod, eoMul, eoNEq, eoNot, eoOr, eoPlus, eoUndef, Fail, syAmpersand, syAsterisk, syEq, syExclamation, syGEq, syGtr, syHash, syLEq, syLss, syMinus, syNEq, syPercent, syPlus, syQuestion, sySlash, and syVBar.

Referenced by LoadTxtAddExp(), LoadTxtExp(), LoadTxtMulExp(), and LoadTxtRelExp().

606  {
607  switch (LxSym){
608  case syPlus: return eoPlus;
609  case syMinus: return eoMinus;
610  case syAsterisk: return eoMul;
611  case sySlash: return eoDiv;
612  case syPercent: return eoMod;
613  case syExclamation: return eoNot;
614  case syVBar: return eoOr;
615  case syAmpersand: return eoAnd;
616  case syQuestion: return eoIf;
617  case syHash: return eoIDiv;
618  case syEq: return eoEq;
619  case syNEq: return eoNEq;
620  case syLss: return eoLss;
621  case syGtr: return eoGtr;
622  case syLEq: return eoLEq;
623  case syGEq: return eoGEq;
624  default: Fail; return eoUndef;
625  }
626 }
Definition: lx.h:49
Definition: lx.h:49
Definition: exp.h:180
Definition: lx.h:49
Definition: lx.h:48
Definition: exp.h:179
Definition: exp.h:180
#define Fail
Definition: bd.h:238
Definition: lx.h:48
Definition: exp.h:180
Definition: lx.h:47
Definition: exp.h:176
Definition: exp.h:178
Definition: lx.h:47
Definition: exp.h:181
Definition: lx.h:49
Definition: exp.h:178
Definition: exp.h:180
Definition: exp.h:179
Definition: lx.h:47
Definition: lx.h:49
Definition: exp.h:180
Definition: exp.h:178
Definition: exp.h:179
Definition: exp.h:180
Definition: exp.h:178
Definition: lx.h:49
Definition: lx.h:47
Definition: lx.h:48
Definition: exp.h:178
Definition: lx.h:47
Definition: exp.h:178
Definition: lx.h:48

Here is the caller graph for this function:

static TStr TExp::GetExpOpStr ( const TExpOp ExpOp)
inlinestatic

Definition at line 266 of file exp.h.

References GetLxSymFromExpOp(), and TLxSymStr::GetSymStr().

Referenced by EvalExpOp(), and GetTopObjNm().

266  {
static TLxSym GetLxSymFromExpOp(const TExpOp &ExpOp)
Definition: exp.cpp:628
TInt ExpOp
Definition: exp.h:193
static TStr GetSymStr(const TLxSym &Sym)
Definition: lx.cpp:142

Here is the call graph for this function:

Here is the caller graph for this function:

TStr TExp::GetExpTypeStr ( const TExpType ExpType)
static

Definition at line 952 of file exp.cpp.

References etBiConst, etBiFunc, etFunc, etLst, etOp, etUndef, etVal, etVar, etVec, and Fail.

Referenced by EvalExp().

952  {
953  switch (ExpType){
954  case etUndef: return "Undef";
955  case etVal: return "Val";
956  case etVec: return "Vec";
957  case etLst: return "Lst";
958  case etOp: return "Op";
959  case etVar: return "Var";
960  case etBiConst: return "BiConst";
961  case etFunc: return "Func";
962  case etBiFunc: return "BiFunc";
963  default: Fail; return "";
964  }
965 }
Definition: exp.h:171
Definition: exp.h:169
Definition: exp.h:170
#define Fail
Definition: bd.h:238
Definition: exp.h:170
Definition: exp.h:171
TInt ExpType
Definition: exp.h:189
Definition: exp.h:170
Definition: exp.h:171
Definition: exp.h:171
Definition: exp.h:171

Here is the caller graph for this function:

TLxSym TExp::GetLxSymFromExpOp ( const TExpOp ExpOp)
staticprivate

Definition at line 628 of file exp.cpp.

References eoAnd, eoDiv, eoEq, eoGEq, eoGtr, eoIDiv, eoIf, eoLEq, eoLss, eoMinus, eoMod, eoMul, eoNEq, eoNot, eoOr, eoPlus, eoUMinus, eoUPlus, Fail, syAmpersand, syAsterisk, syEq, syExclamation, syGEq, syGtr, syHash, syLEq, syLss, syMinus, syNEq, syPercent, syPlus, syQuestion, sySlash, syUndef, and syVBar.

Referenced by GetExpOpStr(), and SaveTxtOp().

628  {
629  switch (ExpOp){
630  case eoUPlus: return syPlus;
631  case eoUMinus: return syMinus;
632  case eoNot: return syExclamation;
633  case eoPlus: return syPlus;
634  case eoMinus: return syMinus;
635  case eoMul: return syAsterisk;
636  case eoDiv: return sySlash;
637  case eoIDiv: return syHash;
638  case eoMod: return syPercent;
639  case eoAnd: return syAmpersand;
640  case eoOr: return syVBar;
641  case eoEq: return syEq;
642  case eoNEq: return syNEq;
643  case eoLss: return syLss;
644  case eoGtr: return syGtr;
645  case eoLEq: return syLEq;
646  case eoGEq: return syGEq;
647  case eoIf: return syQuestion;
648  default: Fail; return syUndef;
649  }
650 }
Definition: lx.h:49
Definition: lx.h:49
Definition: exp.h:180
Definition: lx.h:49
Definition: lx.h:48
Definition: exp.h:179
Definition: exp.h:180
#define Fail
Definition: bd.h:238
Definition: lx.h:48
Definition: exp.h:180
Definition: lx.h:47
Definition: exp.h:178
Definition: lx.h:47
Definition: exp.h:181
Definition: lx.h:49
Definition: exp.h:178
Definition: exp.h:180
Definition: exp.h:179
Definition: lx.h:45
Definition: lx.h:47
Definition: lx.h:49
Definition: exp.h:180
Definition: exp.h:178
Definition: exp.h:179
Definition: exp.h:180
Definition: exp.h:178
Definition: lx.h:49
Definition: exp.h:177
Definition: lx.h:47
Definition: lx.h:48
Definition: exp.h:178
TInt ExpOp
Definition: exp.h:193
Definition: lx.h:47
Definition: exp.h:177
Definition: exp.h:178
Definition: lx.h:48

Here is the caller graph for this function:

TStr TExp::GetStr ( ) const

Definition at line 865 of file exp.cpp.

References TMOut::GetSIn(), TStr::LoadTxt(), TMOut::New(), and SaveTxt().

Referenced by Eval().

865  {
866  PSOut SOut=TMOut::New(); TMOut& MOut=*(TMOut*)SOut();
867  SaveTxt(SOut);
868  TStr ExpStr=TStr::LoadTxt(MOut.GetSIn());
869  return ExpStr;
870 }
PSIn GetSIn(const bool &IsCut=true, const int &CutBfL=-1)
Definition: fl.cpp:666
void SaveTxt(TOLx &Lx) const
Definition: exp.cpp:823
static PSOut New(const int &MxBfL=1024)
Definition: fl.h:428
Definition: fl.h:417
Definition: dt.h:412
static TStr LoadTxt(const PSIn &SIn)
Definition: dt.h:667

Here is the call graph for this function:

Here is the caller graph for this function:

TStr TExp::GetTopObjNm ( ) const

Definition at line 872 of file exp.cpp.

References etBiConst, etBiFunc, etFunc, etOp, etVar, ExpNm, ExpOp, ExpType, and GetExpOpStr().

872  {
873  TStr TopObjNm;
874  TExpType _ExpType=TExpType(int(ExpType));
875  switch (_ExpType){
876  case etOp:{
877  TExpOp _ExpOp=TExpOp(int(ExpOp));
878  TopObjNm=GetExpOpStr(_ExpOp);
879  break;}
880  case etVar:
881  case etBiConst:
882  case etFunc:
883  case etBiFunc:{
884  TopObjNm=ExpNm; break;}
885  default: break;
886  }
887  return TopObjNm;
888 }
Definition: exp.h:171
TExpOp
Definition: exp.h:175
static TStr GetExpOpStr(const TExpOp &ExpOp)
Definition: exp.h:266
Definition: exp.h:171
TInt ExpType
Definition: exp.h:189
TInt ExpOp
Definition: exp.h:193
Definition: dt.h:412
Definition: exp.h:171
Definition: exp.h:171
TExpType
Definition: exp.h:168
TStr ExpNm
Definition: exp.h:192
Definition: exp.h:171

Here is the call graph for this function:

static bool TExp::IsExpStrOk ( const TStr ExpStr,
TStr MsgStr 
)
inlinestatic

Definition at line 234 of file exp.h.

234  {
235  bool Ok; LoadTxt(ExpStr, Ok, MsgStr); return Ok;}
static PExp LoadTxt(const PSIn &SIn, bool &Ok, TStr &MsgStr, const TFSet &Expect=TFSet()|syEof)
Definition: exp.cpp:808
static PExp TExp::Load ( TSIn SIn)
inlinestatic

Definition at line 225 of file exp.h.

225 {return PExp(new TExp(SIn));}
TPt< TExp > PExp
Definition: exp.h:186
TExp(const TExpType &_ExpType=etUndef)
Definition: exp.h:213
PExpVal TExp::LoadAndEvalExpL ( const TStr ExpLStr,
bool &  Ok,
TStr MsgStr,
const PExpEnv ExpEnv = TExpEnv::DfExpEnv 
)
static

Definition at line 918 of file exp.cpp.

References etUndef, ExpExpect, ExpVal, TILx::GetSym(), iloCmtAlw, iloCsSens, iloExcept, LoadTxtExp(), TStrIn::New(), syEof, TILx::Sym, sySemicolon, and TExp().

919  {
920  // create final expression value
921  PExpVal ExpVal;
922  // transform exp. str. to input stream
923  PSIn SIn=TStrIn::New(ExpLStr);
924  // create lexical
926  TFSet Expect=TFSet()|sySemicolon|syEof;
927  // load & evaluate expression separated by semicolon
928  while (Lx.Sym!=syEof){
929  // create expression
930  PExp Exp; Ok=true; MsgStr="Ok";
931  try {
932  Lx.GetSym(ExpExpect);
933  Exp=LoadTxtExp(Lx, Expect);
934  }
935  catch (PExcept Except){
936  Ok=false; MsgStr=Except->GetMsgStr();
937  Exp=PExp(new TExp(etUndef));
938  }
939  // evaluate expression
940  if (Ok){
941  ExpVal=Exp->Eval(Ok, MsgStr, ExpEnv);
942  //printf("%s\n", ExpVal->GetStr().CStr());
943  if (!Ok){
944  return NULL;}
945  } else {
946  return NULL;
947  }
948  }
949  return ExpVal;
950 }
Definition: exp.h:169
Definition: lx.h:127
static const TFSet ExpExpect
Definition: exp.h:199
Definition: bits.h:119
TPt< TExp > PExp
Definition: exp.h:186
Definition: lx.h:126
TExp(const TExpType &_ExpType=etUndef)
Definition: exp.h:213
Definition: lx.h:51
static PSIn New(const TStr &Str)
Definition: dt.h:709
Definition: lx.h:129
PExpVal ExpVal
Definition: exp.h:191
static PExp LoadTxtExp(TILx &Lx, const TFSet &Expect)
Definition: exp.cpp:731
Definition: lx.h:46
Definition: lx.h:126

Here is the call graph for this function:

PExp TExp::LoadTxt ( const PSIn SIn,
bool &  Ok,
TStr MsgStr,
const TFSet Expect = TFSet()|syEof 
)
static

Definition at line 808 of file exp.cpp.

References etUndef, ExpExpect, TILx::GetSym(), iloCmtAlw, iloCsSens, iloExcept, LoadTxtExp(), and TExp().

809  {
811  PExp Exp; Ok=true; MsgStr="Ok";
812  try {
813  Lx.GetSym(ExpExpect);
814  Exp=LoadTxtExp(Lx, Expect);
815  }
816  catch (PExcept Except){
817  Ok=false; MsgStr=Except->GetMsgStr();
818  Exp=PExp(new TExp(etUndef));
819  }
820  return Exp;
821 }
Definition: exp.h:169
Definition: lx.h:127
static const TFSet ExpExpect
Definition: exp.h:199
Definition: bits.h:119
TPt< TExp > PExp
Definition: exp.h:186
Definition: lx.h:126
TExp(const TExpType &_ExpType=etUndef)
Definition: exp.h:213
Definition: lx.h:129
static PExp LoadTxtExp(TILx &Lx, const TFSet &Expect)
Definition: exp.cpp:731
Definition: bd.h:196
Definition: lx.h:126

Here is the call graph for this function:

static PExp TExp::LoadTxt ( const TStr ExpStr,
bool &  Ok,
TStr MsgStr 
)
inlinestatic

Definition at line 238 of file exp.h.

References TStrIn::New().

238  {
239  PSIn SIn=TStrIn::New(ExpStr); return LoadTxt(SIn, Ok, MsgStr);}
static PExp LoadTxt(const PSIn &SIn, bool &Ok, TStr &MsgStr, const TFSet &Expect=TFSet()|syEof)
Definition: exp.cpp:808
static PSIn New(const TStr &Str)
Definition: dt.h:709
Definition: bd.h:196

Here is the call graph for this function:

static PExp TExp::LoadTxt ( const TStr ExpStr)
inlinestatic

Definition at line 240 of file exp.h.

240  {
241  bool Ok; TStr MsgStr; return LoadTxt(ExpStr, Ok, MsgStr);}
static PExp LoadTxt(const PSIn &SIn, bool &Ok, TStr &MsgStr, const TFSet &Expect=TFSet()|syEof)
Definition: exp.cpp:808
Definition: dt.h:412
PExp TExp::LoadTxtAddExp ( TILx Lx,
const TFSet Expect 
)
staticprivate

Definition at line 704 of file exp.cpp.

References AddOpSymSet, eoUMinus, eoUndef, eoUPlus, ExpOp, GetExpOpFromLxSym(), TILx::GetSym(), TFSet::In(), LoadTxtMulExp(), MulExpExpect, TILx::Sym, syMinus, syPlus, and TExp().

Referenced by LoadTxtRelExp().

704  {
705  TExpOp PrefExpOp=eoUndef;
706  if (Lx.Sym==syPlus){PrefExpOp=eoUPlus; Lx.GetSym(MulExpExpect);}
707  else if (Lx.Sym==syMinus){PrefExpOp=eoUMinus; Lx.GetSym(MulExpExpect);}
708  PExp Exp=LoadTxtMulExp(Lx, TFSet(Expect)|AddOpSymSet);
709  if (PrefExpOp!=eoUndef){
710  Exp=PExp(new TExp(PrefExpOp, Exp));}
711  while (AddOpSymSet.In(Lx.Sym)){
713  Lx.GetSym(MulExpExpect);
714  PExp RExp=LoadTxtMulExp(Lx, TFSet(Expect)|AddOpSymSet);
715  Exp=PExp(new TExp(ExpOp, Exp, RExp));
716  }
717  return Exp;
718 }
static TExpOp GetExpOpFromLxSym(const TLxSym &LxSym)
Definition: exp.cpp:606
TExpOp
Definition: exp.h:175
Definition: bits.h:119
Definition: lx.h:47
Definition: exp.h:176
TPt< TExp > PExp
Definition: exp.h:186
TLxSym Sym
Definition: lx.h:149
TExp(const TExpType &_ExpType=etUndef)
Definition: exp.h:213
static PExp LoadTxtMulExp(TILx &Lx, const TFSet &Expect)
Definition: exp.cpp:693
static const TFSet MulExpExpect
Definition: exp.h:198
Definition: exp.h:177
TInt ExpOp
Definition: exp.h:193
Definition: lx.h:47
Definition: bd.h:196
Definition: exp.h:177
static const TFSet AddOpSymSet
Definition: exp.h:197
TLxSym GetSym(const TFSet &Expect)
Definition: lx.cpp:315
bool In(const int &FlagN) const
Definition: bits.h:156

Here is the call graph for this function:

Here is the caller graph for this function:

PExp TExp::LoadTxtExp ( TILx Lx,
const TFSet Expect 
)
staticprivate

Definition at line 731 of file exp.cpp.

References ExpExpect, ExpOp, GetExpOpFromLxSym(), TILx::GetSym(), LoadTxtRelExp(), syColon, TILx::Sym, syQuestion, and TExp().

Referenced by LoadAndEvalExpL(), LoadTxt(), and LoadTxtFact().

731  {
732  PExp Exp=LoadTxtRelExp(Lx, TFSet(Expect)|syQuestion);
733  if (Lx.Sym==syQuestion){
735  Lx.GetSym(ExpExpect);
736  PExp ThenExp=LoadTxtExp(Lx, TFSet()|syColon);
737  Lx.GetSym(ExpExpect);
738  PExp ElseExp=LoadTxtExp(Lx, Expect);
739  Exp=PExp(new TExp(ExpOp, Exp, ThenExp, ElseExp));
740  }
741  return Exp;
742 }
static const TFSet ExpExpect
Definition: exp.h:199
static TExpOp GetExpOpFromLxSym(const TLxSym &LxSym)
Definition: exp.cpp:606
TExpOp
Definition: exp.h:175
Definition: bits.h:119
TPt< TExp > PExp
Definition: exp.h:186
TLxSym Sym
Definition: lx.h:149
TExp(const TExpType &_ExpType=etUndef)
Definition: exp.h:213
static PExp LoadTxtRelExp(TILx &Lx, const TFSet &Expect)
Definition: exp.cpp:720
TInt ExpOp
Definition: exp.h:193
static PExp LoadTxtExp(TILx &Lx, const TFSet &Expect)
Definition: exp.cpp:731
Definition: bd.h:196
Definition: lx.h:46
TLxSym GetSym(const TFSet &Expect)
Definition: lx.cpp:315
Definition: lx.h:48

Here is the call graph for this function:

Here is the caller graph for this function:

PExp TExp::LoadTxtFact ( TILx Lx,
const TFSet Expect 
)
staticprivate

Definition at line 652 of file exp.cpp.

References TVec< TVal, TSizeTy >::Add(), ArgExpV, ExpExpect, ExpNm, ExpVal, Fail, TILx::Flt, TILx::GetSym(), LoadTxtExp(), TExpVal::New(), TILx::Str, syComma, syFlt, syIdStr, syLParen, TILx::Sym, syQStr, syRParen, and TExp().

Referenced by LoadTxtMulExp().

652  {
653  PExp Exp;
654  switch (Lx.Sym){
655  case syFlt:{
657  Exp=PExp(new TExp(ExpVal));
658  Lx.GetSym(Expect);
659  break;}
660  case syIdStr:{
661  TStr ExpNm=Lx.Str;
662  Lx.GetSym(TFSet(Expect)|syLParen);
663  if (Lx.Sym==syLParen){
664  TExpV ArgExpV;
666  while (Lx.Sym!=syRParen){
667  if (Lx.Sym==syComma){Lx.GetSym(ExpExpect);}
668  PExp ArgExp=LoadTxtExp(Lx, TFSet()|syComma|syRParen);
669  ArgExpV.Add(ArgExp);
670  }
671  Lx.GetSym(Expect);
672  Exp=PExp(new TExp(ExpNm, ArgExpV));
673  } else {
674  Exp=PExp(new TExp(ExpNm));
675  }
676  break;}
677  case syQStr:{
678  PExpVal ExpVal=TExpVal::New(Lx.Str);
679  Exp=PExp(new TExp(ExpVal));
680  Lx.GetSym(Expect);
681  break;}
682  case syLParen:{
683  Lx.GetSym(ExpExpect);
684  Exp=LoadTxtExp(Lx, TFSet()|syRParen);
685  Exp->IsParen=true;
686  Lx.GetSym(Expect);
687  break;}
688  default: Fail;
689  }
690  return Exp;
691 }
static const TFSet ExpExpect
Definition: exp.h:199
#define Fail
Definition: bd.h:238
Definition: bits.h:119
Definition: lx.h:45
Definition: lx.h:45
TPt< TExp > PExp
Definition: exp.h:186
TLxSym Sym
Definition: lx.h:149
TExp(const TExpType &_ExpType=etUndef)
Definition: exp.h:213
Definition: lx.h:45
TChA Str
Definition: lx.h:150
static PExpVal New(const TExpValType &ValType=evtUndef)
Definition: exp.h:23
Definition: lx.h:50
Definition: dt.h:412
PExpVal ExpVal
Definition: exp.h:191
Definition: lx.h:46
static PExp LoadTxtExp(TILx &Lx, const TFSet &Expect)
Definition: exp.cpp:731
Definition: bd.h:196
TLxSym GetSym(const TFSet &Expect)
Definition: lx.cpp:315
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
TStr ExpNm
Definition: exp.h:192
Definition: lx.h:50
TExpV ArgExpV
Definition: exp.h:195
double Flt
Definition: lx.h:151

Here is the call graph for this function:

Here is the caller graph for this function:

PExp TExp::LoadTxtMulExp ( TILx Lx,
const TFSet Expect 
)
staticprivate

Definition at line 693 of file exp.cpp.

References ExpOp, FactExpExpect, GetExpOpFromLxSym(), TILx::GetSym(), TFSet::In(), LoadTxtFact(), MulOpSymSet, TILx::Sym, and TExp().

Referenced by LoadTxtAddExp().

693  {
694  PExp Exp=LoadTxtFact(Lx, TFSet(Expect)|MulOpSymSet);
695  while (MulOpSymSet.In(Lx.Sym)){
697  Lx.GetSym(FactExpExpect);
698  PExp RExp=LoadTxtFact(Lx, TFSet(Expect)|MulOpSymSet);
699  Exp=PExp(new TExp(ExpOp, Exp, RExp));
700  }
701  return Exp;
702 }
static TExpOp GetExpOpFromLxSym(const TLxSym &LxSym)
Definition: exp.cpp:606
TExpOp
Definition: exp.h:175
Definition: bits.h:119
TPt< TExp > PExp
Definition: exp.h:186
static const TFSet MulOpSymSet
Definition: exp.h:197
TLxSym Sym
Definition: lx.h:149
static const TFSet FactExpExpect
Definition: exp.h:198
TExp(const TExpType &_ExpType=etUndef)
Definition: exp.h:213
static PExp LoadTxtFact(TILx &Lx, const TFSet &Expect)
Definition: exp.cpp:652
TInt ExpOp
Definition: exp.h:193
Definition: bd.h:196
TLxSym GetSym(const TFSet &Expect)
Definition: lx.cpp:315
bool In(const int &FlagN) const
Definition: bits.h:156

Here is the call graph for this function:

Here is the caller graph for this function:

PExp TExp::LoadTxtRelExp ( TILx Lx,
const TFSet Expect 
)
staticprivate

Definition at line 720 of file exp.cpp.

References AddExpExpect, ExpOp, GetExpOpFromLxSym(), TILx::GetSym(), TFSet::In(), LoadTxtAddExp(), RelOpSymSet, TILx::Sym, and TExp().

Referenced by LoadTxtExp().

720  {
721  PExp Exp=LoadTxtAddExp(Lx, TFSet(Expect)|RelOpSymSet);
722  if (RelOpSymSet.In(Lx.Sym)){
724  Lx.GetSym(AddExpExpect);
725  PExp RExp=LoadTxtAddExp(Lx, Expect);
726  Exp=PExp(new TExp(ExpOp, Exp, RExp));
727  }
728  return Exp;
729 }
static TExpOp GetExpOpFromLxSym(const TLxSym &LxSym)
Definition: exp.cpp:606
TExpOp
Definition: exp.h:175
Definition: bits.h:119
static const TFSet AddExpExpect
Definition: exp.h:198
TPt< TExp > PExp
Definition: exp.h:186
TLxSym Sym
Definition: lx.h:149
TExp(const TExpType &_ExpType=etUndef)
Definition: exp.h:213
static PExp LoadTxtAddExp(TILx &Lx, const TFSet &Expect)
Definition: exp.cpp:704
TInt ExpOp
Definition: exp.h:193
Definition: bd.h:196
static const TFSet RelOpSymSet
Definition: exp.h:197
TLxSym GetSym(const TFSet &Expect)
Definition: lx.cpp:315
bool In(const int &FlagN) const
Definition: bits.h:156

Here is the call graph for this function:

Here is the caller graph for this function:

TExp& TExp::operator= ( const TExp )
inline

Definition at line 231 of file exp.h.

References Fail.

231 {Fail; return *this;}
#define Fail
Definition: bd.h:238
bool TExp::operator== ( const TExp ) const
inline

Definition at line 232 of file exp.h.

References Fail.

232 {Fail; return false;}
#define Fail
Definition: bd.h:238
void TExp::Save ( TSOut SOut) const
inline

Definition at line 226 of file exp.h.

226  {
227  ExpType.Save(SOut); IsParen.Save(SOut);
228  ExpVal.Save(SOut); ExpNm.Save(SOut); ExpOp.Save(SOut);
229  ExpBiId.Save(SOut); ArgExpV.Save(SOut);}
void Save(TSOut &SOut) const
Definition: dt.h:1057
void Save(TSOut &SOut) const
Definition: dt.h:902
TInt ExpBiId
Definition: exp.h:194
void Save(TSOut &SOut) const
Definition: ds.h:885
TBool IsParen
Definition: exp.h:190
void Save(TSOut &SOut, const bool &IsSmall=false) const
Definition: dt.h:440
TInt ExpType
Definition: exp.h:189
TInt ExpOp
Definition: exp.h:193
void Save(TSOut &SOut) const
Definition: xmlser.h:16
PExpVal ExpVal
Definition: exp.h:191
TStr ExpNm
Definition: exp.h:192
TExpV ArgExpV
Definition: exp.h:195
void TExp::SaveTxt ( TOLx Lx) const

Definition at line 823 of file exp.cpp.

References ArgExpV, etBiConst, etBiFunc, etFunc, etLst, etOp, etVal, etVar, etVec, ExpNm, ExpType, ExpVal, Fail, IsParen, TVec< TVal, TSizeTy >::Len(), TOLx::PutIdStr(), TOLx::PutSym(), TExpVal::SaveTxt(), SaveTxtOp(), syComma, syLBrace, syLBracket, syLParen, syRBrace, syRBracket, and syRParen.

Referenced by GetStr().

823  {
824  if (IsParen){Lx.PutSym(syLParen);}
825  TExpType _ExpType=TExpType(int(ExpType));
826  switch (_ExpType){
827  case etVal:
828  ExpVal->SaveTxt(Lx); break;
829  case etVec:{
830  Lx.PutSym(syLBrace);
831  for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
832  if (ArgExpN>0){Lx.PutSym(syComma);}
833  ArgExpV[ArgExpN]->SaveTxt(Lx);
834  }
835  Lx.PutSym(syRBrace);
836  break;}
837  case etLst:{
838  Lx.PutSym(syLBracket);
839  for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
840  if (ArgExpN>0){Lx.PutSym(syComma);}
841  ArgExpV[ArgExpN]->SaveTxt(Lx);
842  }
843  Lx.PutSym(syRBracket);
844  break;}
845  case etOp:
846  SaveTxtOp(Lx); break;
847  case etVar:
848  case etBiConst:
849  Lx.PutIdStr(ExpNm); break;
850  case etFunc:
851  case etBiFunc:{
852  Lx.PutIdStr(ExpNm);
853  Lx.PutSym(syLParen);
854  for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
855  if (ArgExpN>0){Lx.PutSym(syComma);}
856  ArgExpV[ArgExpN]->SaveTxt(Lx);
857  }
858  Lx.PutSym(syRParen);
859  break;}
860  default: Fail;
861  }
862  if (IsParen){Lx.PutSym(syRParen);}
863 }
Definition: exp.h:171
Definition: lx.h:50
Definition: exp.h:170
Definition: lx.h:50
void SaveTxt(TOLx &Lx) const
Definition: exp.cpp:71
#define Fail
Definition: bd.h:238
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
void PutSym(const TLxSym &Sym)
Definition: lx.cpp:751
TBool IsParen
Definition: exp.h:190
Definition: lx.h:50
Definition: exp.h:170
Definition: exp.h:171
Definition: lx.h:50
void SaveTxtOp(TOLx &Lx) const
Definition: exp.cpp:744
TInt ExpType
Definition: exp.h:189
Definition: lx.h:50
PExpVal ExpVal
Definition: exp.h:191
Definition: lx.h:46
Definition: exp.h:170
Definition: exp.h:171
Definition: exp.h:171
TExpType
Definition: exp.h:168
TStr ExpNm
Definition: exp.h:192
Definition: lx.h:50
TExpV ArgExpV
Definition: exp.h:195
Definition: exp.h:171
void PutIdStr(const TStr &Str, const bool &CheckIdStr=true)
Definition: lx.h:286

Here is the call graph for this function:

Here is the caller graph for this function:

void TExp::SaveTxt ( const PSOut SOut) const
inline

Definition at line 244 of file exp.h.

References oloCmtAlw, oloCsSens, and oloSigNum.

244  {
245  TOLx Lx(SOut, TFSet()|oloCmtAlw|oloSigNum|oloCsSens); SaveTxt(Lx);}
Definition: lx.h:248
void SaveTxt(TOLx &Lx) const
Definition: exp.cpp:823
Definition: bits.h:119
Definition: lx.h:251
Definition: lx.h:249
Definition: lx.h:248
void TExp::SaveTxtOp ( TOLx Lx) const
private

Definition at line 744 of file exp.cpp.

References ArgExpV, eoAnd, eoDiv, eoEq, eoGEq, eoGtr, eoIDiv, eoIf, eoLEq, eoLss, eoMinus, eoMod, eoMul, eoNEq, eoNot, eoOr, eoPlus, eoUMinus, eoUPlus, etOp, ExpOp, ExpType, Fail, GetLxSymFromExpOp(), IAssert, TOLx::PutSym(), and syColon.

Referenced by SaveTxt().

744  {
745  IAssert(TExpType(static_cast<int>(ExpType))==etOp);
746  TExpOp _ExpOp=TExpOp(int(ExpOp));
747  TLxSym OpSym=GetLxSymFromExpOp(_ExpOp);
748  switch (_ExpOp){
749  case eoUPlus:
750  case eoUMinus:
751  case eoNot:
752  Lx.PutSym(OpSym); ArgExpV[0]->SaveTxt(Lx);
753  break;
754  case eoPlus: case eoMinus:
755  case eoMul: case eoDiv:
756  case eoIDiv: case eoMod:
757  case eoAnd: case eoOr:
758  case eoEq: case eoNEq:
759  case eoLss: case eoGtr:
760  case eoLEq: case eoGEq:
761  ArgExpV[0]->SaveTxt(Lx); Lx.PutSym(OpSym); ArgExpV[1]->SaveTxt(Lx);
762  break;
763  case eoIf:
764  ArgExpV[0]->SaveTxt(Lx); Lx.PutSym(OpSym);
765  ArgExpV[1]->SaveTxt(Lx); Lx.PutSym(syColon); ArgExpV[2]->SaveTxt(Lx);
766  break;
767  default: Fail;
768  }
769 }
#define IAssert(Cond)
Definition: bd.h:262
static TLxSym GetLxSymFromExpOp(const TExpOp &ExpOp)
Definition: exp.cpp:628
Definition: exp.h:180
TExpOp
Definition: exp.h:175
Definition: exp.h:179
Definition: exp.h:180
#define Fail
Definition: bd.h:238
TLxSym
Definition: lx.h:44
Definition: exp.h:180
void PutSym(const TLxSym &Sym)
Definition: lx.cpp:751
Definition: exp.h:178
Definition: exp.h:181
Definition: exp.h:178
Definition: exp.h:180
Definition: exp.h:179
Definition: exp.h:180
Definition: exp.h:171
Definition: exp.h:178
Definition: exp.h:179
Definition: exp.h:180
Definition: exp.h:178
Definition: exp.h:177
TInt ExpType
Definition: exp.h:189
Definition: exp.h:178
TInt ExpOp
Definition: exp.h:193
Definition: lx.h:46
Definition: exp.h:177
TExpType
Definition: exp.h:168
Definition: exp.h:178
TExpV ArgExpV
Definition: exp.h:195

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class TPt< TExp >
friend

Definition at line 186 of file exp.h.

Member Data Documentation

const TFSet TExp::AddExpExpect
staticprivate

Definition at line 198 of file exp.h.

Referenced by LoadTxtRelExp().

const TFSet TExp::AddOpSymSet
staticprivate

Definition at line 197 of file exp.h.

Referenced by LoadTxtAddExp().

TExpV TExp::ArgExpV
private

Definition at line 195 of file exp.h.

Referenced by EvalExp(), EvalExpOp(), GetArgExps(), GetArgExpStr(), LoadTxtFact(), SaveTxt(), SaveTxtOp(), and TExp().

TCRef TExp::CRef
private

Definition at line 186 of file exp.h.

TExpBi TExp::ExpBi
staticprivate

Definition at line 188 of file exp.h.

Referenced by EvalExp(), and TExp().

TInt TExp::ExpBiId
private

Definition at line 194 of file exp.h.

Referenced by EvalExp(), and TExp().

const TFSet TExp::ExpExpect
staticprivate

Definition at line 199 of file exp.h.

Referenced by LoadAndEvalExpL(), LoadTxt(), LoadTxtExp(), and LoadTxtFact().

TStr TExp::ExpNm
private

Definition at line 192 of file exp.h.

Referenced by EvalExp(), GetTopObjNm(), LoadTxtFact(), SaveTxt(), and TExp().

TInt TExp::ExpOp
private
TInt TExp::ExpType
private

Definition at line 189 of file exp.h.

Referenced by EvalExp(), GetTopObjNm(), SaveTxt(), SaveTxtOp(), and TExp().

PExpVal TExp::ExpVal
private

Definition at line 191 of file exp.h.

Referenced by Eval(), EvalExp(), EvalExpOp(), LoadAndEvalExpL(), LoadTxtFact(), and SaveTxt().

const TFSet TExp::FactExpExpect
staticprivate

Definition at line 198 of file exp.h.

Referenced by LoadTxtMulExp().

TBool TExp::IsParen
private

Definition at line 190 of file exp.h.

Referenced by SaveTxt().

const TFSet TExp::MulExpExpect
staticprivate

Definition at line 198 of file exp.h.

Referenced by LoadTxtAddExp().

const TFSet TExp::MulOpSymSet
staticprivate

Definition at line 197 of file exp.h.

Referenced by LoadTxtMulExp().

const TFSet TExp::RelExpExpect
staticprivate

Definition at line 199 of file exp.h.

const TFSet TExp::RelOpSymSet
staticprivate

Definition at line 197 of file exp.h.

Referenced by LoadTxtRelExp().

const TFSet TExp::UAddOpSymSet
staticprivate

Definition at line 197 of file exp.h.


The documentation for this class was generated from the following files: