コード例 #1
0
ファイル: wixexp.cpp プロジェクト: mkarlovc/gcentralization
TWixExpLxSym TWixExpLx::GetSym(const TFSet& Expect){
  Str.Clr();
  while (ChDef.IsSpace(Ch)){GetCh();}
  if (Expect.In(wesyNum)){
    if (!ChDef.IsNum(Ch)){throw EWixExp("Number expected.");}
    Sym=wesyNum;
    do {Str.AddCh(Ch); GetCh();} while (ChDef.IsNum(Ch));
  } else {
    switch (ChDef.GetChTy(Ch)){
      case welctAlpha:
      case welctNum:
        do {Str.AddCh(Ch); GetCh();} while (ChDef.IsAlNum(Ch));
        if (Str=="OR"){Sym=wesyOr;}
        else if (Str=="AND"){Sym=wesyAnd;}
        else if (Str=="NOT"){Sym=wesyNot;}
        else {Sym=wesyWord;}
        break;
      case welctSym:
        Str.AddCh(Ch);
        switch (Ch){
          case ':': Sym=wesyColon; break;
          case '(': Sym=wesyLParen; break;
          case ')': Sym=wesyRParen; break;
          case '|': Sym=wesyOr; break;
          case '&': Sym=wesyAnd; break;
          case '!': Sym=wesyNot; break;
          case '+': Sym=wesyIncl; break;
          case '-': Sym=wesyExcl; break;
          case '*': Sym=wesyWCard; break;
          default: Sym=wesySSym;
        }
        GetCh();
        break;
      case welctEof: Sym=wesyEof; break;
      default: Sym=wesyUndef; GetCh();
    }
  }

  if ((!Expect.In(Sym))&&(!Expect.Empty())){
    if (Sym==wesyEof){
      throw EWixExp("Unexpected end of expression.");
    } else {
      throw EWixExp("Unexpected symbol.");
    }
  }
  return Sym;
}
コード例 #2
0
ファイル: ssqldm.cpp プロジェクト: Accio/snap
TSqlDmLxSym TSqlDmLx::GetSym(const TFSet& Expect){
  if (!PrevSymStStack.Empty()){
    // symbols already on the stack
    PrevSymStStack.Top().Restore(*this); PrevSymStStack.Pop();
  } else {
    // usual symbol
    while (ChDef.IsSpace(Ch)){GetCh();}
    SymLnN=LnN; SymLnChN=LnChN; SymChN=ChN;

    if (ChDef.IsAlpha(Ch)){ // name
      Str.Clr(); UcStr.Clr();
      do {Str.AddCh(Ch); UcStr.AddCh(ChDef.GetUc(Ch));}
      while (ChDef.IsAlNum(GetCh()));
      Sym=TSqlDmLxSymStr::GetRwSym(UcStr);
      if (Sym==dsyUndef){Sym=dsyName;}
    } else
    if (Ch=='['){ // bracketed name
      Str.Clr(); UcStr.Clr(); GetCh();
      while ((Ch!=']')&&(Ch!=TCh::EofCh)){
        Str.AddCh(Ch); UcStr.AddCh(ChDef.GetUc(Ch)); GetCh();}
      if (Ch==TCh::EofCh){Sym=dsyUndef;}
      else {Sym=dsyName; GetCh();}
    } else
    if (Ch=='\''){ // string in single quotes
      Str.Clr(); UcStr.Clr(); GetCh();
      while ((Ch!='\'')&&(Ch!=TCh::EofCh)){
        Str.AddCh(Ch); UcStr.AddCh(ChDef.GetUc(Ch)); GetCh();}
      if (Ch==TCh::EofCh){Sym=dsyUndef;}
      else {Sym=dsyStr; GetCh();}
    } else
    if (ChDef.IsNum(Ch)){ // integer or float
      Str.Clr();
      do {Str.AddCh(Ch);} while (ChDef.IsNum(GetCh()));
      if (Ch=='.'){
        Str.AddCh(Ch);
        while (ChDef.IsNum(GetCh())){Str.AddCh(Ch);}
      }
      if ((Ch=='e')||(Ch=='E')){
        Str.AddCh(Ch); GetCh();
        if ((Ch=='+')||(Ch=='-')){Str.AddCh(Ch); GetCh();}
        while (ChDef.IsNum(Ch)){Str.AddCh(Ch); GetCh();}
      }
      UcStr=Str;
      if (Expect.In(syFlt)){Sym=dsyFlt; Flt=atof(Str.CStr());}
      else {Sym=dsyInt; Int=atoi(Str.CStr());}
    } else
    if (Ch=='/'){ // slash or // commenatry or /* */ commentary
      GetCh();
      if (Ch=='/'){
        do {GetCh();} while (!ChDef.IsEof(Ch));
        if (Ch==TCh::CrCh){
          if (GetCh()==TCh::LfCh){GetCh();}
        } else
        if (Ch==TCh::LfCh){
          if (GetCh()==TCh::CrCh){GetCh();}
        }
        GetSym(Expect);
      } else
      if (Ch=='*'){
        do {while (GetCh()!='*'){}} while (GetCh()!='/');
        GetCh(); GetSym(Expect);
      } else {
        Sym=dsySlash;
      }
    } else
    if (Ch=='-'){ // minus or -- commenatry
      GetCh();
      if (Ch=='-'){
        do {GetCh();} while (!ChDef.IsEof(Ch));
        if (Ch==TCh::CrCh){
          if (GetCh()==TCh::LfCh){GetCh();}
        } else
        if (Ch==TCh::LfCh){
          if (GetCh()==TCh::CrCh){GetCh();}
        }
        GetSym(Expect);
      } else {
        Sym=dsyMinus;
      }
    } else
    if (Ch==TCh::EofCh){ // end-of-file
      Sym=dsyEof;
    } else { // other symbols
      switch (Ch){
        case ',': Sym=dsyComma; GetCh(); break;
        case '.':
          if (ChDef.IsNum(GetCh())){
            PutCh('.'); PutCh('0'); return GetSym(Expect);}
          else {Sym=dsyPeriod;}
          break;
        case ';': Sym=dsySemicolon; GetCh(); break;
        case '<':
          GetCh();
          if (Ch=='='){Sym=dsyLEq; GetCh();}
          else if (Ch=='>'){Sym=dsyNEq; GetCh();}
          else {Sym=dsyLss;} break;
        case '=': Sym=dsyEq; GetCh(); break;
        case '>':
          if (GetCh()=='='){Sym=dsyGEq; GetCh();}
          else {Sym=dsyGtr;} break;
        case '+': Sym=dsyPlus; GetCh(); break;
        case '-': Sym=dsyMinus; GetCh(); break;
        case '*': Sym=dsyAsterisk; GetCh(); break;
        case '/': Sym=dsySlash; GetCh(); break;
        case '(': Sym=dsyLParen; GetCh(); break;
        case ')': Sym=dsyRParen; GetCh(); break;
        case '{': Sym=dsyLBrace; GetCh(); break;
        case '}': Sym=dsyRBrace; GetCh(); break;
        default: Sym=dsyUndef; GetCh(); break;
      }
    }
  }

  if ((!Expect.In(Sym))&&(!Expect.Empty())){
   TStr MsgStr=
    TStr("Unexpected symbol (")+Str+") ["+GetFPosStr()+"]";
   throw TExcept::Throw(MsgStr);
  }
  return Sym;
}
コード例 #3
0
ファイル: tql.cpp プロジェクト: Accio/snap
TTqlLxSym TTqlLx::GetSym(const TFSet& Expect){
  Str.Clr();
  while (ChDef.IsSpace(Ch)){GetCh();}
  if (Expect.In(tsyNum)){
    if (!ChDef.IsNum(Ch)){throw ETql("Number expected.");}
    Sym=tsyNum;
    do {Str.AddCh(Ch); GetCh();} while (ChDef.IsNum(Ch));
  } else {
    switch (ChDef.GetChTy(Ch)){
      case tlcAlpha:
      case tlcNum:
        do {Str.AddCh(Ch); GetCh();} while (ChDef.IsAlNum(Ch));
        if (Str=="OR"){Sym=tsyOr;}
        else if (Str=="AND"){Sym=tsyAnd;}
        else if (Str=="NOT"){Sym=tsyNot;}
        else {Sym=tsyWord;}
        break;
      case tlcSym:
        Str.AddCh(Ch);
        switch (Ch){
          case '\"': Sym=tsyDQuote; GetCh(); break;
          case ':': Sym=tsyColon; GetCh(); break;
          case '(': Sym=tsyLParen; GetCh(); break;
          case ')': Sym=tsyRParen; GetCh(); break;
          case '[': Sym=tsyLBracket; GetCh(); break;
          case ']': Sym=tsyRBracket; GetCh(); break;
          case '|': Sym=tsyOr; GetCh(); break;
          case '&': Sym=tsyAnd; GetCh(); break;
          case '!': Sym=tsyNot; GetCh(); break;
          case '+': Sym=tsyIncl; GetCh(); break;
          case '-': Sym=tsyExcl; GetCh(); break;
          case '#': Sym=tsyTitle; GetCh(); break;
          case '*': Sym=tsyWCard; GetCh(); break;
          case '<':
            GetCh();
            if (Ch=='='){Sym=tsyLEq; GetCh();}
            else if (Ch=='>'){Sym=tsyNEq; GetCh();}
            else {Sym=tsyLss;}
            break;
          case '=': Sym=tsyEq; GetCh(); break;
          case '>':
            GetCh();
            if (Ch=='='){Sym=tsyGEq; GetCh();}
            else {Sym=tsyGtr;}
            break;
          default: Sym=tsySSym; GetCh();
        }
        break;
      case tlcEof: Sym=tsyEof; break;
      default: Sym=tsyUndef; GetCh();
    }
  }

  if ((!Expect.In(Sym))&&(!Expect.Empty())){
    if (Sym==tsyEof){
      throw ETql("Unexpected end of expression.");
    } else {
      throw ETql("Unexpected symbol.");
    }
  }
  return Sym;
}