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


C++ Grammar::build_CFSM方法代码示例

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


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

示例1: main

int main() {
//	freopen("in.txt", "r+t", stdin);
//	freopen("out.txt", "w+t", stdout);
	Grammar g;
	parsingProduction("<instruction> 	-> <navigational>", g);
	parsingProduction("<instruction> 	-> <time-keeping>", g);
	parsingProduction("<instruction> 	-> <navigational> AND <time-keeping>", g);
	parsingProduction("<navigational> 	-> <directional>", g);
	parsingProduction("<navigational> 	-> <navigational> AND THEN <directional>", g);
	parsingProduction("<directional> 	-> <how> <direction>", g);
	parsingProduction("<directional> 	-> <how> <direction> <where>", g);
	parsingProduction("<how> 			-> GO", g);
	parsingProduction("<how> 			-> GO <when>", g);
	parsingProduction("<how>			-> KEEP", g);
	parsingProduction("<direction> 		-> RIGHT", g);
	parsingProduction("<direction>		-> LEFT", g);
	parsingProduction("<when>			-> FIRST", g);
	parsingProduction("<when>			-> SECOND", g);
	parsingProduction("<when>			-> THIRD", g);
	parsingProduction("<where> 			-> AT <sign>", g);
	parsingProduction("<sign>			-> SIGNWORDS", g);
	parsingProduction("<time-keeping> 	-> <record>", g);
	parsingProduction("<time-keeping>	-> <change>", g);
	parsingProduction("<record>			-> RECORD TIME", g);
	parsingProduction("<change>			-> <cas> TO NNN KMH", g);
	parsingProduction("<cas>			-> CHANGE AVERAGE SPEED", g);
	parsingProduction("<cas> 			-> CAS", g);
	g.start_symbol = "<instruction>";
		
	g.fill_first_set();
	g.fill_follow_set();
	g.build_CFSM();
	
	char 	line[1024];
	int 	cases = 0;
	while(gets(line)) {
		if(!strcmp(line, "#"))
			break;
		queue<string> tokens;
		vector<string> val;
		int f = scanTokens(line, tokens, val);
		printf("%3d.", ++cases);
		if(!f) {
			puts(" Trap!");
			continue;
		}
		f = g.slr1driver(tokens);
		if(!f) {
			puts(" Trap!");
			continue;
		}
		for(int i = 0; i < val.size(); i++) {
			if(val[i][0] == '"')
				for(int j = 0; j < val[i].length(); j++)
					if(val[i][j] == '_')
						val[i][j] = ' ';
			printf(" %s", val[i].c_str());
		}
		puts("");
	}
	return 0;
}
开发者ID:JohnXinhua,项目名称:UVa,代码行数:62,代码来源:171+-+Car+Trialling.cpp


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