Esempio n. 1
0
File: exp.cpp Progetto: Accio/snap
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;
}
Esempio n. 2
0
File: tql.cpp Progetto: Accio/snap
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;
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
File: exp.cpp Progetto: Accio/snap
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;
}
Esempio n. 5
0
File: exp.cpp Progetto: Accio/snap
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;
}
Esempio n. 6
0
/////////////////////////////////////////////////
// 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;
}
Esempio n. 7
0
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);
}
Esempio n. 8
0
File: exp.cpp Progetto: Accio/snap
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;
    }
  }
}
Esempio n. 10
0
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();
  }
}
Esempio n. 11
0
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();
    }
  }
}
Esempio n. 12
0
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, ">");
  }
}
Esempio n. 13
0
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());
}
Esempio n. 14
0
/////////////////////////////////////////////////
// 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;
  }
}
Esempio n. 15
0
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();
  }
}
Esempio n. 16
0
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;
}
Esempio n. 17
0
File: gstat.cpp Progetto: Accio/snap
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);
    }
  }
}
Esempio n. 18
0
File: tql.cpp Progetto: Accio/snap
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();
  }
}
Esempio n. 19
0
File: exp.cpp Progetto: Accio/snap
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;
}
Esempio n. 20
0
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;
}
Esempio n. 21
0
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;
}
Esempio n. 22
0
File: tql.cpp Progetto: Accio/snap
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;
}
Esempio n. 23
0
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();
  }
}
Esempio n. 24
0
File: exp.cpp Progetto: Accio/snap
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;
}
Esempio n. 25
0
/////////////////////////////////////////////////
// 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);
  }
}
Esempio n. 26
0
File: exp.cpp Progetto: Accio/snap
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;
}
Esempio n. 27
0
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;
}
Esempio n. 28
0
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);
    }
}
Esempio n. 29
0
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();
  }
}
Esempio n. 30
0
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;
}