Пример #1
0
	PureRegex::PureRegex(const String & regex)
	{
		RegexParser p;
		RefPtr<RegexNode> tree = p.Parse(regex);
		if (tree)
		{
			NFA_Graph nfa;
			nfa.GenerateFromRegexTree(tree.operator ->());
			DFA_Graph dfa;
			dfa.Generate(&nfa);
			dfaTable = new DFA_Table();
			dfa.ToDfaTable(dfaTable.operator->());
		}
		else
		{
			IllegalRegexException ex;
			if (p.Errors.Count())
				ex.Message = p.Errors[0].Text;
			throw ex;
		}
	}
Пример #2
0
	void MetaLexer::ConstructDFA()
	{
		RegexParser parser;
		NFA_Graph nfa;
		NFA_Node * node = nfa.CreateNode();
		nfa.SetStartNode(node);
		for (int i=0; i<Regex.Count(); i++)
		{
			RefPtr<RegexNode> tree = parser.Parse(Regex[i]);
			if (tree)
			{
				NFA_Graph cNfa;
				cNfa.GenerateFromRegexTree(tree.operator->(), true);
				cNfa.SetTerminalIdentifier(i);
				nfa.CombineNFA(&cNfa);
				NFA_Translation * trans = nfa.CreateTranslation();
				trans->NodeDest = cNfa.GetStartNode();
				trans->NodeSrc = node;
				trans->NodeDest->PrevTranslations.Add(trans);
				trans->NodeSrc->Translations.Add(trans);
			}
			else
			{
				LexerError err;
				err.Position = 0;
				err.Text = L"Illegal regex for \"" + String(TokenNames[i]) + L"\"";
				Errors.Add(err);
				return;
			}
		}
		nfa.PostGenerationProcess();
		DFA_Graph dfaGraph;
		dfaGraph.Generate(&nfa);
		dfa = new DFA_Table();
		dfaGraph.ToDfaTable(dfa.operator ->());
	}