本文整理汇总了C++中Grammar::find方法的典型用法代码示例。如果您正苦于以下问题:C++ Grammar::find方法的具体用法?C++ Grammar::find怎么用?C++ Grammar::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grammar
的用法示例。
在下文中一共展示了Grammar::find方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: gen_aux
void gen_aux(const Grammar& g, const string& word, vector<string>& ret, const int depth) {
if (depth > 3) {
return;
}
if (!bracketed(word)) {
ret.push_back(word);
} else {
// locate rule that corresponds to word
Grammar::const_iterator it = g.find(word);
if (it == g.end()) {
throw logic_error("empty rule");
}
// fetch the set of possible rules
const Rule_collection& c = it->second;
int index = nrand(c.size());
const Rule& r = c[index];
// recursively expand the selected rule
for (Rule::const_iterator i = r.begin();
i != r.end();
++i) {
gen_aux(g, *i, ret, depth + 1);
}
}
}
示例2: logic_error
void
gen_aux(const Grammar& g, const string& word, vector<string>& ret)
{
if (!bracketed(word))
{
ret.push_back(word);
}
else
{
// locate the rule that corresponds to word
Grammar::const_iterator it = g.find(word);
if (it == g.end())
throw logic_error("empty rule");
// fetch the set of possible rules
const Rule_collection& c = it->second;
// from which we select one at random
const Rule& r = c[nrand(c.size())];
// recursively expand the selected rule
for (Rule::const_iterator i = r.begin(); i != r.end(); ++i)
gen_aux(g, *i, ret);
}
}
示例3:
void
expand_aux (const Grammar &g, const std::string &word, TokenStack &result)
{
Grammar::const_iterator it = g.find (word);
if (g.end() != it)
{
const RuleCollection &rc = it->second;
const Rule &r = rc[nrand(rc.size())];
for (int i = r.size() - 1; i > -1; --i)
{
result.push(r[i]);
}
}
}
示例4: gen_aux
void gen_aux(const Grammar& g, const std::string& word, std::list<std::string>& ret)
{
if(!bracketed(word)) {
ret.push_back(word);
}
else {
Grammar::const_iterator it = g.find(word);
if(it == g.end())
throw std::logic_error("empty rule");
const Rule_collection& c = it->second;
const Rule& r = c[nrand(c.size())];
for(Rule::const_iterator i = r.begin(); i != r.end(); ++i)
gen_aux(g, *i, ret);
}
}
示例5: logic_error
void
gen_aux (const Grammar &g, const std::string &word, std::vector<std::string> &result)
{
if (!bracketed (word))
{
result.push_back (word);
}
else
{
Grammar::const_iterator it = g.find (word);
if (g.end() == it)
throw std::logic_error ("empty grammar rule");
const RuleCollection &rc = it->second;
const Rule &r = rc[nrand(rc.size())];
for (Rule::const_iterator r_it = r.begin(); r_it != r.end(); ++r_it)
gen_aux (g, *r_it, result);
}
}
示例6: gen_aux
void gen_aux(const Grammar& g, const std::string& word, std::vector<std::string>& ret)
{
if (!bracketed(word)) {
ret.push_back(word);
}
else {
Grammar::const_iterator it = g.find(word);
if (it == g.end()) {
std::logic_error("Rule is empty");
}
// get rule collection from grammar
const Rule_collection& c = it->second;
// select a new rule from collection at random
const Rule& r = c[nrand(c.size())];
// expand rule
for (Rule::const_iterator i = r.begin(); i != r.end(); ++i) {
gen_aux(g, *i, ret);
}
}
}