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


C++ ParseNode::getToken方法代码示例

本文整理汇总了C++中ParseNode::getToken方法的典型用法代码示例。如果您正苦于以下问题:C++ ParseNode::getToken方法的具体用法?C++ ParseNode::getToken怎么用?C++ ParseNode::getToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParseNode的用法示例。


在下文中一共展示了ParseNode::getToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addSymbols

// pre: the state 'lastState' is a newly created state that has only a lambda transition coming in to it.
// post: lastState is updated to a new state that has the property that only lambda transitions go to it.
void addSymbols(ParseNode::iterator_type begin, ParseNode::iterator_type end, FaSymbolTable &symTab, FaRuleIr &ruleIr, FaNfa *nfa, unsigned &lastState)
{
	for(ParseNode::iterator_type i = begin; i != end; ++i)
	{
		assert((*i)->getToken() == RULE_rcsymbol);
		unsigned symbolHeadToken = (*(*i)->begin())->getToken();
	
		if(symbolHeadToken == RULE_rcitem)
		{
			ParseNode *item = *(*i)->begin();
			assert(item->getToken() == RULE_rcitem);
			
			ParseNode *item2 = *item->begin();
			std::string item2Text = item2->getTokenText();
			unsigned newState = ruleIr.addState(*nfa);
			
			bool ok = ruleIr.addEdge(*nfa, lastState, newState, item2Text);
			if(!ok)
			{
				std::string msg = "error adding NFA transition (check that keywords and tokens are defined before use)";
				throw ParseSpecificError((*i)->getLine(), (*i)->getFile(), msg);
			}
			
			lastState = newState;
		}
		else
		if(symbolHeadToken == '{' || symbolHeadToken == '[')
		{
			unsigned q0 = ruleIr.addState(*nfa);
			ruleIr.addLambda(*nfa, lastState, q0);
			lastState = q0;
			ParseNode::iterator_type j = (*i)->begin();
			ParseNode *alternate = *++j;
			assert(alternate->getToken() == RULE_rcalternate);
			addSymbols(alternate->begin(), alternate->end(), symTab, ruleIr, nfa, lastState);
			
			if(symbolHeadToken == '{')
				ruleIr.addLambda(*nfa, lastState, q0);
			ruleIr.addLambda(*nfa, q0, lastState);
			unsigned qf = ruleIr.addState(*nfa);
			ruleIr.addLambda(*nfa, lastState, qf);
			lastState = qf;
		}
	}
	
	unsigned newState = ruleIr.addState(*nfa);
	ruleIr.addLambda(*nfa, lastState, newState);
	lastState = newState;
}
开发者ID:huffman,项目名称:CRUDASM7,代码行数:51,代码来源:ruleparse.cpp


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