Skip to content
Snippets Groups Projects
ToRegExpStateElimination.h 3.1 KiB
Newer Older
Tomáš Pecka's avatar
Tomáš Pecka committed
/*
 * ToRegExpStateElimination.h
Tomáš Pecka's avatar
Tomáš Pecka committed
 *
 * This file is part of Algorithms library toolkit.
 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)

 * Algorithms library toolkit is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * Algorithms library toolkit is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with Algorithms library toolkit.  If not, see <http://www.gnu.org/licenses/>.
 *
Tomáš Pecka's avatar
Tomáš Pecka committed
 *  Created on: 9. 2. 2014
Jan Trávníček's avatar
Jan Trávníček committed
 *	  Author: Tomas Pecka
#ifndef TO_REG_EXP_STATE_ELIMINATION_H_
#define TO_REG_EXP_STATE_ELIMINATION_H_
#include <regexp/unbounded/UnboundedRegExp.h>
Tomáš Pecka's avatar
Tomáš Pecka committed

#include <automaton/FSM/DFA.h>
#include <automaton/FSM/NFA.h>
#include <automaton/FSM/MultiInitialStateNFA.h>
Tomáš Pecka's avatar
Tomáš Pecka committed
#include <automaton/FSM/EpsilonNFA.h>
#include <automaton/FSM/ExtendedNFA.h>

namespace automaton {
namespace convert {
 * Converts a finite automaton to a regular expression using using the State Elimination algorithm (Melichar: Jazyky a překlady 2.118).
 * This algorithm returns the regular expression as regexp::UnboundedRegExp.
Tomáš Pecka's avatar
Tomáš Pecka committed
 */
class ToRegExpStateElimination {
Tomáš Pecka's avatar
Tomáš Pecka committed
public:
Jan Trávníček's avatar
Jan Trávníček committed
	/**
	 * Performs conversion.
	 * @tparam T type of the finite automaton
	 * @param automaton finite automaton to convert
	 * @return unbounded regular expression equivalent to the original automaton
Jan Trávníček's avatar
Jan Trávníček committed
	 */
	template<class T>
	static regexp::UnboundedRegExp < > convert(const T& automaton);
Tomáš Pecka's avatar
Tomáš Pecka committed

private:
	/**
	 * Helper function to create new initial and final states in the automaton for the algorithm.
	 * @param automaton extended finite automaton
	 */
	static void extendExtendedNFA(automaton::ExtendedNFA < > & automaton);
	/**
	 * Helper function to create a regexp from all transitions between states @p from and @p to.
	 * It creates the alternation regexp of all such transitions.
	 * @param automaton automaton to select the transitions
	 * @param from source state in @param automaton
	 * @param to   destination state in @param automaton
	 * @return the regular expression node representing the transitions between states @p from and @p to
	 */
	static const regexp::UnboundedRegExpStructure < DefaultSymbolType > transitionsToRegExp(const automaton::ExtendedNFA < > & automaton, const DefaultStateType& from, const DefaultStateType& to);
	/**
	 * Helper function for the elimination of a single state according to the algorithm.
	 * @param extendedAutomaton automaton for the elimination
	 * @param state state to eliminate
	 * @return the @p extendedAutomaton after the elimination of a state @state.
	 */
	static automaton::ExtendedNFA < > eliminateState(const automaton::ExtendedNFA < > & extendedAutomaton, const DefaultStateType& state);
} /* namespace convert */
} /* namespace automaton */
#endif /* TO_REG_EXP_STATE_ELIMINATION_H_ */