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


C++ SymbolList::size方法代码示例

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


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

示例1: getNumberOfDistinctPositionsWithoutGap

size_t getNumberOfDistinctPositionsWithoutGap(const SymbolList& l1, const SymbolList& l2) {
      if (l1.getAlphabet()->getAlphabetType() != l2.getAlphabet()->getAlphabetType()) throw AlphabetMismatchException("SymbolListTools::getNumberOfDistinctPositions.", l1.getAlphabet(), l2.getAlphabet());
      const Alphabet* alpha = l1.getAlphabet();
      int gapCode = alpha->getGapCharacterCode();
      size_t n = min(l1.size(), l2.size());
      size_t count = 0;
      for (size_t i = 0; i < n; i++) {
          int x = l1[i];
          int y = l2[i];
          if (alpha->isUnresolved(x)) x = gapCode;
          if (alpha->isUnresolved(x)) y = gapCode;
          if (x != gapCode && y != gapCode && x != y) count++;
      }
      return count;
}
开发者ID:kgori,项目名称:bpp,代码行数:15,代码来源:Alignment.cpp

示例2: cyk

bool Grammar::cyk(const std::string& input) {
	unsigned int n = input.size();
	SymbolList in_sl;
	for( auto ch : input ) {
		in_sl.push_back(ch);
	}
	in_sl = to_pseudo_non_terminals(in_sl);

	std::vector<SymbolList> pairs;
	for( auto it = in_sl.begin(); it != in_sl.end() - 1; ++it ) {
		SymbolList temp_sl;
		temp_sl.push_back(*it);
		temp_sl.push_back(*( it + 1 ));
		pairs.push_back(temp_sl);
	}

	std::vector<SymbolList> sl_vect;
	for( auto t : pairs ) {
		SymbolList temp = find_as_list(t);
		if( temp.size() == 0 ) {
			Symbol temp_sym("empty");
			temp.push_back(temp_sym);
		}
		sl_vect.push_back(temp);
	}

	for( auto x : sl_vect ) {
		for( auto t : x ) {
			std::cout << t << '|';
		}
		std::cout << '\n';
	}

	return true;
}
开发者ID:Templar-von-Midgard,项目名称:Context-Free-Grammar-transformer,代码行数:35,代码来源:Grammar.cpp

示例3: checkAmbiguity

void SymbolTable::checkAmbiguity(const Symbol& s) {
//  f(a : inteiro)
//  f(b : inteiro, ... resto)
//  -> declaracao ambigua

    if (!s.type()->isSubprogram()) {
        return;
    }

    SymbolList list =
        _table[globalScope()].findAllByLexeme(s.lexeme());

    if (list.size() == 0) {
        return;
    }

    for (SymbolList::iterator it = list.begin(); it != list.end(); ++it) {
        if (!(*it).type()->isSubprogram()) {
            continue;
        }

        int size = (*it).type()->paramTypes().size();
        if ((size + 1) == s.type()->paramTypes().size()) {
            Type *sss = s.type()->paramTypes().back();
            bool bn = sss->isReticences();
            if (s.type()->paramTypes().back()->isReticences()) {
                throw AmbiguousDeclarationException(s, *it);
            }
        } else if ((size - 1) == s.type()->paramTypes().size()) {
            if ((*it).type()->paramTypes().back()->isReticences()) {
                throw AmbiguousDeclarationException(s, *it);
            }
        }
    }
}
开发者ID:BackupTheBerlios,项目名称:gpt-svn,代码行数:35,代码来源:SymbolTable.cpp

示例4: replace_first_of

void replace_first_of(SymbolList& sl, const Symbol& of, const Symbol& with) {
	//std::cout << "replace_first_with\n";
	for( unsigned int i = 0; i < sl.size(); ++i ) {
		if( sl[i] == of ) {
			sl[i] = with;
			return;
		}
	}
}
开发者ID:Templar-von-Midgard,项目名称:Context-Free-Grammar-transformer,代码行数:9,代码来源:Grammar.cpp

示例5: permutations

std::vector<SymbolList> permutations(const SymbolList& str, const SymbolList& of) {
	std::vector<SymbolList> ret;
	unsigned int size = of.size();
	unsigned int n = factorial(size);
	SymbolList temp = str;
	//std::cout << temp << '\n';
	while( !empty_intersection(temp, of) && temp.size() > 1 ) {
		SymbolList copy = temp;
		for( unsigned int i = 0; i < copy.size(); ++i ) {
			if( contains_char(of, copy[i]) ) {
				copy.erase(copy.begin() + i);
				ret.push_back(copy);
				//std::cout << copy << std::endl;
				break;
			}
		}
		temp = ret.back();
	}
	return ret;
}
开发者ID:Templar-von-Midgard,项目名称:Context-Free-Grammar-transformer,代码行数:20,代码来源:Grammar.cpp

示例6: reportResults

  virtual
  void reportResults (CReport & report)
  {
    trial( testSet, notCirc, symbolMap);

    if (testSet.size() == 0) return;

    report.addAtLine(1, "Circularities found");

    stringstream str;

    str << testSet << ends;

    report.addAtLine(2, str.str() );
  }
开发者ID:madGambol,项目名称:OMDT,代码行数:15,代码来源:circAnalysis.cpp

示例7: setSymbols

void Preprocessor::setSymbols(const SymbolList& symbols)
{
    uint nb_symbols = symbols.size();
    this->symbols.resize(nb_symbols);

#ifdef PREPROC_KEEP_ORIGINAL_SYMBOLS
    this->original_symbols.resize(nb_symbols);
#endif

    for(uint i=0 ; i < nb_symbols ; i++)
    {
        this->symbols[i] = symbols[i];
#ifdef PREPROC_KEEP_ORIGINAL_SYMBOLS
        this->original_symbols[i] = symbols[i];
#endif
    }
}
开发者ID:Funto,项目名称:Tohoku-Engine,代码行数:17,代码来源:Preprocessor.cpp

示例8: those_that_product

SymbolList Grammar::those_that_product(SymbolList& sl) {
	SymbolList ret;
	for( auto CV : sl ) {
		for( auto nT : non_terminals ) {
			for( auto rule : production_rules[get_nt_index(nT)] ) {
				if( sl.size() != rule.size() ) { continue; }
				for( unsigned int i = 0; i < rule.size(); ++i ) {
					if( !(sl[i] == rule[i]) ) { break; }
					if( i == rule.size() - 1 ) {
						ret.push_back(nT);
					}
				}
			}
		}
	}
	return ret;
}
开发者ID:Templar-von-Midgard,项目名称:Context-Free-Grammar-transformer,代码行数:17,代码来源:Grammar.cpp

示例9: UndeclaredSymbolException

const Symbol&
SymbolTable::getSymbol(const std::string& lexeme, const TypeList& params) {
    //deve considerar promocao de tipos
    //    função f(a:real) ...
    //    f(1);                //resolve para a função "f_real"

//checar:
//  f(a : inteiro)
//  f(b : real)
//  f(2); //primeira versão, sempre!


    SymbolList list = _table[globalScope()].findAllByLexeme(lexeme);

    if (list.size() == 0) {
        throw UndeclaredSymbolException(lexeme);
    }

    //try exact version
    for (SymbolList::iterator it = list.begin(); it != list.end(); ++it) {
        if ((*it).type()->isSubprogram() &&
                (*it).type()->paramTypes().equals(params)) {
            return (*it);
        }
    }

    //tentando promocoes...
    for (SymbolList::iterator it = list.begin(); it != list.end(); ++it) {
        if ((*it).type()->isSubprogram() &&
                (*it).type()->paramTypes().isLValueFor(params)) {
            return (*it);
        }
    }

    throw UnmatchedException(lexeme);

//   std::string id = Symbol::buildIdentifier(lexeme, params);
//   SymbolList::const_iterator it = _table[globalScope()].findByIdentifier(id);
//   if (it == _table[globalScope()].end()) {
//     throw UndeclaredSymbolException(id);
//   }
//   return (*it);
}
开发者ID:BackupTheBerlios,项目名称:gpt-svn,代码行数:43,代码来源:SymbolTable.cpp

示例10: nominal_test

void LexerTests::nominal_test()
{
    cout << "-------------------------------------- Lexer ------------------------------------" << endl;

    ifstream ifs("../../tests/files/correct.lt");
    //Vérification du fichier
    if (!ifs.good())
    {
        ifs.close();
        FAILED(0);
        PRINT("Failed to open file...");
        return;
    }
    Lexer lexer(ifs);
    SymbolList symbols;
    Symbol symbol;
    lexer.MoveForward(); // commence à lire en placant la tete de lecture au debut du flux
    symbol = lexer.GetNext();
    while(symbol.code != S_EOF)
    {   if(symbol.code == S_LEXER_ERROR)
        {   PRINT("Lexer error encountered...");
            break;
        }
        // on récupère les valeurs
        symbols.push_back(symbol);
        // on déplace la tête de lecture
        lexer.MoveForward();
        // on lit le prochain symbole
        symbol = lexer.GetNext();
    }
    symbols.push_back(symbol);
    /*
     * Programme testé : correct.lt
     *
     * 1. var a,b;
     * 2. const c = 4;
     * 3. const d = 6;
     * 4. var e;
     * 5. a := (c+d)*3-5;
     * 6. lire b;
     * 7. ecrire a*b;
     * 8. e := b+d;
     * 9. ecrire e;
     */
    SymbolList expectedSymbols;
#define PUSH_SYM(symbolcode, value) expectedSymbols.push_back(Symbol(symbolcode, value));
    // ligne 1
    PUSH_SYM(S_VAR,"var");PUSH_SYM(S_ID,"a");PUSH_SYM(S_V,",");PUSH_SYM(S_ID,"b");PUSH_SYM(S_PV,";");
    // ligne 2
    PUSH_SYM(S_CONST,"const");PUSH_SYM(S_ID,"c");PUSH_SYM(S_EQ,"=");PUSH_SYM(S_NUM,"4");PUSH_SYM(S_PV,";");
    // ligne 3
    PUSH_SYM(S_CONST,"const");PUSH_SYM(S_ID,"d");PUSH_SYM(S_EQ,"=");PUSH_SYM(S_NUM,"6");PUSH_SYM(S_PV,";");
    // ligne 4
    PUSH_SYM(S_VAR,"var");PUSH_SYM(S_ID,"e");PUSH_SYM(S_PV,";");
    // ligne 5
    PUSH_SYM(S_ID,"a");PUSH_SYM(S_AFFECT,":=");PUSH_SYM(S_PO,"(");PUSH_SYM(S_ID,"c");PUSH_SYM(S_PLUS,"+");PUSH_SYM(S_ID,"d");PUSH_SYM(S_PF,")");PUSH_SYM(S_MULT,"*");PUSH_SYM(S_NUM,"3");PUSH_SYM(S_MINUS,"-");PUSH_SYM(S_NUM,"5");PUSH_SYM(S_PV,";");
    // ligne 6
    PUSH_SYM(S_READ,"lire");PUSH_SYM(S_ID,"b");PUSH_SYM(S_PV,";");
    // ligne 7
    PUSH_SYM(S_WRITE,"ecrire");PUSH_SYM(S_ID,"a");PUSH_SYM(S_MULT,"*");PUSH_SYM(S_ID,"b");PUSH_SYM(S_PV,";");
    // ligne 8
    PUSH_SYM(S_ID,"e");PUSH_SYM(S_AFFECT,":=");PUSH_SYM(S_ID,"b");PUSH_SYM(S_PLUS,"+");PUSH_SYM(S_ID,"d");PUSH_SYM(S_PV,";");
    // ligne 9
    PUSH_SYM(S_WRITE,"ecrire");PUSH_SYM(S_ID,"e");PUSH_SYM(S_PV,";");
    // eof
    PUSH_SYM(S_EOF,"");

    // verification de l'adequation des quatres tableaux
    // -- on vérifie d'abord la taille
    if(symbols.size() != expectedSymbols.size())
    {   FAILED(0);
        PRINT("Les tailles des tableaux ne correspondent pas !");
        PRINT("symbols.size() = " << symbols.size());
        PRINT("expectedSymbols.size() = " << expectedSymbols.size());
    }
    else
    {   list<Symbol>::iterator realSymbol = symbols.begin(), expectedSymbol = expectedSymbols.begin();
        // ici on peut tester que sur un itérateur car on sait que tous les tableaux font la meme taille
        int iter(1);
        bool failed(false);
        while(realSymbol != symbols.end())
        {   // tests de correspondance
            if(realSymbol->code != expectedSymbol->code)
            {   FAILED(iter);
                PRINT("real code = '" << realSymbol->code << "'");
                PRINT("expected code = '" << expectedSymbol->code << "'");
                failed = true;
                break; // sortie du while
            }
            else if(realSymbol->buf != expectedSymbol->buf)
            {   FAILED(iter);
                PRINT("real buf = '" << realSymbol->buf << "'");
                PRINT("expected buf = '" << expectedSymbol->buf << "'");
                failed = true;
                break; // sortie du while
            }
            // incrément des itérateurs
            realSymbol++; expectedSymbol++;
            iter++;
        }
//.........这里部分代码省略.........
开发者ID:Hexanonyme,项目名称:GL_Lutin,代码行数:101,代码来源:lexertests.cpp

示例11: subset_of

bool subset_of(const SymbolList& in, const SymbolList& of) {
	return intersection(in, of).size() == in.size();
}
开发者ID:Templar-von-Midgard,项目名称:Context-Free-Grammar-transformer,代码行数:3,代码来源:Grammar.cpp


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