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


C++ NFA::createAll方法代码示例

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


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

示例1: main

int main() {
	cout << "Enter file name for lexical rules" << endl;
	string file = "test";
	cin >> file;
	FileReader *f = new FileReader();
	f->readTheFile((char*) file.c_str());
	f->initializeForNFA();
	NFA *n = new NFA(f->regularExpressions);
	n->defs = f->defs;
	n->matchedExps = f->expressionsID;
	n->createAll();
	cout << "  Start Conversion NFA to DFA " << endl;
	vector<char> all_inputs;
	for (set<char>::iterator i = n->input.begin(); i != n->input.end(); i++) {
		all_inputs.push_back(*i);
	}
	DFA_Builder* DFA = new DFA_Builder(n->NFATable, n->matchedExps, all_inputs);
	cout << " Conversion Function " << endl;
	DFA->NFA_to_DFA();

	cout << "Enter file name for syntax rules" << endl;
	string syntax_file = "syntax_test.txt";
	cin >> syntax_file;
	// read syntax rules file and generate productions
	SyntaxRulesParser* syntaxParser = new SyntaxRulesParser();
	syntaxParser->parse(syntax_file.c_str());
	vector<Production> prods = syntaxParser->productions;
	printf("Print Productions...\n");
		for (size_t i = 0; i < prods.size(); i++) {
			Production prod = prods[i];
			printf("%s -> ", prod.LHS.c_str());
			for (size_t j = 0; j < prod.RHS.size(); j++) {
				for (size_t k = 0; k < prod.RHS[j].size(); k++)
					printf("%s ", prod.RHS[j][k].name.c_str());
				puts("");
				if (j < prod.RHS.size() - 1)
					printf("     |");
			}
			puts("");
		}
		cout << endl;
	// Generate parser
	ParserGenerator* parserGenerator  = new ParserGenerator(syntaxParser->productions , syntaxParser->LHS_index);
	bool isLL1 = parserGenerator->generateParser();
	if(!isLL1)
	{
		cout << "Not LL(1) grammar" << endl;
		return 0;
	}
	// read program source file
	cout << "Enter file name for source code" << endl;
	string src_file = "src_file";
	cin >> src_file;
	Simulator* sim = new Simulator(DFA->DFA, DFA->patterns);
	sim->open_file(src_file.c_str());

	// start reading src file tokens and parse it using LL(1) parser
//	freopen("Parser_output.txt", "w", stdout);
	parserGenerator->SimuParser(sim);
//		string lex;
//		lex = sim->next_token().first;
//		while (!lex.empty())
//		{
//			cout << lex << endl;
//			lex = sim->next_token().first;
//		}

	fclose(stdout);

	//	test_parser();
	//	test_parser_parseFile();
	return 0;
}
开发者ID:Belbesy,项目名称:JCompiler,代码行数:73,代码来源:Test.cpp


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