本文整理汇总了C++中rule::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ rule::begin方法的具体用法?C++ rule::begin怎么用?C++ rule::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rule
的用法示例。
在下文中一共展示了rule::begin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decompose
// decomposes a rule (A -> B C D E ...) into the rules (A -> B#C#D E), (B#C#D -> B#C D), (B#C -> B C), ... respectively.
// might expand 'nonterminals'
// might rewrite 'rule_to_decompose'
void decompose(rule &rule_to_decompose, set<string> &nonterminals, rules &decomposed_rules) {
string temp;
if (rule_to_decompose.size() == 2) {
if (is_in(rule_to_decompose[1], nonterminals)) {
cerr << " ERROR : irregular occurence of chain rule (i.e. A -> B)! - ignored " << '\n';
return;
} else
decomposed_rules.insert(rule_to_decompose);
} else {
for (size_t i = 1; i<rule_to_decompose.size();++i)
if (!is_in(rule_to_decompose[i], nonterminals)) {
temp = "#" + rule_to_decompose[i];
nonterminals.insert(temp);
decomposed_rules.insert(rule{ temp, rule_to_decompose[i] });
replace(rule_to_decompose.begin() + i, rule_to_decompose.end(), rule_to_decompose[i], temp);
}
while(rule_to_decompose.size() > 3) {
temp = rule_to_decompose[1] + "#" + rule_to_decompose[2];
nonterminals.insert(temp);
decomposed_rules.insert(rule{ temp, rule_to_decompose[1], rule_to_decompose[2] });
rule_to_decompose[1] = temp;
rule_to_decompose.erase(rule_to_decompose.begin() + 2);
}
decomposed_rules.insert(rule_to_decompose);
}
}