SNAP Library , Developer Reference  2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TExp Class Reference

#include <exp.h>

Collaboration diagram for TExp:

List of all members.

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().

                                        :
    ExpType(_ExpType), IsParen(false),
    ExpVal(), ExpNm(), ExpOp(), ExpBiId(), ArgExpV(){}

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 >::Add(), ArgExpV, and TPt< TRec >::Empty().

                                                      :
  ExpType(etOp), IsParen(false),
  ExpVal(), ExpNm(), ExpOp(_ExpOp), ExpBiId(), ArgExpV(){
  ArgExpV.Add(Exp1);
  if (!Exp2.Empty()){ArgExpV.Add(Exp2);}
  if (!Exp3.Empty()){ArgExpV.Add(Exp3);}
}

Here is the call graph for this function:

TExp::TExp ( const PExpVal _ExpVal)

Definition at line 780 of file exp.cpp.

                                :
  ExpType(etVal), IsParen(false),
  ExpVal(_ExpVal), ExpNm(), ExpOp(), ExpBiId(), ArgExpV(){}
TExp::TExp ( const TStr _VarNm)

Definition at line 784 of file exp.cpp.

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

                            :
  ExpType(), IsParen(false),
  ExpVal(), ExpNm(_VarNm), ExpOp(), ExpBiId(), ArgExpV(){
  TExpBiId _ExpBiId;
  if (ExpBi.IsExpBiId(ExpNm, _ExpBiId)){
    ExpType=etBiConst;
    ExpBiId=TInt(int(_ExpBiId));
  } else {
    ExpType=etVar;
  }
}

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().

                                                    :
  ExpType(), IsParen(false),
  ExpVal(), ExpNm(_FuncNm), ExpOp(), ExpBiId(), ArgExpV(_ArgExpV){
  TExpBiId _ExpBiId;
  if (ExpBi.IsExpBiId(ExpNm, _ExpBiId)){
    ExpType=etBiFunc;
    ExpBiId=TInt(int(_ExpBiId));
  } else {
    ExpType=etFunc;
  }
}

Here is the call graph for this function:

TExp::~TExp ( ) [inline]

Definition at line 221 of file exp.h.

{}
TExp::TExp ( TSIn SIn) [inline]

Definition at line 222 of file exp.h.

                 :
    ExpType(SIn), IsParen(SIn),
    ExpVal(SIn), ExpNm(SIn), ExpOp(SIn), ExpBiId(SIn), ArgExpV(SIn){}

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().

                                                                               {
  Ok=true; MsgStr="Ok";
  PExpVal ExpVal; TChA DbgChA;
  if (DbgP){DbgChA+="Debug Expression: ";}
  try {
    ExpVal=EvalExp(ExpEnv, DbgP, DbgChA);
  }
  catch (PExcept E){
    Ok=false; MsgStr=E->GetMsgStr();
  }
  if (!Ok){return TExpVal::GetUndefExpVal();}
  if (DbgP){
    DbgChA+='['; DbgChA+=GetStr(); DbgChA+=" -> ";
    DbgChA+=ExpVal->GetStr(); DbgChA+="] "; DbgChA+=MsgStr;
    DbgStr=DbgChA;
  }
  return ExpVal;
}

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.

                                                     {
    bool Ok; TStr MsgStr; TStr DbgStr;
    return Eval(Ok, MsgStr, false, DbgStr, ExpEnv);}
PExpVal TExp::Eval ( bool &  Ok,
TStr MsgStr,
const PExpEnv ExpEnv = TExpEnv::DfExpEnv 
) [inline]

Definition at line 256 of file exp.h.

                                                                             {
    TStr DbgStr; return Eval(Ok, MsgStr, false, DbgStr, ExpEnv);}
PExpVal TExp::Eval ( const PExpEnv ExpEnv,
const bool &  DbgP,
TStr DbgStr 
) [inline]

Definition at line 258 of file exp.h.

                                                                     {
    bool Ok; TStr MsgStr; return Eval(Ok, MsgStr, DbgP, DbgStr, ExpEnv);}
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 >::Len(), TExpVal::New(), and TExcept::Throw().

Referenced by Eval().

                                                       {
  PExpVal OutExpVal;
  TExpType _ExpType=TExpType(int(ExpType));
  switch (_ExpType){
    case etUndef:
      OutExpVal=TExpVal::GetUndefExpVal();
      break;
    case etVal:
      OutExpVal=ExpVal;
      break;
    case etVec:{
      PExpVal ExpVal=TExpVal::New(evtVec);
      for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
        PExpVal ArgExpVal=
         PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
        ExpVal->AddToVec(ArgExpVal);
      }
      OutExpVal=ExpVal;
      break;}
    case etLst:{
      PExpVal ExpVal=TExpVal::New(evtLst);
      for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
        PExpVal ArgExpVal=
         PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
        ExpVal->AddToLst(ArgExpVal);
      }
      OutExpVal=ExpVal;
      break;}
    case etOp:
      OutExpVal=EvalExpOp(ExpEnv, DbgP, DbgChA); break;
    case etVar:{
      bool IsVar=false;
      PExpVal ExpVal=ExpEnv->GetVarVal(ExpNm.GetUc(), IsVar);
      if (!IsVar){TExcept::Throw(TStr("Variable not defined (")+ExpNm+").");}
      OutExpVal=ExpVal;
      break;}
    case etBiConst:
      OutExpVal=ExpBi.GetBiConstVal(TExpBiId(int(ExpBiId)));
      break;
    case etFunc:
    case etBiFunc:{
      TExpValV ArgExpValV(ArgExpV.Len(), 0);
      for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
        PExpVal ArgExpVal=
         PExpVal(ArgExpV[ArgExpN]->EvalExp(ExpEnv, DbgP, DbgChA));
        ArgExpValV.Add(ArgExpVal);
      }
      switch (_ExpType){
        case etFunc:{
          bool IsFunc=false;
          PExpVal ExpVal=ExpEnv->GetFuncVal(ExpNm.GetUc(), ArgExpValV, IsFunc);
          if (!IsFunc){
            TExcept::Throw(TStr("Function not defined (")+ExpNm+").");}
          OutExpVal=ExpVal;
          break;}
        case etBiFunc:
          OutExpVal=ExpBi.GetBiFuncVal(TExpBiId(int(ExpBiId)), ArgExpValV, ExpEnv);
          break;
        default: Fail; OutExpVal=NULL;
      }
      break;}
    default: Fail; OutExpVal=NULL;
  }
  if (DbgP){
    switch (_ExpType){
      case etVal:
      case etOp:
        break;
      case etUndef:
      case etVec:
      case etLst:{
        TStr ExpTypeStr=TExp::GetExpTypeStr(_ExpType);
        DbgChA+='['; DbgChA+=ExpTypeStr; DbgChA+='=';
        DbgChA+=OutExpVal->GetStr(); DbgChA+="] ";
        break;}
      case etVar:
      case etBiConst:
      case etFunc:
      case etBiFunc:
        DbgChA+='['; DbgChA+=ExpNm; DbgChA+='=';
        DbgChA+=OutExpVal->GetStr(); DbgChA+="] ";
        break;
      default: Fail;
    }
  }
  return OutExpVal;
}

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().

                                                       {
  PExpVal OutExpVal;
  TExpOp _ExpOp=TExpOp(int(ExpOp));
  switch (_ExpOp){
    case eoUPlus:
    case eoUMinus:
    case eoNot:{
      PExpVal ExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
      TExpValType ExpValType=ExpVal->GetValType();
      if (ExpValType==evtFlt){
        TFlt Flt;
        switch (_ExpOp){
          case eoUPlus: Flt=ExpVal->GetFltVal(); break;
          case eoUMinus: Flt=-ExpVal->GetFltVal(); break;
          case eoNot: Flt=double(ExpVal->GetFltValAsInt()==0);
          default: Fail; Flt=0;
        }
        OutExpVal=TExpVal::New(Flt);
      } else {
        TExcept::Throw("Bad argument types.");
      }
      break;}
    case eoPlus:
    case eoMinus:
    case eoMul:
    case eoDiv:
    case eoIDiv:
    case eoMod:
    case eoAnd:
    case eoOr:{
      PExpVal LExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
      PExpVal RExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
      TExpValType LExpValType=LExpVal->GetValType();
      TExpValType RExpValType=RExpVal->GetValType();
      if ((LExpValType==evtFlt)&&(RExpValType==evtFlt)){
        // check left expression
        double LVal=LExpVal->GetFltVal();
        int LValExpon; frexp(LVal, &LValExpon);
        if (LValExpon>150){LExpVal=TExpVal::GetZeroExpVal();}
        // check right expression
        double RVal=LExpVal->GetFltVal();
        int RValExpon; frexp(RVal, &RValExpon);
        if (RValExpon>150){RExpVal=TExpVal::GetZeroExpVal();}
        // calculate
        TFlt Flt;
        switch (_ExpOp){
          case eoPlus: Flt=LExpVal->GetFltVal()+RExpVal->GetFltVal(); break;
          case eoMinus: Flt=LExpVal->GetFltVal()-RExpVal->GetFltVal(); break;
          case eoMul: Flt=LExpVal->GetFltVal()*RExpVal->GetFltVal(); break;
          case eoDiv:
            if (RExpVal->GetFltVal()==0){TExcept::Throw("Division by zero.");}
            else {Flt=LExpVal->GetFltVal()/RExpVal->GetFltVal();}
            break;
          case eoIDiv:
            if (RExpVal->GetFltValAsInt()==0){TExcept::Throw("Division by zero.");}
            else {Flt=LExpVal->GetFltValAsInt()/RExpVal->GetFltValAsInt();}
            break;
          case eoMod:
            if (RExpVal->GetFltValAsInt()==0){TExcept::Throw("Division by zero.");}
            else {Flt=LExpVal->GetFltValAsInt()%RExpVal->GetFltValAsInt();}
            break;
          case eoAnd:
            Flt=(LExpVal->GetFltValAsInt()!=0)&&(RExpVal->GetFltValAsInt()!=0); break;
          case eoOr:
            Flt=(LExpVal->GetFltValAsInt()!=0)||(RExpVal->GetFltValAsInt()!=0); break;
          default: Fail; Flt=0;
        }
        OutExpVal=TExpVal::New(Flt);
      } else
      if ((_ExpOp==eoPlus)&&(LExpValType==evtStr)&&(RExpValType==evtStr)){
        TStr Str=LExpVal->GetStrVal()+RExpVal->GetStrVal();
        OutExpVal=TExpVal::New(Str);
      } else {
        TExcept::Throw("Bad argument types.");
      }
      break;}
    case eoEq:
    case eoNEq:
    case eoLss:
    case eoGtr:
    case eoLEq:
    case eoGEq:{
      PExpVal LExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
      PExpVal RExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
      TExpValType LExpValType=LExpVal->GetValType();
      TExpValType RExpValType=RExpVal->GetValType();
      if ((LExpValType==evtFlt)&&(RExpValType==evtFlt)){
        TFlt Flt;
        switch (_ExpOp){
          case eoEq: Flt=double(LExpVal->GetFltVal()==RExpVal->GetFltVal()); break;
          case eoNEq: Flt=double(LExpVal->GetFltVal()!=RExpVal->GetFltVal()); break;
          case eoLss: Flt=double(LExpVal->GetFltVal()<RExpVal->GetFltVal()); break;
          case eoGtr: Flt=double(LExpVal->GetFltVal()>RExpVal->GetFltVal()); break;
          case eoLEq: Flt=double(LExpVal->GetFltVal()<=RExpVal->GetFltVal()); break;
          case eoGEq: Flt=double(LExpVal->GetFltVal()>=RExpVal->GetFltVal()); break;
          default: Fail; Flt=0;
        }
        OutExpVal=TExpVal::New(Flt);
      } else
      if ((LExpValType==evtStr)&&(RExpValType==evtStr)){
        TFlt Flt;
        switch (_ExpOp){
          case eoEq: Flt=double(LExpVal->GetStrVal()==RExpVal->GetStrVal()); break;
          case eoNEq: Flt=double(LExpVal->GetStrVal()!=RExpVal->GetStrVal()); break;
          case eoLss: Flt=double(LExpVal->GetStrVal()<RExpVal->GetStrVal()); break;
          case eoGtr: Flt=double(LExpVal->GetStrVal()>RExpVal->GetStrVal()); break;
          case eoLEq: Flt=double(LExpVal->GetStrVal()<=RExpVal->GetStrVal()); break;
          case eoGEq: Flt=double(LExpVal->GetStrVal()>=RExpVal->GetStrVal()); break;
          default: Fail; Flt=0;
        }
        OutExpVal=TExpVal::New(Flt);
      } else {
        TExcept::Throw("Bad argument types.");
      }
      break;}
    case eoIf:{
      PExpVal CondExpVal=ArgExpV[0]->EvalExp(ExpEnv, DbgP, DbgChA);
      TExpValType CondExpValType=CondExpVal->GetValType();
      if (CondExpValType==evtFlt){
        PExpVal ExpVal;
        if (CondExpVal->GetFltVal()!=0){
          ExpVal=ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
        } else {
          ExpVal=ArgExpV[2]->EvalExp(ExpEnv, DbgP, DbgChA);
        }
        OutExpVal=ExpVal;
      } else {
        TExcept::Throw("Bad argument types.");
      }
      break;}
    default: Fail; OutExpVal=NULL;
  }
  if (DbgP){
    DbgChA+="['"; DbgChA+=TExp::GetExpOpStr(_ExpOp);
    DbgChA+="'='"; DbgChA+=OutExpVal->GetStr(); DbgChA+="'] ";
  }
  return OutExpVal;
}

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 >::Len().

                           {
  return ArgExpV.Len();
}

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.

                                                {
  return ArgExpV[ArgExpN]->GetStr();
}
void TExp::GetBiDescV ( TStrPrV BiDescV) [static]

Definition at line 967 of file exp.cpp.

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

                                     {
  BiDescV.Clr();
  // constants
  BiDescV.Add(TStrPr("True", "Logical 'True' == 1."));
  BiDescV.Add(TStrPr("False", "Logical 'False' == 0."));
  BiDescV.Add(TStrPr("E", "Nat. logarithm basis (2.7182...)."));
  BiDescV.Add(TStrPr("Pi", "Constant pi (3.1415...)."));

  // trigonometric funcions
  BiDescV.Add(TStrPr("Sin(X)", "Sine of angle in radians."));
  BiDescV.Add(TStrPr("Cos(X)", "Cosine of angle in radians."));
  BiDescV.Add(TStrPr("Tan(X)", "Tangent of angle in radians."));
  BiDescV.Add(TStrPr("ASin(X)", "Arc sine of (-1..+1)."));
  BiDescV.Add(TStrPr("ACos(X)", "Arc cosine of (-1..+1)."));
  BiDescV.Add(TStrPr("ATan(X)", "Arc tangent of (-inf..+inf)."));
  BiDescV.Add(TStrPr("SinH(X)", "Hyperbolic sine."));
  BiDescV.Add(TStrPr("CosH(X)", "Hyperbolic cosine."));
  BiDescV.Add(TStrPr("TanH(X)", "Hyperbolic tangent."));

  // exponential functions
  BiDescV.Add(TStrPr("Pow(X, Y)", "X to the power of Y."));
  BiDescV.Add(TStrPr("Exp(X)", "Exponential E to the power of X."));
  BiDescV.Add(TStrPr("Sqr(X)", "X squared."));
  BiDescV.Add(TStrPr("Sqrt(X)", "Positive square root."));
  BiDescV.Add(TStrPr("Log(X)", "Natural logarithm."));
  BiDescV.Add(TStrPr("Log10(X)", "Base 10 logarithm."));

  // number manipulation functions
  BiDescV.Add(TStrPr("Ceil(X)", "The smallest integer not less than X."));
  BiDescV.Add(TStrPr("Floor(X)", "The largest integer not greater than X."));
  BiDescV.Add(TStrPr("Int(X)", "Integer part of X."));
  BiDescV.Add(TStrPr("Frac(X)", "Fractional part of X."));
  BiDescV.Add(TStrPr("Abs(X)", "Absolute value of X."));

  // random deviates
  BiDescV.Add(TStrPr("UniDev()", "Uniform deviate (0..1)."));
  BiDescV.Add(TStrPr("NrmDev()", "Normal deviate (0, 1)."));
  BiDescV.Add(TStrPr("ExpDev()", "Exponential deviate."));
  BiDescV.Add(TStrPr("GamDev(Order)", "Gamma deviate of Order."));
  BiDescV.Add(TStrPr("PoiDev(Mean)", "Poisson deviate."));
  BiDescV.Add(TStrPr("BinDev(Prb, Trials)", "Binomial deviate."));

  // operators
  BiDescV.Add(TStrPr("+N", "Unary plus."));
  BiDescV.Add(TStrPr("-N", "Unary minus."));
  BiDescV.Add(TStrPr("!L", "Not."));
  BiDescV.Add(TStrPr("N1+N2", "Plus."));
  BiDescV.Add(TStrPr("N1-N2", "Minus."));
  BiDescV.Add(TStrPr("N1*N2", "Multiply."));
  BiDescV.Add(TStrPr("N1/N2", "Division."));
  BiDescV.Add(TStrPr("N1#N2", "Integer division."));
  BiDescV.Add(TStrPr("N1%N2", "Modulo."));
  BiDescV.Add(TStrPr("L1&L2", "And."));
  BiDescV.Add(TStrPr("L1|L2", "Or."));
  BiDescV.Add(TStrPr("E1=E2", "Equal."));
  BiDescV.Add(TStrPr("E1<>E2", "Not equal."));
  BiDescV.Add(TStrPr("E1<E2", "Less."));
  BiDescV.Add(TStrPr("E1>E2", "Greater."));
  BiDescV.Add(TStrPr("E1<=E2", "Less or equal."));
  BiDescV.Add(TStrPr("E1>=E2", "Greater or equal."));
  BiDescV.Add(TStrPr("L?E1:E2", "If L then return E1 else return E2."));
}

Here is the call graph for this function:

TExpOp TExp::GetExpOpFromLxSym ( const TLxSym LxSym) [static, private]

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().

                                                 {
  switch (LxSym){
    case syPlus: return eoPlus;
    case syMinus: return eoMinus;
    case syAsterisk: return eoMul;
    case sySlash: return eoDiv;
    case syPercent: return eoMod;
    case syExclamation: return eoNot;
    case syVBar: return eoOr;
    case syAmpersand: return eoAnd;
    case syQuestion: return eoIf;
    case syHash: return eoIDiv;
    case syEq: return eoEq;
    case syNEq: return eoNEq;
    case syLss: return eoLss;
    case syGtr: return eoGtr;
    case syLEq: return eoLEq;
    case syGEq: return eoGEq;
    default: Fail; return eoUndef;
  }
}

Here is the caller graph for this function:

static TStr TExp::GetExpOpStr ( const TExpOp ExpOp) [inline, static]

Definition at line 266 of file exp.h.

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

Referenced by EvalExpOp(), and GetTopObjNm().

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().

                                               {
  switch (ExpType){
    case etUndef: return "Undef";
    case etVal: return "Val";
    case etVec: return "Vec";
    case etLst: return "Lst";
    case etOp: return "Op";
    case etVar: return "Var";
    case etBiConst: return "BiConst";
    case etFunc: return "Func";
    case etBiFunc: return "BiFunc";
    default: Fail; return "";
  }
}

Here is the caller graph for this function:

TLxSym TExp::GetLxSymFromExpOp ( const TExpOp ExpOp) [static, private]

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().

                                                 {
  switch (ExpOp){
    case eoUPlus: return syPlus;
    case eoUMinus: return syMinus;
    case eoNot: return syExclamation;
    case eoPlus: return syPlus;
    case eoMinus: return syMinus;
    case eoMul: return syAsterisk;
    case eoDiv: return sySlash;
    case eoIDiv: return syHash;
    case eoMod: return syPercent;
    case eoAnd: return syAmpersand;
    case eoOr: return syVBar;
    case eoEq: return syEq;
    case eoNEq: return syNEq;
    case eoLss: return syLss;
    case eoGtr: return syGtr;
    case eoLEq: return syLEq;
    case eoGEq: return syGEq;
    case eoIf: return syQuestion;
    default: Fail; return syUndef;
  }
}

Here is the caller graph for this function:

TStr TExp::GetStr ( ) const

Definition at line 865 of file exp.cpp.

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

Referenced by Eval().

                        {
  PSOut SOut=TMOut::New(); TMOut& MOut=*(TMOut*)SOut();
  SaveTxt(SOut);
  TStr ExpStr=TStr::LoadTxt(MOut.GetSIn());
  return ExpStr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 872 of file exp.cpp.

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

                             {
  TStr TopObjNm;
  TExpType _ExpType=TExpType(int(ExpType));
  switch (_ExpType){
    case etOp:{
      TExpOp _ExpOp=TExpOp(int(ExpOp));
      TopObjNm=GetExpOpStr(_ExpOp);
      break;}
    case etVar:
    case etBiConst:
    case etFunc:
    case etBiFunc:{
      TopObjNm=ExpNm; break;}
    default: break;
  }
  return TopObjNm;
}

Here is the call graph for this function:

static bool TExp::IsExpStrOk ( const TStr ExpStr,
TStr MsgStr 
) [inline, static]

Definition at line 234 of file exp.h.

                                                          {
    bool Ok; LoadTxt(ExpStr, Ok, MsgStr); return Ok;}
static PExp TExp::Load ( TSIn SIn) [inline, static]

Definition at line 225 of file exp.h.

{return PExp(new TExp(SIn));}
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().

                                                                    {
  // create final expression value
  PExpVal ExpVal;
  // transform exp. str. to input stream
  PSIn SIn=TStrIn::New(ExpLStr);
  // create lexical
  TILx Lx(SIn, TFSet()|iloCmtAlw|iloCsSens|iloExcept);
  TFSet Expect=TFSet()|sySemicolon|syEof;
  // load & evaluate expression separated by semicolon
  while (Lx.Sym!=syEof){
    // create expression
    PExp Exp; Ok=true; MsgStr="Ok";
    try {
      Lx.GetSym(ExpExpect);
      Exp=LoadTxtExp(Lx, Expect);
    }
    catch (PExcept Except){
      Ok=false; MsgStr=Except->GetMsgStr();
      Exp=PExp(new TExp(etUndef));
    }
    // evaluate expression
    if (Ok){
      ExpVal=Exp->Eval(Ok, MsgStr, ExpEnv);
      //printf("%s\n", ExpVal->GetStr().CStr());
      if (!Ok){
        return NULL;}
    } else {
      return NULL;
    }
  }
  return ExpVal;
}

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().

Referenced by GetStr().

                                                              {
  TILx Lx(SIn, TFSet()|iloCmtAlw|iloCsSens|iloExcept);
  PExp Exp; Ok=true; MsgStr="Ok";
  try {
    Lx.GetSym(ExpExpect);
    Exp=LoadTxtExp(Lx, Expect);
  }
  catch (PExcept Except){
    Ok=false; MsgStr=Except->GetMsgStr();
    Exp=PExp(new TExp(etUndef));
  }
  return Exp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PExp TExp::LoadTxt ( const TStr ExpStr,
bool &  Ok,
TStr MsgStr 
) [inline, static]

Definition at line 238 of file exp.h.

References TStrIn::New().

                                                                 {
    PSIn SIn=TStrIn::New(ExpStr); return LoadTxt(SIn, Ok, MsgStr);}

Here is the call graph for this function:

static PExp TExp::LoadTxt ( const TStr ExpStr) [inline, static]

Definition at line 240 of file exp.h.

                                         {
    bool Ok; TStr MsgStr; return LoadTxt(ExpStr, Ok, MsgStr);}
PExp TExp::LoadTxtAddExp ( TILx Lx,
const TFSet Expect 
) [static, private]

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().

                                                     {
  TExpOp PrefExpOp=eoUndef;
  if (Lx.Sym==syPlus){PrefExpOp=eoUPlus; Lx.GetSym(MulExpExpect);}
  else if (Lx.Sym==syMinus){PrefExpOp=eoUMinus; Lx.GetSym(MulExpExpect);}
  PExp Exp=LoadTxtMulExp(Lx, TFSet(Expect)|AddOpSymSet);
  if (PrefExpOp!=eoUndef){
    Exp=PExp(new TExp(PrefExpOp, Exp));}
  while (AddOpSymSet.In(Lx.Sym)){
    TExpOp ExpOp=GetExpOpFromLxSym(Lx.Sym);
    Lx.GetSym(MulExpExpect);
    PExp RExp=LoadTxtMulExp(Lx, TFSet(Expect)|AddOpSymSet);
    Exp=PExp(new TExp(ExpOp, Exp, RExp));
  }
  return Exp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PExp TExp::LoadTxtExp ( TILx Lx,
const TFSet Expect 
) [static, private]

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().

                                                  {
  PExp Exp=LoadTxtRelExp(Lx, TFSet(Expect)|syQuestion);
  if (Lx.Sym==syQuestion){
    TExpOp ExpOp=GetExpOpFromLxSym(Lx.Sym);
    Lx.GetSym(ExpExpect);
    PExp ThenExp=LoadTxtExp(Lx, TFSet()|syColon);
    Lx.GetSym(ExpExpect);
    PExp ElseExp=LoadTxtExp(Lx, Expect);
    Exp=PExp(new TExp(ExpOp, Exp, ThenExp, ElseExp));
  }
  return Exp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PExp TExp::LoadTxtFact ( TILx Lx,
const TFSet Expect 
) [static, private]

Definition at line 652 of file exp.cpp.

References TVec< TVal >::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().

                                                   {
  PExp Exp;
  switch (Lx.Sym){
    case syFlt:{
      PExpVal ExpVal=TExpVal::New(Lx.Flt);
      Exp=PExp(new TExp(ExpVal));
      Lx.GetSym(Expect);
      break;}
    case syIdStr:{
      TStr ExpNm=Lx.Str;
      Lx.GetSym(TFSet(Expect)|syLParen);
      if (Lx.Sym==syLParen){
        TExpV ArgExpV;
        Lx.GetSym(TFSet(ExpExpect)|syRParen);
        while (Lx.Sym!=syRParen){
          if (Lx.Sym==syComma){Lx.GetSym(ExpExpect);}
          PExp ArgExp=LoadTxtExp(Lx, TFSet()|syComma|syRParen);
          ArgExpV.Add(ArgExp);
        }
        Lx.GetSym(Expect);
        Exp=PExp(new TExp(ExpNm, ArgExpV));
      } else {
        Exp=PExp(new TExp(ExpNm));
      }
      break;}
    case syQStr:{
      PExpVal ExpVal=TExpVal::New(Lx.Str);
      Exp=PExp(new TExp(ExpVal));
      Lx.GetSym(Expect);
      break;}
    case syLParen:{
      Lx.GetSym(ExpExpect);
      Exp=LoadTxtExp(Lx, TFSet()|syRParen);
      Exp->IsParen=true;
      Lx.GetSym(Expect);
      break;}
    default: Fail;
  }
  return Exp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PExp TExp::LoadTxtMulExp ( TILx Lx,
const TFSet Expect 
) [static, private]

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().

                                                     {
  PExp Exp=LoadTxtFact(Lx, TFSet(Expect)|MulOpSymSet);
  while (MulOpSymSet.In(Lx.Sym)){
    TExpOp ExpOp=GetExpOpFromLxSym(Lx.Sym);
    Lx.GetSym(FactExpExpect);
    PExp RExp=LoadTxtFact(Lx, TFSet(Expect)|MulOpSymSet);
    Exp=PExp(new TExp(ExpOp, Exp, RExp));
  }
  return Exp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PExp TExp::LoadTxtRelExp ( TILx Lx,
const TFSet Expect 
) [static, private]

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().

                                                     {
  PExp Exp=LoadTxtAddExp(Lx, TFSet(Expect)|RelOpSymSet);
  if (RelOpSymSet.In(Lx.Sym)){
    TExpOp ExpOp=GetExpOpFromLxSym(Lx.Sym);
    Lx.GetSym(AddExpExpect);
    PExp RExp=LoadTxtAddExp(Lx, Expect);
    Exp=PExp(new TExp(ExpOp, Exp, RExp));
  }
  return Exp;
}

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.

{Fail; return *this;}
bool TExp::operator== ( const TExp ) const [inline]

Definition at line 232 of file exp.h.

References Fail.

{Fail; return false;}
void TExp::Save ( TSOut SOut) const [inline]

Definition at line 226 of file exp.h.

                               {
    ExpType.Save(SOut); IsParen.Save(SOut);
    ExpVal.Save(SOut); ExpNm.Save(SOut); ExpOp.Save(SOut);
    ExpBiId.Save(SOut); ArgExpV.Save(SOut);}
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 >::Len(), TOLx::PutIdStr(), TOLx::PutSym(), TExpVal::SaveTxt(), SaveTxtOp(), syComma, syLBrace, syLBracket, syLParen, syRBrace, syRBracket, and syRParen.

Referenced by GetStr().

                                 {
  if (IsParen){Lx.PutSym(syLParen);}
  TExpType _ExpType=TExpType(int(ExpType));
  switch (_ExpType){
    case etVal:
      ExpVal->SaveTxt(Lx); break;
    case etVec:{
      Lx.PutSym(syLBrace);
      for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
        if (ArgExpN>0){Lx.PutSym(syComma);}
        ArgExpV[ArgExpN]->SaveTxt(Lx);
      }
      Lx.PutSym(syRBrace);
      break;}
    case etLst:{
      Lx.PutSym(syLBracket);
      for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
        if (ArgExpN>0){Lx.PutSym(syComma);}
        ArgExpV[ArgExpN]->SaveTxt(Lx);
      }
      Lx.PutSym(syRBracket);
      break;}
    case etOp:
      SaveTxtOp(Lx); break;
    case etVar:
    case etBiConst:
      Lx.PutIdStr(ExpNm); break;
    case etFunc:
    case etBiFunc:{
      Lx.PutIdStr(ExpNm);
      Lx.PutSym(syLParen);
      for (int ArgExpN=0; ArgExpN<ArgExpV.Len(); ArgExpN++){
        if (ArgExpN>0){Lx.PutSym(syComma);}
        ArgExpV[ArgExpN]->SaveTxt(Lx);
      }
      Lx.PutSym(syRParen);
      break;}
    default: Fail;
  }
  if (IsParen){Lx.PutSym(syRParen);}
}

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.

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().

                                   {
  IAssert(TExpType(static_cast<int>(ExpType))==etOp);
  TExpOp _ExpOp=TExpOp(int(ExpOp));
  TLxSym OpSym=GetLxSymFromExpOp(_ExpOp);
  switch (_ExpOp){
    case eoUPlus:
    case eoUMinus:
    case eoNot:
      Lx.PutSym(OpSym); ArgExpV[0]->SaveTxt(Lx);
      break;
    case eoPlus: case eoMinus:
    case eoMul: case eoDiv:
    case eoIDiv: case eoMod:
    case eoAnd: case eoOr:
    case eoEq: case eoNEq:
    case eoLss: case eoGtr:
    case eoLEq: case eoGEq:
      ArgExpV[0]->SaveTxt(Lx); Lx.PutSym(OpSym); ArgExpV[1]->SaveTxt(Lx);
      break;
    case eoIf:
      ArgExpV[0]->SaveTxt(Lx); Lx.PutSym(OpSym);
      ArgExpV[1]->SaveTxt(Lx); Lx.PutSym(syColon); ArgExpV[2]->SaveTxt(Lx);
      break;
    default: Fail;
  }
}

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 [static, private]

Definition at line 198 of file exp.h.

Referenced by LoadTxtRelExp().

const TFSet TExp::AddOpSymSet [static, private]

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 [static, private]

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 [static, private]

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::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 [static, private]

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 [static, private]

Definition at line 198 of file exp.h.

Referenced by LoadTxtAddExp().

const TFSet TExp::MulOpSymSet [static, private]

Definition at line 197 of file exp.h.

Referenced by LoadTxtMulExp().

const TFSet TExp::RelExpExpect [static, private]

Definition at line 199 of file exp.h.

const TFSet TExp::RelOpSymSet [static, private]

Definition at line 197 of file exp.h.

Referenced by LoadTxtRelExp().

const TFSet TExp::UAddOpSymSet [static, private]

Definition at line 197 of file exp.h.


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