|
SNAP Library 2.1, User Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <exp.h>
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 |
| TExp & | operator= (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 > |
| TExp::TExp | ( | const TExpType & | _ExpType = etUndef | ) | [inline] |
| TExp::TExp | ( | const TExpOp & | _ExpOp, |
| const PExp & | Exp1, | ||
| const PExp & | Exp2 = NULL, |
||
| const PExp & | Exp3 = NULL |
||
| ) |
| TExp::TExp | ( | const PExpVal & | _ExpVal | ) |
| TExp::TExp | ( | const TStr & | _VarNm | ) |
| TExp::TExp | ( | const TStr & | _FuncNm, |
| const TExpV & | _ArgExpV | ||
| ) |
| TExp::~TExp | ( | ) | [inline] |
| TExp::TExp | ( | TSIn & | SIn | ) | [inline] |
| 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.
{
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;
}
| PExpVal TExp::Eval | ( | const PExpEnv & | ExpEnv = TExpEnv::DfExpEnv | ) | [inline] |
| PExpVal TExp::Eval | ( | bool & | Ok, |
| TStr & | MsgStr, | ||
| const PExpEnv & | ExpEnv = TExpEnv::DfExpEnv |
||
| ) | [inline] |
| PExpVal TExp::Eval | ( | const PExpEnv & | ExpEnv, |
| const bool & | DbgP, | ||
| TStr & | DbgStr | ||
| ) | [inline] |
| PExpVal TExp::EvalExp | ( | const PExpEnv & | ExpEnv, |
| const bool & | DbgP, | ||
| TChA & | DbgChA | ||
| ) | [private] |
Definition at line 517 of file exp.cpp.
{
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;
}
| PExpVal TExp::EvalExpOp | ( | const PExpEnv & | ExpEnv, |
| const bool & | DbgP, | ||
| TChA & | DbgChA | ||
| ) | [private] |
Definition at line 377 of file exp.cpp.
{
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;
}
| int TExp::GetArgExps | ( | ) | const |
| TStr TExp::GetArgExpStr | ( | const int & | ArgExpN | ) | const |
| void TExp::GetBiDescV | ( | TStrPrV & | BiDescV | ) | [static] |
Definition at line 967 of file exp.cpp.
{
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."));
}
| TExpOp TExp::GetExpOpFromLxSym | ( | const TLxSym & | LxSym | ) | [static, private] |
Definition at line 606 of file exp.cpp.
{
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;
}
}
| static TStr TExp::GetExpOpStr | ( | const TExpOp & | ExpOp | ) | [inline, static] |
Definition at line 266 of file exp.h.
{
return TLxSymStr::GetSymStr(TExp::GetLxSymFromExpOp(ExpOp));}
| TStr TExp::GetExpTypeStr | ( | const TExpType & | ExpType | ) | [static] |
Definition at line 952 of file exp.cpp.
{
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 "";
}
}
| TLxSym TExp::GetLxSymFromExpOp | ( | const TExpOp & | ExpOp | ) | [static, private] |
Definition at line 628 of file exp.cpp.
{
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;
}
}
| TStr TExp::GetStr | ( | ) | const |
Definition at line 865 of file exp.cpp.
{
PSOut SOut=TMOut::New(); TMOut& MOut=*(TMOut*)SOut();
SaveTxt(SOut);
TStr ExpStr=TStr::LoadTxt(MOut.GetSIn());
return ExpStr;
}
| TStr TExp::GetTopObjNm | ( | ) | const |
| static bool TExp::IsExpStrOk | ( | const TStr & | ExpStr, |
| TStr & | MsgStr | ||
| ) | [inline, static] |
| static PExp TExp::Load | ( | TSIn & | SIn | ) | [inline, static] |
| PExpVal TExp::LoadAndEvalExpL | ( | const TStr & | ExpLStr, |
| bool & | Ok, | ||
| TStr & | MsgStr, | ||
| const PExpEnv & | ExpEnv = TExpEnv::DfExpEnv |
||
| ) | [static] |
Definition at line 918 of file exp.cpp.
{
// 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;
}
| static PExp TExp::LoadTxt | ( | const TStr & | ExpStr, |
| bool & | Ok, | ||
| TStr & | MsgStr | ||
| ) | [inline, static] |
Definition at line 238 of file exp.h.
{
PSIn SIn=TStrIn::New(ExpStr); return LoadTxt(SIn, Ok, MsgStr);}
| static PExp TExp::LoadTxt | ( | const TStr & | ExpStr | ) | [inline, static] |
| PExp TExp::LoadTxtAddExp | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 704 of file exp.cpp.
{
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;
}
| PExp TExp::LoadTxtExp | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 731 of file exp.cpp.
{
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;
}
| PExp TExp::LoadTxtFact | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 652 of file exp.cpp.
{
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;
}
| PExp TExp::LoadTxtMulExp | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 693 of file exp.cpp.
{
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;
}
| PExp TExp::LoadTxtRelExp | ( | TILx & | Lx, |
| const TFSet & | Expect | ||
| ) | [static, private] |
Definition at line 720 of file exp.cpp.
{
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;
}
| bool TExp::operator== | ( | const TExp & | ) | const [inline] |
| void TExp::Save | ( | TSOut & | SOut | ) | const [inline] |
| void TExp::SaveTxt | ( | TOLx & | Lx | ) | const |
Definition at line 823 of file exp.cpp.
{
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);}
}
| void TExp::SaveTxt | ( | const PSOut & | SOut | ) | const [inline] |
| void TExp::SaveTxtOp | ( | TOLx & | Lx | ) | const [private] |
Definition at line 744 of file exp.cpp.
{
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;
}
}
const TFSet TExp::AddExpExpect [static, private] |
const TFSet TExp::AddOpSymSet [static, private] |
TExpV TExp::ArgExpV [private] |
TCRef TExp::CRef [private] |
TExpBi TExp::ExpBi [static, private] |
TInt TExp::ExpBiId [private] |
const TFSet TExp::ExpExpect [static, private] |
TStr TExp::ExpNm [private] |
TInt TExp::ExpOp [private] |
TInt TExp::ExpType [private] |
PExpVal TExp::ExpVal [private] |
const TFSet TExp::FactExpExpect [static, private] |
TBool TExp::IsParen [private] |
const TFSet TExp::MulExpExpect [static, private] |
const TFSet TExp::MulOpSymSet [static, private] |
const TFSet TExp::RelExpExpect [static, private] |
const TFSet TExp::RelOpSymSet [static, private] |
const TFSet TExp::UAddOpSymSet [static, private] |