本文整理汇总了C++中MMap::find方法的典型用法代码示例。如果您正苦于以下问题:C++ MMap::find方法的具体用法?C++ MMap::find怎么用?C++ MMap::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MMap
的用法示例。
在下文中一共展示了MMap::find方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildMTable
MMap BuildMTable(const FirstSets& first,
const FollowSets& follow,
Grammar& g)
{
MMap M;
std::wcout << L"\n Building M table \n";
for (int k = 0; k < g.GetNumOfProductions(); k++)
{
//Para cada producao da gramatica A = alfa
const Production& production = g.GetProduction(k);
Print(std::wcout, production);
//Aqui o first tem que ser em relacao a "alfa" e não a "A"
// pois o A engloba todos os "firsts" e aqui se quer o first especifico
// desta producao
// Entao o FirstSets& first é o "pior caso" o first de qualquer "A"
// No aho novo parece que tem um defeito de escrita e que o first deveria
// ser first alfa no dois (esta so no segundo)
//Nao testei se o follow teria que ter algo assim
std::set<const GrammarSymbol*> f = GetFirstSet(first, g, production);
//Regra 1
//auto f = first.Get(production.GetLeftSymbol());
for (auto it = f.begin(); it != f.end(); ++it)
{
// Para cada terminal a em primeiro(A)
const GrammarSymbol* pgs = (*it);
if (pgs->IsTerminal() && pgs != g.epsilon())
{
//M[A, a] = alfa
std::wcout << L"[" << production.GetLeftSymbol()->GetName() << L"," <<
pgs->GetName() << L"] = " ;
Print(std::wcout, production);
/*if (M.find(MKey(production.GetLeftSymbol(), pgs)) != M.end())
{
std::wcout << L"<-- duplicated" << std::endl;
throw std::exception("multiple entries");
}*/
auto MTableIt = M.find(MKey(production.GetLeftSymbol(), pgs, k));
if (MTableIt != M.end())
{
if (MTableIt->m_pNotTerminal->GetName() !=
production.GetLeftSymbol()->GetName())
{
//if (MTableIt->)
//M.insert(MKey(production.GetLeftSymbol(), pgs, k));
std::string strError;
strError = "Multiple entries ";
strError += to_utf8_string(production.GetLeftSymbol()->GetName());
strError += " -> ";
strError += to_utf8_string(pgs->GetName());
throw std::exception(strError.c_str());
}
else
{
//ja existe a regra igual
//std::string strError;
//strError = "Multiple entries ";
//strError += to_utf8_string(production.GetLeftSymbol()->GetName());
//strError += " -> ";
//strError += to_utf8_string(pgs->GetName());
//throw std::exception(strError.c_str());
}
}
else
{
//criar a regra
std::wcout << std::endl;
M.insert(MKey(production.GetLeftSymbol(), pgs, k));
}
//M[MKey(production.GetLeftSymbol(), pgs)] = k;
}
else if (pgs == g.epsilon())
{
// Nao existe epsilon o input stream
// entao vou fazer para cada follow
auto fo = follow.Get(production.GetLeftSymbol());
//se esta em folow
for (auto it = fo.begin(); it != fo.end(); ++it)
{
const GrammarSymbol* b = (*it);
if (b->IsTerminal() && b != g.epsilon()) //ou $ que da no mesmo
{
std::wcout << L"[" << production.GetLeftSymbol()->GetName() << L"," <<
b->GetName() << L"] = " ;
Print(std::wcout, production);
auto MTableIt = M.find(MKey(production.GetLeftSymbol(), b, k));
if (MTableIt != M.end())
{
if (MTableIt->m_pNotTerminal->GetName() !=
production.GetLeftSymbol()->GetName())
{
std::wcout << L"<-- duplicated" << std::endl;
//.........这里部分代码省略.........