本文整理汇总了C++中table::ifexist方法的典型用法代码示例。如果您正苦于以下问题:C++ table::ifexist方法的具体用法?C++ table::ifexist怎么用?C++ table::ifexist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类table
的用法示例。
在下文中一共展示了table::ifexist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: substitute
int unifier::substitute(vector<Token> &head, vector<Token> &body, table tab){
for (unsigned int i = 2; i < head.size() - 1; i++){
string newrule;
// if two constant, check if they are the same, move to the next position
if (head[i].type == Token::NUMBER && body[i].type == Token::NUMBER){
if (head[i].s == body[i].s){
continue;
}
else{ // if they are mis-matched constant, stop unifying and break the loop, in this case that means return to the caller
return -1;
}
}
// if one bound and one unbound
else if ((head[i].type == Token::BOUND && body[i].type == Token::UNBOUND) || (head[i].type == Token::UNBOUND && body[i].type == Token::BOUND)){
if (head[i].type == Token::BOUND){
newrule = head[i].s + " / " + body[i].s;
}
else
newrule = body[i].s + " / " + head[i].s;
}
// if one bound and one number at current position
else if ((head[i].type == Token::BOUND && body[i].type == Token::NUMBER) || (head[i].type == Token::NUMBER && body[i].type == Token::BOUND)){
if (head[i].type == Token::BOUND){
entry* thebound = tab.ifexist(head[i].s);
if (to_string(thebound->p->num) != body[i].s) // bound must has the same value as number
return -1;
newrule = body[i].s + " / " + head[i].s;
}
else{
entry* thebound = tab.ifexist(body[i].s);
if (head[i].s != to_string(thebound->p->num)) // bound must has the same value as number
return -1;
newrule = head[i].s + " / " + body[i].s;
}
}
// if one unbound and one number
else if ((head[i].type == Token::UNBOUND && body[i].type == Token::NUMBER) || (head[i].type == Token::NUMBER && body[i].type == Token::UNBOUND)){
if (head[i].type == Token::UNBOUND)
newrule = body[i].s + " / " + head[i].s;
else
newrule = head[i].s + " / " + body[i].s;
}
// if there are two unbound
else if (head[i].type == Token::UNBOUND && body[i].type == Token::UNBOUND){
newrule = head[i].s + " / " + body[i].s;
}
// if there are two identical bound, do nothing
else if (head[i].type == Token::BOUND && body[i].type == Token::BOUND){
if (head[i].s != body[i].s){
return -1;
}
else{
continue;
}
}
// else these two predicate cannot be matched
else{
return -1;
}
sr.addRule(newrule); // add rules into the lruleist
// replace all same variables by the other variables in both working copies
replace(head, newrule);
replace(body, newrule);
}
return 0;
}