当前位置: 首页>>代码示例>>C++>>正文


C++ Symbols::insert方法代码示例

本文整理汇总了C++中Symbols::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ Symbols::insert方法的具体用法?C++ Symbols::insert怎么用?C++ Symbols::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symbols的用法示例。


在下文中一共展示了Symbols::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Analyze

void GrammerAnalyzer::Analyze()
{
   _TerminalSymbols.clear();
   _NonTerminalSymbols.clear();
   _Productions.clear();
   Symbols lhsSymbols;
   Symbols rhsSymbols;
   ifstream inFile(_Filename.c_str());
   while (inFile.good() && !inFile.eof())
   {
      string line;
      getline(inFile, line);
      if (line.empty()) continue;
      const string lhs = line.substr(0,line.find_first_of('>')+1);
      vector<string> rhs;
      while (!line.empty())
      {
         string word;
         if (line.at(0) == ' ') 
         {
            line = line.substr(1); 
            continue; 
         }
         if (line.at(0) == '<')
         {
            size_t p2 = line.find_first_of('>') + 1;
            word = line.substr(0,p2);
         }
         else
         {
            const bool alphabetsOnly(isalpha(line.at(0)));
            for (string::const_iterator itr = line.begin(); itr != line.end(); ++itr)
            {
               if (*itr == ' ') break;
               if (alphabetsOnly)
               {
                  if (isalpha(*itr))
                     word += *itr;
                  else
                     break;
               }
               else
               {
                  if (*itr == '<')
                     break;
                  word += *itr;
               }
            }
         }
         cout << "Processing Word : " << word << endl;
         rhs.push_back(word);
         if (word.at(0) == '<')
            _NonTerminalSymbols.insert(word);
         else if (word.at(0) == '#')
         {
            cout << "\t Ignoring : " << word << endl;
//            rhs.pop_back();
         }
         else
            _TerminalSymbols.insert(word);
         line = line.substr(word.size());
      }
      rhs.erase(rhs.begin());
      _Productions.push_back(make_pair(lhs,rhs));
      lhsSymbols.insert(lhs);
      rhsSymbols.insert(rhs.begin(), rhs.end());
   }

   cout << "************************" << endl;
   cout << "Productions : " << endl;
   for (Productions::const_iterator itr = _Productions.begin(); itr != _Productions.end(); ++itr)
   {
      cout << (*itr).first << " \t-->\t " ;
      for (vector<string>::const_iterator itr2 = (*itr).second.begin(); itr2 != (*itr).second.end(); ++itr2)
         cout << ' ' << *itr2;
      cout << endl;
   }
   cout << "************************" << endl;
   cout << "Terminal Symbols : " << endl;
   for (Symbols::const_iterator itr = _TerminalSymbols.begin(); itr != _TerminalSymbols.end(); ++itr)
      cout << (*itr) << endl;
   cout << "************************" << endl;
   cout << "Non Terminal Symbols : " << endl;
   for (Symbols::const_iterator itr = _NonTerminalSymbols.begin(); itr != _NonTerminalSymbols.end(); ++itr)
      cout << (*itr) << endl;

   cout << "************************" << endl;
   cout << "Non Terminal Symbols On LHS of Productions : " << endl;
   for (Symbols::const_iterator itr = lhsSymbols.begin(); itr != lhsSymbols.end(); ++itr)
      cout << (*itr) << endl;

   cout << "************************" << endl;
   cout << "Symbols on RHS of productions : " << endl;
   for (Symbols::const_iterator itr = rhsSymbols.begin(); itr != rhsSymbols.end(); ++itr)
      if (itr->at(0) != '#') cout << (*itr) << endl;
}
开发者ID:jmundack,项目名称:universal_compiler,代码行数:96,代码来源:GrammerAnalyzer.cpp


注:本文中的Symbols::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。