Exemplo n.º 1
0
	void convertToNFA(Automata& nfa, State& s, State& e) const
	{
		e = nfa.generateState();
		State childE;
		child->convertToNFA(nfa, s, childE);
		nfa.addTransition(childE, e, Transition::EPSILON);
		nfa.addTransition(e, s, Transition::EPSILON);
	}
Exemplo n.º 2
0
	void convertToNFA(Automata& nfa, State& s, State& e) const
	{
		State leftS; State leftE;
		State rightS; State rightE;
		left->convertToNFA(nfa, leftS, leftE);
		right->convertToNFA(nfa, rightS, rightE);
		s = nfa.generateState();
		e = nfa.generateState();
		nfa.addTransition(s, leftS, Transition::EPSILON);
		nfa.addTransition(s, rightS, Transition::EPSILON);
		nfa.addTransition(leftE, e, Transition::EPSILON);
		nfa.addTransition(rightE, e, Transition::EPSILON);
	}
Exemplo n.º 3
0
	void convertToNFA(Automata& nfa, State& s, State& e) const
	{
		s = nfa.generateState();
		e = nfa.generateState();
		State current = s;
		for (auto i = siblings.begin(); i != siblings.end(); ++i)
		{
			State siblingS;
			State siblingE;
			(*i)->convertToNFA(nfa, siblingS, siblingE);
			nfa.addTransition(current, siblingS, Transition::EPSILON);
			current = siblingE;
		}
		nfa.addTransition(current, e, Transition::EPSILON);
	}
Exemplo n.º 4
0
	bool chainConcatenation(Automata& nfa, int count, bool addEps, State& s, State& e) const
	{
		if (count == 0)
		{
			return false;
		}
		s = nfa.generateState();
		e = nfa.generateState();
		State current = s;
		for (int i = 0; i < count; ++i)
		{
			State childS;
			State childE;
			child->convertToNFA(nfa, childS, childE);
			nfa.addTransition(current, childS, Transition::EPSILON);
			if (addEps)
			{
				nfa.addTransition(current, e, Transition::EPSILON);
			}
			current = childE;
		}
		nfa.addTransition(current, e, Transition::EPSILON);
		return true;
	}
Exemplo n.º 5
0
	void convertToNFA(Automata& nfa, State& s, State& e) const
	{
		child->convertToNFA(nfa, s, e);
		nfa.addTransition(s, e, Transition::EPSILON);
	}
Exemplo n.º 6
0
	void convertToNFA(Automata& nfa, State& s, State& e) const
	{
		s = nfa.generateState();
		e = nfa.generateState();
		nfa.addTransition(s, e, Transition::WILDCARD);
	}
Exemplo n.º 7
0
	void convertToNFA(Automata& nfa, State& s, State& e) const
	{
		s = nfa.generateState();
		e = nfa.generateState();
		nfa.addTransition(s, e, rangeSet);
	}
Exemplo n.º 8
0
	void convertToNFA(Automata& nfa, State& s, State& e) const
	{
		// special case : {count,} {,}
		if (maxCount == -1)
		{
			State tmpS;
			State tmpE;
			bool result = chainConcatenation(nfa, minCount, false, tmpS, tmpE);
			State kleenS;
			State kleenE;
			KleenNode(child).convertToNFA(nfa, kleenS, kleenE);
			if (result)
			{
				s = tmpS;
				nfa.addTransition(tmpE, kleenS, Transition::EPSILON);
				e = kleenE;
			}
			else
			{
				s = kleenS;
				e = kleenE;
			}
		}
		// other case : {count}, {count1, count2}, {,count2}
		else if (minCount <= maxCount && minCount >= 0)
		{
			State firstS; State firstE;
			State secondS; State secondE;
			bool resultFirst = chainConcatenation(nfa, minCount, false, firstS, firstE);
			bool resultSecond = chainConcatenation(nfa, maxCount - minCount, true, secondS, secondE);
			if (!resultFirst && !resultSecond)
			{
				s = nfa.generateState();
				e = nfa.generateState();
				nfa.addTransition(s, e, Transition::EPSILON);
				return;
			}
			if (resultFirst)
			{
				s = firstS;
			}
			else
			{
				s = secondS;
			}
			if (resultSecond)
			{
				e = secondE;
			}
			else
			{
				e = firstE;
			}
			if (resultFirst && resultSecond)
			{
				nfa.addTransition(firstE, secondS, Transition::EPSILON);
			}
		}
		else
		{
			throw ParseError();
		}
	}