PExpVal TExp::LoadAndEvalExpL( const TStr& ExpLStr, bool& Ok, TStr& MsgStr, const PExpEnv& ExpEnv){ // 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; }
PTqlItem TTqlExp::ParseExp(TTqlLx& Lx, const TFSet& Expect){ PTqlItem Item=ParseTerm(Lx, TFSet(Expect)|tsyOr); while (Lx.Sym==tsyOr){ Lx.GetSym(TermExpect); PTqlItem RItem=ParseTerm(Lx, TFSet(Expect)|tsyOr); Item=PTqlItem(new TTqlItem(titOr, Item, RItem)); } return Item; }
PWixExpItem TWixExp::ParseExp(TWixExpLx& Lx, const TFSet& Expect){ PWixExpItem ExpItem=ParseTerm(Lx, TFSet(Expect)|wesyOr); while (Lx.Sym==wesyOr){ Lx.GetSym(TermExpect); PWixExpItem RExpItem=ParseTerm(Lx, TFSet(Expect)|wesyOr); ExpItem=PWixExpItem(new TWixExpItem(weitOr, ExpItem, RExpItem)); } return ExpItem; }
PExp TExp::LoadTxtMulExp(TILx& Lx, const TFSet& Expect){ 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::LoadTxtExp(TILx& Lx, const TFSet& Expect){ 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; }
///////////////////////////////////////////////// // SqlDm-Program PSqlDmProg TSqlDmProg::LoadTxt(PSIn& SIn){ // create object PSqlDmProg Prog=TSqlDmProg::New(); // parse object TSqlDmLx Lx(SIn); Lx.GetSym(TFSet(TSqlDmStat::StatExpect)|dsyEof); while (Lx.Sym!=dsyEof){ PSqlDmStat Stat=TSqlDmStat::LoadTxt(Lx, TFSet(dsySemicolon, dsyEof)); Prog->StatV.Add(Stat); Lx.GetSym(TFSet(TSqlDmStat::StatExpect)|dsyEof); } // return object return Prog; }
bool TLxSymStr::IsSep(const TLxSym& PrevSym, const TLxSym& Sym){ static TFSet SepPrevSymSet=TFSet()| syUndef|syColon|syDColon|syEq| syLParen|syRParen|syLBracket|syRBracket|syLBrace|syRBrace| syEoln|syEof; static TFSet SepSymSet=TFSet()| syPeriod|syComma|syColon|syDColon|sySemicolon| syEq| syExclamation|syQuestion| syLParen|syRParen|syLBracket|syRBracket|syLBrace|syRBrace| syEoln|syEof; return !SepPrevSymSet.In(PrevSym) && !SepSymSet.In(Sym); }
PExp TExp::LoadTxtAddExp(TILx& Lx, const TFSet& Expect){ 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; }
void TNmObjBs::LoadNrWordBs(const PSIn& SIn){ if (SIn.Empty()){return;} TILx Lx(SIn, TFSet(iloCmtAlw, iloRetEoln, iloExcept)); // traverse lines Lx.GetSym(syQStr, syEoln, syEof); while (Lx.Sym!=syEof){ if (Lx.Sym==syQStr){ // get normalized word TStr NrWordStr=Lx.Str; // get inflected words Lx.GetSym(syColon); Lx.GetSym(syQStr, syEoln); while (Lx.Sym!=syEoln){ // get inflected word TStr WordStr=Lx.Str; // test if inflected word already exists if (WordStrToNrH.IsKey(WordStr)){ printf("Word already normalized (%s)", WordStr.CStr());} // add inflected word and corresponding normalized word WordStrToNrH.AddDat(WordStr, NrWordStr); //printf("'%s' ->'%s'\n", WordStr.CStr(), NrWordStr.CStr()); Lx.GetSym(syQStr, syEoln); } Lx.GetSym(syQStr, syEoln, syEof); } else if (Lx.Sym==syEoln){ // empty line Lx.GetSym(syQStr, syEoln, syEof); } else { Fail; } } }
void TYFSelBs::SaveTxt( const PSOut& SOut, const PYBs& YBs, const PYDsBs& YDsBs){ PYWordDs NegWordDs=TYDmDs::GetNegWordDs(YNegDsType, YBs, YDsBs); TOLx Lx(SOut, TFSet()|oloFrcEoln|oloSigNum); for (int DocId=0; DocId<DocIdToWordIdEstVV.Len(); DocId++){ TIntFltKdV& WordIdEstKdV=DocIdToWordIdEstVV[DocId]; TFltIntKdV WordEstIdKdV(WordIdEstKdV.Len(), 0); for (int WordIdN=0; WordIdN<WordIdEstKdV.Len(); WordIdN++){ int WordId=WordIdEstKdV[WordIdN].Key; double WordEst=WordIdEstKdV[WordIdN].Dat; WordEstIdKdV.Add(TFltIntKd(WordEst, WordId)); } WordEstIdKdV.Sort(false); Lx.PutVarStr("UrlStr", YBs->GetDocUrlStr(DocId)); Lx.PutVarInt("DocId", DocId); PYWordDs WordDs=YDsBs->GetWordDs(DocId); Lx.PutVar("WordIdEstKdV", true, true); {for (int WordIdN=0; WordIdN<WordEstIdKdV.Len(); WordIdN++){ double WordEst=WordEstIdKdV[WordIdN].Key; int WordId=WordEstIdKdV[WordIdN].Dat; TStr WordStr=YBs->GetWordStr(WordId); double PosWordPrb=WordDs->GetWordPrb(WordId); double NegWordPrb=NegWordDs->GetWordPrb(WordId); Lx.PutQStr(WordStr); Lx.PutTab(); Lx.PutFlt(WordEst); Lx.PutIndent(1); Lx.PutSym(syLBracket); Lx.PutFlt(PosWordPrb); Lx.PutFlt(NegWordPrb); Lx.PutSym(syRBracket); Lx.PutLn(); }} Lx.PutSym(syRBracket); Lx.PutLn(); } }
void TDzsKwBs::AddHits(const PBook& Book, const TStr& FNm){ PSOut SOut=TFOut::New(FNm); TOLx Lx(SOut, TFSet()|oloFrcEoln|oloSigNum|oloTabSep); int KwToSecIdVP=KwToSecIdVH.FFirstKeyId(); while (KwToSecIdVH.FNextKeyId(KwToSecIdVP)){ TChA QueryChA=KwToSecIdVH.GetKey(KwToSecIdVP); for (int QueryChN=0; QueryChN<QueryChA.Len(); QueryChN++){ if ((' '<QueryChA[QueryChN])&&(QueryChA[QueryChN]<='~')){ if (QueryChA[QueryChN]!='*'){ if (!TCh::IsAlNum(QueryChA[QueryChN])){ QueryChA.PutCh(QueryChN, ' ');} } } } TStr QueryStr=QueryChA; PBixRes BixRes=Book->Search(QueryStr); if (BixRes->IsOk()){ Lx.PutUQStr(QueryStr); Lx.PutUQStr(TInt::GetStr(BixRes->GetHits())); printf("%s - %d\n", QueryStr.CStr(), BixRes->GetHits()); int Hits=BixRes->GetHits(); // TInt::GetMn(BixRes->GetHits(), 10); for (int HitN=0; HitN<Hits; HitN++){ TStr SecIdStr; TStr TitleStr; TStr SecStr; TStr CtxStr; BixRes->GetHitInfo( Book, HitN, -1, 100, SecIdStr, TitleStr, SecStr, CtxStr); KwToSecIdVH[KwToSecIdVP].Add(SecIdStr); Lx.PutUQStr(SecIdStr); } Lx.PutLn(); } else { Lx.PutUQStr(QueryStr); Lx.PutUQStr("Error"); Lx.PutStr(BixRes->GetMsgStr()); printf("%s - Error - %s\n", QueryStr.CStr(), BixRes->GetMsgStr().CStr()); Lx.PutLn(); } } }
void TWebTxtBsTrmSrv::OnLn(const int& CltSockId, const TStr& Ln){ TChA InNotifyChA; InNotifyChA+=TStr("[")+TInt::GetStr(CltSockId)+"] "; //InNotifyChA+=TStr("[")+GetCltPeerNm(CltSockId)+"] "; InNotifyChA+=TStr("[")+TSecTm::GetCurTm().GetStr()+"] "; InNotifyChA+=Ln; TNotify::OnNotify(WebTxtBs->GetNotify(), ntInfo, InNotifyChA); PSIn SIn=TMIn::New(Ln); TILx Lx(SIn, TFSet()|iloExcept); TChA MsgChA; bool SendMsgToClt=true; Lx.GetSym(); if (Lx.Sym==syIdStr){ try { ParseAndExeCmLn(CltSockId, Lx, SendMsgToClt, MsgChA); } catch (PExcept Except){ MsgChA=TStr("Error: ")+Except->GetMsgStr()+"\r\n"; } } else { if (Lx.Sym!=syEof){ MsgChA="Error: No command keyword.\r\n";} } if (SendMsgToClt){ SendTxtToClt(CltSockId, MsgChA); SendTxtToClt(CltSockId, ">"); } }
void TWebTxtBsSrv::PrepTplSet(const TStr& FNm, const TStr& DfFNm){ // get template input-stream (priority order: FNm, DfFNm, DfTplSetStr) PSIn SIn; bool FExists=false; SIn=TFIn::New(FNm, FExists); if (!FExists){SIn=TFIn::New(DfFNm, FExists);} if (!FExists){SIn=TStrIn::New(GetDfTplSetStr());} TILx Lx(SIn, TFSet()|iloRetEoln|iloSigNum|iloUniStr); Lx.GetStrToEolnAndCh('.'); do { TStr SecNm=Lx.GetStr(); if (SecNm=="End"){Lx.GetStrToEolnAndCh('.');} else if (SecNm=="Stop"){break;} else if (SecNm=="Template"){ Lx.GetStr("ContentType"); Lx.GetSym(syEq); TStr ContTypeStr=Lx.GetStr(); Lx.GetStr("Category"); Lx.GetSym(syEq); TStr CatStr=Lx.GetStr(); Lx.GetEoln(); TStr Tpl=Lx.GetStrToEolnAndCh('.'); Tpl.ChangeStrAll(HostNmMacro, HostNm); Tpl.ChangeStrAll(PortMacro, PortNStr); AddTpl(ContTypeStr, CatStr, Tpl); } else if (SecNm=="Variable"){ Lx.GetStr("ContentType"); Lx.GetSym(syEq); TStr ContTypeStr=Lx.GetStr(); TStr VarNm=Lx.GetStr(); Lx.GetSym(syEq); TStr VarVal=Lx.GetStr(); Lx.GetEoln(); AddVar(ContTypeStr, VarNm, VarVal); Lx.GetStrToEolnAndCh('.'); } else if (SecNm=="Remark"){ Lx.GetStrToEolnAndCh('.'); } else { Fail; } } while (!Lx.IsEof()); }
///////////////////////////////////////////////// // Wix-Expression PWixExpItem TWixExp::ParseFact(TWixExpLx& Lx, const TFSet& Expect){ if (Lx.Sym==wesyNot){ Lx.GetSym(FactExpect); PWixExpItem ExpItem=ParseFact(Lx, Expect); return PWixExpItem(new TWixExpItem(weitNot, ExpItem)); } else if (Lx.Sym==wesyIncl){ Lx.GetSym(FactExpect); PWixExpItem ExpItem=ParseFact(Lx, Expect); return PWixExpItem(new TWixExpItem(weitIncl, ExpItem)); } else if (Lx.Sym==wesyExcl){ Lx.GetSym(FactExpect); PWixExpItem ExpItem=ParseFact(Lx, Expect); return PWixExpItem(new TWixExpItem(weitExcl, ExpItem)); } else if (Lx.Sym==wesyLParen){ Lx.GetSym(ExpExpect); PWixExpItem ExpItem=ParseExp(Lx, TFSet()|wesyRParen); Lx.GetSym(Expect); return ExpItem; } else if (Lx.Sym==wesyDQuote){ TStrV WordStrV; Lx.GetSym(TFSet()|wesyWord|wesyDQuote); while (Lx.Sym==wesyWord){ WordStrV.Add(Lx.Str); Lx.GetSym(TFSet()|wesyWord|wesyDQuote); } Lx.GetSym(Expect); return PWixExpItem(new TWixExpItem(WordStrV)); } else if (Lx.Sym==wesyWord){ PWixExpItem ExpItem=PWixExpItem(new TWixExpItem(Lx.Str)); Lx.GetSym(TFSet(Expect)|wesyWCard); if (Lx.Sym==wesyWCard){ PWixExpItem WCardExpItem= PWixExpItem(new TWixExpItem(weitWCard, ExpItem)); ExpItem=WCardExpItem; Lx.GetSym(Expect); } return ExpItem; } else { Fail; return NULL; } }
TWixExp::TWixExp(const TStr& _ExpStr): ExpStr(_ExpStr), Ok(true), ErrMsg(), ExpItem(), FactExpect(), TermExpect(), ExpExpect(){ // prepare expect sets FactExpect=TFSet()|wesyNot|wesyIncl|wesyExcl|wesyLParen|wesyDQuote|wesyWord; TermExpect=FactExpect; ExpExpect=TermExpect; // parse the expression string TWixExpLx Lx(ExpStr); try { Lx.GetSym(ExpExpect); ExpItem=ParseExp(Lx, TFSet()|wesyEof); } catch (EWixExp E){ Ok=false; ErrMsg=E.GetErrMsg(); } }
PTb TTb::LoadTxtCsv(const TStr& FNm, const PTb& Tb){ // open file PSIn SIn=TFIn::New(FNm); TILx Lx(SIn, TFSet()|iloRetEoln|iloSigNum|iloUniStr); // read variable names Lx.GetStr(); bool IsTupNm=(Lx.UcStr=="NAME")||(Lx.UcStr=="ID"); if (IsTupNm){Lx.GetSym(syComma); Lx.GetStr();} do { PTbVarType VarType=PTbVarType(new TTbVarType()); PTbVar Var=PTbVar(new TGTbVar(Lx.Str, VarType)); Tb->AddVar(Var); if (Lx.GetSym(syComma, syEoln, syEof)==syComma){ Lx.GetSym(syStr);} } while (Lx.Sym==syStr); // read tuples TFSet ValSymSet=TFSet()|syQuestion|syAsterisk|sySlash|syFlt|syStr; if (Lx.Sym!=syEof){ Lx.GetSym(TFSet(ValSymSet)|syEof);} while (Lx.Sym!=syEof){ int TupN; if (IsTupNm){ TupN=Tb->AddTup(Lx.GetSymStr()); Lx.GetSym(syComma); Lx.GetSym(ValSymSet);} else {TupN=Tb->AddTup();} for (int VarN=0; VarN<Tb->GetVars(); VarN++){ if (VarN>0){Lx.GetSym(syComma); Lx.GetSym(ValSymSet);} switch (Lx.Sym){ case syQuestion: Tb->PutVal(TupN, VarN, TTbVal(tvtUnknw)); break; case syAsterisk: Tb->PutVal(TupN, VarN, TTbVal(tvtUnimp)); break; case sySlash: Tb->PutVal(TupN, VarN, TTbVal(tvtUnapp)); break; case syStr: Tb->PutDsc(TupN, VarN, Lx.Str); break; case syFlt: Tb->PutFlt(TupN, VarN, Lx.Flt); break; default: Fail; } } Lx.GetSym(syEoln, syEof); while (Lx.Sym==syEoln){Lx.GetSym(TFSet(ValSymSet)|syEoln|syEof);} } Tb->DefVarTypes(); return Tb; }
void TGStatVec::PlotAllVsX(const TGStatVal& XVal, const TStr& OutFNm, TStr Desc, const TGpScaleTy& Scale, const bool& PowerFit) const { const TFSet SkipStat = TFSet() | gsvFullDiamDev | gsvEffDiamDev | gsvEffWccDiamDev | gsvFullWccDiamDev; for (int stat = gsvNone; stat < gsvMx; stat++) { const TGStatVal Stat = TGStatVal(stat); if (SkipStat.In(Stat)) { continue; } if (Last()->HasVal(Stat) && Last()->HasVal(XVal) && Stat!=XVal) { Plot(XVal, Stat, OutFNm, Desc, Scale, PowerFit); } } }
TTqlExp::TTqlExp(const TStr& _ExpStr): ExpStr(_ExpStr), Ok(true), ErrMsg(), Item(), RelOpSet(), FactExpect(), TermExpect(), ExpExpect(){ // symbol sets RelOpSet=TFSet(tsyLss, tsyLEq, tsyEq, tsyNEq, tsyGEq, tsyGtr); FactExpect=TFSet(tsyNot, tsyIncl, tsyExcl, tsyTitle, tsyLParen, tsyLBracket, tsyDQuote, tsyWord); TermExpect=FactExpect; ExpExpect=TermExpect; TTqlLx Lx(ExpStr); try { Lx.GetSym(ExpExpect); Item=ParseExp(Lx, TFSet()|tsyEof); } catch (ETql E){ Ok=false; ErrMsg=E.GetErrMsg(); } }
PExp TExp::LoadTxtRelExp(TILx& Lx, const TFSet& Expect){ 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; }
PWixExpItem TWixExp::ParseTerm(TWixExpLx& Lx, const TFSet& Expect){ TFSet LoopExpect=TFSet(Expect)|FactExpect|wesyAnd; PWixExpItem ExpItem=ParseFact(Lx, LoopExpect); while ((Lx.Sym==wesyAnd)||(FactExpect.In(Lx.Sym))){ if (Lx.Sym==wesyAnd){ Lx.GetSym(FactExpect);} PWixExpItem RExpItem=ParseFact(Lx, LoopExpect); ExpItem=PWixExpItem(new TWixExpItem(weitAnd, ExpItem, RExpItem)); } return ExpItem; }
TPlVal TPlBs::ParseTup(TILx& Lx, const TFSet& Expect, const PPlBs& PlBs){ IAssert(TupExpect.In(Lx.Sym)); int FuncId=PlBs->AtomH.AddKey(Lx.Str); TPlValV ValV; Lx.GetSym(syLParen); Lx.GetSym(ExpExpect); TPlVal Val=ParseExp(Lx, TFSet()|syComma|syRParen, PlBs); ValV.Add(Val); while (Lx.Sym==syComma){ Lx.GetSym(ExpExpect); Val=ParseExp(Lx, TFSet()|syComma|syRParen, PlBs); ValV.Add(Val); } Lx.GetSym(Expect); // create and store tuple PPlTup Tup=TPlTup::New(FuncId, ValV); int TupId=PlBs->AddTup(Tup); TPlVal TupVal; TupVal.PutTupId(TupId); return TupVal; }
PTqlItem TTqlExp::ParseTerm(TTqlLx& Lx, const TFSet& Expect){ TFSet LoopExpect=TFSet(Expect)|FactExpect|tsyAnd; PTqlItem Item=ParseFact(Lx, LoopExpect); while ((Lx.Sym==tsyAnd)||(FactExpect.In(Lx.Sym))){ if (Lx.Sym==tsyAnd){ Lx.GetSym(FactExpect);} PTqlItem RItem=ParseFact(Lx, LoopExpect); Item=PTqlItem(new TTqlItem(titAnd, Item, RItem)); } return Item; }
void TTb::SaveAssis(const TStr& FNm){ TStr DoFNm=FNm.GetFPath()+"AsDo"+FNm.GetFMid().GetSubStr(0, 3)+".Dat"; TStr DaFNm=FNm.GetFPath()+"AsDa"+FNm.GetFMid().GetSubStr(0, 3)+".Dat"; TOLx DoLx(PSOut(new TFOut(DoFNm)), TFSet()|oloFrcEoln|oloSigNum|oloUniStr); int Dscs=GetVar(0)->GetVarType()->GetDscs(); Assert(Dscs>0); DoLx.PutInt(Dscs); DoLx.PutDosLn(); for (int DscN=0; DscN<Dscs; DscN++){ TTbVal Val=GetVar(0)->GetVarType()->GetVal(DscN); DoLx.PutStr(GetVar(0)->GetVarType()->GetValStr(Val)); DoLx.PutDosLn(); } DoLx.PutInt(TInt(GetVars()-1)); DoLx.PutDosLn(); for (int VarN=1; VarN<GetVars(); VarN++){ DoLx.PutStr(GetVar(VarN)->GetNm()); DoLx.PutDosLn(); int Dscs=GetVar(VarN)->GetVarType()->GetDscs(); if (Dscs>0){ DoLx.PutInt(Dscs); DoLx.PutDosLn(); for (int DscN=0; DscN<Dscs; DscN++){ TTbVal Val=GetVar(VarN)->GetVarType()->GetVal(DscN); DoLx.PutStr(GetVar(VarN)->GetVarType()->GetValStr(DscN)); DoLx.PutDosLn();} } else { DoLx.PutInt(TInt(0)); DoLx.PutInt(TInt(100)); DoLx.PutDosLn(); } } TOLx DaLx(PSOut(new TFOut(DaFNm)), TFSet()|oloFrcEoln|oloSigNum|oloUniStr); for (int TupN=0; TupN<GetTups(); TupN++){ for (int VarN=0; VarN<GetVars(); VarN++){ TTbVal Val=GetVal(TupN, VarN); switch (Val.GetValTag()){ case tvtUnknw: DaLx.PutSym(syQuestion); break; case tvtUnimp: DaLx.PutSym(syAsterisk); break; case tvtUnapp: DaLx.PutSym(syAsterisk); break; case tvtDsc: DaLx.PutInt(TInt(1+Val.GetDsc())); break; case tvtFlt: DaLx.PutFlt(Val.GetFlt()); break; default: Fail; } } DaLx.PutDosLn(); } }
PExp TExp::LoadTxtFact(TILx& Lx, const TFSet& Expect){ 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; }
///////////////////////////////////////////////// // Dzs-Keyword-Base TDzsKwBs::TDzsKwBs(const TStr& FNm): KwToSecIdVH(10000){ PSIn SIn=TFIn::New(FNm); TILx Lx(SIn, TFSet()|iloTabSep); Lx.GetSym(syStr, syEoln, syEof); while (Lx.Sym!=syEof){ if (Lx.Sym==syStr){ KwToSecIdVH.AddDat(Lx.Str); while (Lx.GetSym()!=syEoln){} } Lx.GetSym(syStr, syEoln, syEof); } }
PExp TExp::LoadTxt( const PSIn& SIn, bool& Ok, TStr& MsgStr, const TFSet& Expect){ 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; }
PPlBs TPlBs::LoadTxtPl(const TStr& FNmWc){ PPlBs PlBs=TPlBs::New(); printf("Loading Prolog from '%s'...\n", FNmWc.CStr()); TFFile FFile(FNmWc); TStr FNm; while (FFile.Next(FNm)){ printf(" ...loading '%s'\n", FNm.CStr()); // process prolog-file PSIn SIn=TFIn::New(FNm); TILx Lx(SIn, TFSet()|/*iloList|*/iloCmtAlw|iloCsSens|iloUniStr|iloExcept); Lx.GetSym(TFSet(TupExpect)|syEof); while (Lx.Sym!=syEof){ TPlVal TupVal=TPlBs::ParseTup(Lx, TFSet()|syPeriod, PlBs); int FuncId=PlBs->TupV[TupVal.GetTupId()]->GetFuncId(); int Arity=PlBs->TupV[TupVal.GetTupId()]->GetVals(); PlBs->FuncIdArityPrToTupIdVH. AddDat(TIntPr(FuncId, Arity)).Add(TupVal.GetTupId()); Lx.GetSym(TFSet(TupExpect)|syEof); } //break; } printf("Done.\n"); return PlBs; }
void TVizMapContext::PaintMgGlass(PGks Gks, const int& KeyWdFontSize) { // drawing the dark circle TFltRect ZoomRect = GetZoomRect(); int SizeX = TFlt::Round((MgGlassSize/ZoomRect.GetXLen()) * Gks->GetWidth()); int SizeY = TFlt::Round((MgGlassSize/ZoomRect.GetYLen()) * Gks->GetHeight()); Gks->SetBrush(TGksBrush::New(ColorMgGlass)); Gks->FillEllipse(ScreenX-SizeX, ScreenY-SizeY, ScreenX+SizeX, ScreenY+SizeY); // drawing the keywords if (MgGlassKeyWdV.Len() > 0) { // prepare the string Gks->SetFont(TGksFont::New("ARIAL", KeyWdFontSize, TGksColor::GetBlack(), TFSet()|gfsBold)); TStr KeyWdStr = Gks->BreakTxt(MgGlassKeyWdV, ", ", ",", MgGlassWindowWidth); TStr NearPointStr; if (NearPointN != -1) { PVizMapPoint NearPoint = VizMapFrame->GetPoint(NearPointN); if (NearPoint->IsPointNm()) { TStr NearPointNm = NearPoint->GetPointNm(); if (NearPointNm.IsStrIn("[[")) { const int StartPos = NearPointNm.SearchStr("[["); NearPointNm = NearPointNm.Left(StartPos - 1); } NearPointStr = Gks->BreakTxt(NearPointNm, " ", "", MgGlassWindowWidth, 1); NearPointStr.DelChAll('\n'); NearPointStr += "\n"; } } TStr DocCountStr = "#documents = " + MgGlassPoints.GetStr() + "\n"; // compose the final message KeyWdStr = NearPointStr + DocCountStr + KeyWdStr; // find position of the window int WndWidth = Gks->GetTxtWidth(KeyWdStr) + 6; int WndHeight = Gks->GetTxtHeight(KeyWdStr) + 6; int PosX = ScreenX + 20, PosY = ScreenY + 20; if (PosX + WndWidth > Gks->GetWidth()) { PosX = ScreenX - 20 - WndWidth; } if (PosY + WndHeight > Gks->GetHeight()) { PosY = ScreenY - 20 - WndHeight; } // draw the keyword string Gks->SetBrush(TGksBrush::New(ColorMgGlassWndShadow)); Gks->FillRect(PosX + 5, PosY + 5, PosX + WndWidth + 5, PosY + WndHeight + 5); Gks->SetBrush(TGksBrush::New(ColorMgGlassWnd)); Gks->SetPen(TGksPen::New(ColorMgGlassWndFrm)); Gks->Rectangle(PosX, PosY, PosX + WndWidth, PosY + WndHeight); Gks->PutTxt(KeyWdStr, PosX+3, PosY+3); } }
void TYInvIx::SaveTxt(const PSOut& SOut, const PYBs& YBs){ TOLx Lx(SOut, TFSet()|oloFrcEoln|oloSigNum); int WordIdToFirstDocIdNP=WordIdToFirstDocIdNH.FFirstKeyId(); while (WordIdToFirstDocIdNH.FNextKeyId(WordIdToFirstDocIdNP)){ int WordId=WordIdToFirstDocIdNH.GetKey(WordIdToFirstDocIdNP); TStr WordStr; if (YBs.Empty()){WordStr=TInt::GetStr(WordId);} else {WordStr=YBs->GetWordStr(WordId);} Lx.PutStr(WordStr); Lx.PutSym(syColon); Lx.PutSym(syLBracket); int DocIdN=FFirstDocId(WordId); int DocId; while (FNextWordId(DocIdN, DocId)){ Lx.PutInt(DocId);} Lx.PutSym(syRBracket); Lx.PutLn(); } }
PTb TTb::LoadTxtTab(const TStr& FNm, const PTb& Tb){ // open file PSIn SIn=TFIn::New(FNm); TILx Lx(SIn, TFSet()|iloTabSep); // read variable names Lx.GetStr(); bool IsTupNm=(Lx.UcStr=="NAME")||(Lx.UcStr=="ID"); if (IsTupNm){Lx.GetSym(syTab); Lx.GetStr();} do { PTbVarType VarType=PTbVarType(new TTbVarType()); PTbVar Var=PTbVar(new TGTbVar(Lx.Str, VarType)); Tb->AddVar(Var); if (Lx.GetSym(syTab, syEoln, syEof)==syTab){ Lx.GetSym(syStr);} } while (Lx.Sym==syStr); // read tuples if (Lx.Sym!=syEof){ Lx.GetSym(syStr, syEof);} while (Lx.Sym!=syEof){ int TupN; if (IsTupNm){ TupN=Tb->AddTup(Lx.GetSymStr()); Lx.GetSym(syTab); Lx.GetStr();} else {TupN=Tb->AddTup();} for (int VarN=0; VarN<Tb->GetVars(); VarN++){ if (VarN>0){Lx.GetSym(syTab); Lx.GetStr();} if (Lx.Str=='?'){Tb->PutVal(TupN, VarN, TTbVal(tvtUnknw));} else if (Lx.Str=='*'){Tb->PutVal(TupN, VarN, TTbVal(tvtUnimp));} else if (Lx.Str=='/'){Tb->PutVal(TupN, VarN, TTbVal(tvtUnapp));} else { double Flt; if (TStr(Lx.Str).IsFlt(Flt)){ Tb->PutFlt(TupN, VarN, Flt); } else { Tb->PutDsc(TupN, VarN, Lx.Str); } } } //printf("Tups: %d\r", Tb->GetTups()); Lx.GetSym(syEoln, syEof); while (Lx.Sym==syEoln){Lx.GetSym(syStr, syEoln, syEof);} } Tb->DefVarTypes(); return Tb; }