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


C++ table::ifexist方法代码示例

本文整理汇总了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;
}
开发者ID:vincewang15,项目名称:Compiler,代码行数:73,代码来源:Unifier.cpp


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