14 for (
int VecValN=0; VecValN<ExpVal.
ValV.
Len(); VecValN++){
15 if (*
ValV[VecValN]!=*ExpVal.
ValV[VecValN]){
return false;}}
22 if (*ValLN->
GetVal()!=*ExpValLN->
GetVal()){
return false;}
24 ExpValLN=ExpValLN->
Next();
27 default:
Fail;
return false;
41 if (*
ValV[VecValN]<*ExpVal.
ValV[VecValN]){
return true;}
42 else if (*
ValV[VecValN]==*ExpVal.
ValV[VecValN]){VecValN++;}
50 while ((ValLN!=NULL)&&(ExpValLN!=NULL)){
54 ValLN=ValLN->
Next(); ExpValLN=ExpValLN->
Next();}
58 default:
Fail;
return false;
79 for (
int ValN=0; ValN<
ValV.
Len(); ValN++){
80 ValV[ValN]->SaveTxt(Lx);}
86 for (
int ValN=0; ValN<
ValL.
Len(); ValN++){
109 CloneExpVal->
Flt=ExpVal->
Flt;
110 CloneExpVal->
Str=ExpVal->
Str;
112 for (
int VecValN=0; VecValN<ExpVal->
ValV.
Len(); VecValN++){
116 while (ExpValLN!=NULL){
118 ExpValLN=ExpValLN->
Next();
140 if (RqFuncNm.
GetUc()!=FuncNm.
GetUc()){
return false;}
141 switch (RqFuncArgType){
144 if (ArgValV.
Len()!=1){
return false;}
145 if (ArgValV[0]->GetValType()!=
evtFlt){
return false;}
148 if (ArgValV.
Len()!=1){
return false;}
149 if (ArgValV[0]->GetValType()!=
evtStr){
return false;}
152 if (ArgValV.
Len()!=2){
return false;}
153 if (ArgValV[0]->GetValType()!=
evtFlt){
return false;}
154 if (ArgValV[1]->GetValType()!=
evtFlt){
return false;}
157 if (ArgValV.
Len()!=2){
return false;}
158 if (ArgValV[0]->GetValType()!=
evtFlt){
return false;}
159 if (ArgValV[1]->GetValType()!=
evtStr){
return false;}
162 if (ArgValV.
Len()!=2){
return false;}
163 if (ArgValV[0]->GetValType()!=
evtStr){
return false;}
164 if (ArgValV[1]->GetValType()!=
evtFlt){
return false;}
167 if (ArgValV.
Len()!=2){
return false;}
168 if (ArgValV[0]->GetValType()!=
evtStr){
return false;}
169 if (ArgValV[1]->GetValType()!=
evtStr){
return false;}
172 if (ArgValV.
Len()!=2){
return false;}
173 if (ArgValV[0]->GetValType()!=
evtStr){
return false;}
175 default:
Fail;
return false;
184 ExpBiNmToIdH(100), ExpBiIdToArgTypeH(100){
256 if (RqArgs!=ActArgs){
282 int Args=ArgValV.
Len();
283 double ArgFlt1=0;
double ArgFlt2=0;
284 switch (ExpBiArgType){
291 ArgFlt1=ArgValV[0]->GetFltVal();
break;
296 ArgFlt1=ArgValV[0]->GetFltVal();
297 ArgFlt2=ArgValV[1]->GetFltVal();
break;
325 double Int; modf(ArgFlt1, &Int);
328 double Frac, Int; Frac=modf(ArgFlt1, &Int);
337 int ArgInt1=int(ArgFlt1);
338 ExpVal=
TExpVal::New(ExpEnv->GetRnd().GetGammaDev(ArgInt1));
break;}
340 ExpVal=
TExpVal::New(ExpEnv->GetRnd().GetPoissonDev(ArgFlt1));
break;}
342 int ArgInt2=int(ArgFlt2);
343 ExpVal=
TExpVal::New(ExpEnv->GetRnd().GetBinomialDev(ArgFlt1, ArgInt2));
break;}
345 int ArgInt1=int(ArgFlt1);
if (ArgInt1<0){ArgInt1=0;}
346 int ArgInt2=int(ArgFlt2);
349 int ArgInt1=int(ArgFlt1);
if (ArgInt1<0){ArgInt1=0;}
350 int ArgInt2=int(ArgFlt2);
353 int ArgInt1=int(ArgFlt1);
if (ArgInt1<0){ArgInt1=0;}
354 int ArgInt2=int(ArgFlt2);
378 const PExpEnv& ExpEnv,
const bool& DbgP,
TChA& DbgChA){
393 default:
Fail; Flt=0;
415 int LValExpon; frexp(LVal, &LValExpon);
419 int RValExpon; frexp(RVal, &RValExpon);
443 default:
Fail; Flt=0;
473 default:
Fail; Flt=0;
486 default:
Fail; Flt=0;
496 if (CondExpValType==
evtFlt){
499 ExpVal=
ArgExpV[1]->EvalExp(ExpEnv, DbgP, DbgChA);
501 ExpVal=
ArgExpV[2]->EvalExp(ExpEnv, DbgP, DbgChA);
508 default:
Fail; OutExpVal=NULL;
512 DbgChA+=
"'='"; DbgChA+=OutExpVal->
GetStr(); DbgChA+=
"'] ";
518 const PExpEnv& ExpEnv,
const bool& DbgP,
TChA& DbgChA){
530 for (
int ArgExpN=0; ArgExpN<
ArgExpV.
Len(); ArgExpN++){
539 for (
int ArgExpN=0; ArgExpN<
ArgExpV.
Len(); ArgExpN++){
547 OutExpVal=
EvalExpOp(ExpEnv, DbgP, DbgChA);
break;
560 for (
int ArgExpN=0; ArgExpN<
ArgExpV.
Len(); ArgExpN++){
563 ArgExpValV.Add(ArgExpVal);
576 default:
Fail; OutExpVal=NULL;
579 default:
Fail; OutExpVal=NULL;
590 DbgChA+=
'['; DbgChA+=ExpTypeStr; DbgChA+=
'=';
591 DbgChA+=OutExpVal->
GetStr(); DbgChA+=
"] ";
597 DbgChA+=
'['; DbgChA+=
ExpNm; DbgChA+=
'=';
598 DbgChA+=OutExpVal->
GetStr(); DbgChA+=
"] ";
699 Exp=
PExp(
new TExp(ExpOp, Exp, RExp));
710 Exp=
PExp(
new TExp(PrefExpOp, Exp));}
715 Exp=
PExp(
new TExp(ExpOp, Exp, RExp));
726 Exp=
PExp(
new TExp(ExpOp, Exp, RExp));
739 Exp=
PExp(
new TExp(ExpOp, Exp, ThenExp, ElseExp));
773 ExpType(
etOp), IsParen(false),
774 ExpVal(), ExpNm(), ExpOp(_ExpOp), ExpBiId(), ArgExpV(){
781 ExpType(
etVal), IsParen(false),
782 ExpVal(_ExpVal), ExpNm(), ExpOp(), ExpBiId(), ArgExpV(){}
785 ExpType(), IsParen(false),
786 ExpVal(), ExpNm(_VarNm), ExpOp(), ExpBiId(), ArgExpV(){
797 ExpType(), IsParen(false),
798 ExpVal(), ExpNm(_FuncNm), ExpOp(), ExpBiId(), ArgExpV(_ArgExpV){
809 const PSIn& SIn,
bool& Ok,
TStr& MsgStr,
const TFSet& Expect){
811 PExp Exp; Ok=
true; MsgStr=
"Ok";
817 Ok=
false; MsgStr=Except->GetMsgStr();
831 for (
int ArgExpN=0; ArgExpN<
ArgExpV.
Len(); ArgExpN++){
839 for (
int ArgExpN=0; ArgExpN<
ArgExpV.
Len(); ArgExpN++){
854 for (
int ArgExpN=0; ArgExpN<
ArgExpV.
Len(); ArgExpN++){
884 TopObjNm=
ExpNm;
break;}
895 return ArgExpV[ArgExpN]->GetStr();
899 bool& Ok,
TStr& MsgStr,
const bool& DbgP,
TStr& DbgStr,
const PExpEnv& ExpEnv){
900 Ok=
true; MsgStr=
"Ok";
902 if (DbgP){DbgChA+=
"Debug Expression: ";}
904 ExpVal=
EvalExp(ExpEnv, DbgP, DbgChA);
907 Ok=
false; MsgStr=E->GetMsgStr();
911 DbgChA+=
'['; DbgChA+=
GetStr(); DbgChA+=
" -> ";
912 DbgChA+=ExpVal->
GetStr(); DbgChA+=
"] "; DbgChA+=MsgStr;
930 PExp Exp; Ok=
true; MsgStr=
"Ok";
936 Ok=
false; MsgStr=Except->GetMsgStr();
941 ExpVal=Exp->Eval(Ok, MsgStr, ExpEnv);
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";
961 case etFunc:
return "Func";
963 default:
Fail;
return "";
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...)."));
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."));
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."));
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."));
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."));
1010 BiDescV.
Add(
TStrPr(
"+N",
"Unary plus."));
1011 BiDescV.
Add(
TStrPr(
"-N",
"Unary 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."));
1022 BiDescV.
Add(
TStrPr(
"E1<>E2",
"Not equal."));
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."));
1038 ChA+=OpStr; ChA+=
" "; ChA+=
ArgItemV[0]->GetNm();
1042 ChA+=
" "; ChA+=OpStr; ChA+=
" ";
1047 ChA+=
" "; ChA+=OpStr; ChA+=
" ";
1049 ChA+=
" "; ChA+=
":"; ChA+=
" ";
1062 if (ArgN>0){ChA+=
", ";}
1075 if (TypeStr==
"Op"){
return ehotOp;}
1076 else if (TypeStr==
"Var"){
return ehotVar;}
1077 else if (TypeStr==
"Func"){
return ehotFunc;}
1078 else if (TypeStr==
"Templ"){
return ehotTempl;}
1090 TXmlTokV ObjTokV; Doc->GetTagTokV(
"ExpHelp|Obj", ObjTokV);
1091 for (
int ObjTokN=0; ObjTokN<ObjTokV.
Len(); ObjTokN++){
1092 PXmlTok ObjTok=ObjTokV[ObjTokN];
1106 for (
int ArgTokN=0; ArgTokN<ArgTokV.
Len(); ArgTokN++){
1107 PXmlTok ArgTok=ArgTokV[ArgTokN];
1115 ArgItemV.
Add(ArgItem);
1120 ExpHelp->AddObj(Obj);
1128 for (
int ObjN=0; ObjN<
ObjV.
Len(); ObjN++){
1132 CatNmV.
Ins(0,
"All");
1137 for (
int ObjN=0; ObjN<
ObjV.
Len(); ObjN++){
1138 TStr ObjCatNm=
ObjV[ObjN]->GetCatNm();
1139 TStr ObjHdNm=
ObjV[ObjN]->GetHdItem()->GetNm();
1140 if ((CatNm.
Empty())||(CatNm==
"All")||(CatNm==ObjCatNm)){
1148 for (
int ObjN=0; ObjN<
ObjV.
Len(); ObjN++){
1149 if (
ObjV[ObjN]->GetHdItem()->GetNm().GetUc()==ObjNm.
GetUc()){
TSizeTy AddUnique(const TVal &Val)
Adds element Val to a vector only if the element Val is not already in the vector.
PExpVal GetBiConstVal(const TExpBiId &ExpBiId)
static const TFSet ExpExpect
static TExpOp GetExpOpFromLxSym(const TLxSym &LxSym)
static PExpHelp LoadXml(const PSIn &SIn)
static TLxSym GetLxSymFromExpOp(const TExpOp &ExpOp)
TPair< TStr, TStr > TStrPr
void AddBi(const TStr &ExpBiNm, const TExpBiId &ExpBiId, const TExpBiArgType &ExpBiArgType=ebatUndef)
TStr GetHdArgNmStr() const
void SaveTxt(TOLx &Lx) const
static PExpVal GetUndefExpVal()
PSIn GetSIn(const bool &IsCut=true, const int &CutBfL=-1)
void SaveTxt(TOLx &Lx) const
PExpVal Eval(bool &Ok, TStr &MsgStr, const bool &DbgP, TStr &DbgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
TSizeTy Len() const
Returns the number of elements in the vector.
void GetCatNmV(TStrV &CatNmV) const
static PExpVal GetZeroExpVal()
static PExpHelpObj New(const TExpHelpObjType &Type, const TStr &CatNm, const PExpHelpItem &HdItem, const TExpHelpItemV &ArgItemV=TExpHelpItemV())
static const TFSet AddExpExpect
const TDat & GetDat(const TKey &Key) const
void PutSym(const TLxSym &Sym)
static double Sqr(const double &x)
void PutQStr(const TStr &Str)
PExpHelpObj GetObj(const TStr &ObjNm) const
static PSOut New(const int &MxBfL=1024)
static const TFSet MulOpSymSet
static double GetExpDevStep(const int &Seed, const int &Steps)
static const TFSet FactExpExpect
TStr GetTokStr(const bool &XmlP=true) const
TExp(const TExpType &_ExpType=etUndef)
static PExp LoadTxtFact(TILx &Lx, const TFSet &Expect)
static PExp LoadTxt(const PSIn &SIn, bool &Ok, TStr &MsgStr, const TFSet &Expect=TFSet()|syEof)
TStr GetArgExpStr(const int &ArgExpN) const
static PExp LoadTxtRelExp(TILx &Lx, const TFSet &Expect)
static PExp LoadTxtMulExp(TILx &Lx, const TFSet &Expect)
void AssertArgs(const int &RqArgs, const int &ActArgs)
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
static TExpHelpObjType GetObjTypeFromStr(const TStr &TypeStr)
PExpVal EvalExp(const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA)
static PExpVal ZeroExpVal
static TStr GetExpOpStr(const TExpOp &ExpOp)
static void GetBiDescV(TStrPrV &BiDescV)
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
TExpBiArgType GetExpBiArgType(const TExpBiId &ExpBiId)
static void Throw(const TStr &MsgStr)
void GetObjHdNmV(const TStr &CatNm, TStrV &ObjHdNmV) const
bool operator<(const TExpVal &ExpVal) const
static double GetNrmDevStep(const int &Seed, const int &Steps)
static const TFSet MulExpExpect
static PExp LoadTxtAddExp(TILx &Lx, const TFSet &Expect)
static PSIn New(const TStr &Str)
bool operator==(const TExpVal &ExpVal) const
TExpValType GetValType() const
static const TFSet UAddOpSymSet
void PutFlt(const TFlt &Flt, const int &Width=-1, const int &Prec=-1)
PExpVal GetBiFuncVal(const TExpBiId &ExpBiId, const TExpValV &ArgValV, const PExpEnv &ExpEnv)
bool IsExpBiId(const TStr &ExpBiNm, TExpBiId &ExpBiId)
static double GetUniDevStep(const int &Seed, const int &Steps)
static PExpVal New(const TExpValType &ValType=evtUndef)
void Ins(const TSizeTy &ValN, const TVal &Val)
Inserts new element Val before the element at position ValN.
void SaveTxtOp(TOLx &Lx) const
void AddToVec(const PExpVal &ExpVal)
void AssertArgValType(const TExpValType &ExpValType, const PExpVal &ExpVal)
PLstNd AddBack(const TVal &Val)
PXmlTok GetTagTok(const TStr &TagPath) const
static const TFSet RelExpExpect
void GetTagTokV(const TStr &TagPath, TXmlTokV &XmlTokV) const
PExpVal EvalExpOp(const PExpEnv &ExpEnv, const bool &DbgP, TChA &DbgChA)
static TStr LoadTxt(const PSIn &SIn)
void AddToLst(const PExpVal &ExpVal)
static PXmlDoc LoadTxt(TXmlLx &Lx)
static TStr GetExpTypeStr(const TExpType &ExpType)
static PExp LoadTxtExp(TILx &Lx, const TFSet &Expect)
static bool IsFuncOk(const TStr &RqFuncNm, const TExpFuncArgType &RqFuncArgType, const TStr &FuncNm, const TExpValV &ArgValV)
static PExpHelpItem New(const TStr &Nm, const TStr &TypeStr, const TStr &DescStr, const TStr &DfValStr)
static const TFSet RelOpSymSet
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
static PExpVal MkClone(const PExpVal &ExpVal)
static const TFSet AddOpSymSet
TLxSym GetSym(const TFSet &Expect)
static PExpVal LoadAndEvalExpL(const TStr &ExpLStr, bool &Ok, TStr &MsgStr, const PExpEnv &ExpEnv=TExpEnv::DfExpEnv)
bool IsKey(const TKey &Key) const
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
int GetFltValAsInt(const bool &ThrowExceptP=true) const
TDat & AddDat(const TKey &Key)
TIntIntH ExpBiIdToArgTypeH
static PExpVal UndefExpVal
void PutIdStr(const TStr &Str, const bool &CheckIdStr=true)
bool In(const int &FlagN) const