Skip to content
Snippets Groups Projects
Commit 0b251989 authored by Jan Vesely's avatar Jan Vesely
Browse files

add comments into rhdpda determinization

parent 976656f6
No related branches found
No related tags found
No related merge requests found
......@@ -23,30 +23,115 @@ using namespace alphabet;
namespace determinization {
namespace rhdpda {
 
/**
* Class for running basic determinization algorithm on rhdpda.
*/
class RhdpdaDeterminizer : public Determinizer
{
private:
/** Real-time height-deterministic pushdown automaton */
PDA* rhdpda;
/** Real-time deterministic pushdown automaton */
PDA* rdpda;
/** Map of states of deterministic pda, where key is the name of state and value is data about this state */
map<string, StateData> states;
/** Set of internal transitions from rhdpda */
set<TransitionPDA> internalTransitions;
/** Set of push transitions from rhdpda */
set<TransitionPDA> pushTransitions;
/** Set of pop transitions from rhdpda */
set<TransitionPDA> popTransitions;
/** Set of all possible pairs of states and stack symbols */
set<StateSymbolPair> allStateSymbolPairs;
/** Vector with all possible S components of deterministic pda */
vector<SComponent> allSComponents;
/** Vector with all possible R components of deterministic pda */
vector<RComponent> allRComponents;
 
/**
* Divides transitions of rhdpda into internal, push and pop transitions.
*
* @return void
*/
void divideTransitions();
/**
* Adds transitions into determinsitic pda with values from given sample transition and with symbol X
* on the end of push and pop symbols, where X is any stack symbol.
*
* @param sampleTransition
* @return void
*/
void generateTransitionsForAllPossibleStackSymbols(const TransitionPDA& sampleTransition);
/**
* Returns name of stack symbol of deterministic pda which is created from given S and R component and input symbol.
* This method also ensures that this stack symbol is already added into deterministic pda.
*
* @param s S component of stack symbol
* @param r R component of stack symbol
* @param input input symbol
* @return name of stack symbol
*/
string buildStackSymbolName(const SComponent& s, const RComponent& r, const Symbol& input);
/**
* Returns state and symbol pairs that are created by combining state from given set of states and given symbol.
*
* @param states
* @param symbol
* @return state and symbol pairs that are created by combining given states and symbol
*/
set<StateSymbolPair> combineStatesWithSymbol(const set<State>& states, const Symbol& symbol);
/**
* Returns S component that contains pairs where both elements are same. These pairs are created from given set
* of state and symbol pairs.
*
* @param pairs set of state and symbol pairs from which to create identity pairs
* @return pairs where both elements are same
*/
const SComponent getSComponentWithPairsIdentity(const set<StateSymbolPair>& pairs);
/**
* Returns existing state from states map, if there is one with same name, or creates new one and adds it into
* states map and deterministic pda.
*
* @param s S component of state
* @param r R component of state
* @return state of deterministic pda
*/
const State& getOrCreateState(const SComponent& s, const RComponent& r);
/**
* Runs some initializiation stuff before determinization algorithm.
*/
void initDeterminization();
 
public:
/**
* @param rhdpda real-time height-deterministic pushdown automaton given for determinization
*/
RhdpdaDeterminizer(PDA* rhdpda);
/**
* Runs determinization algorithm on rhdpda given in constructor.
*
* @return real-time deterministic pushdown automaton
*/
Automaton* determinize();
};
 
}
......
......@@ -24,29 +24,106 @@ using namespace determinization;
namespace determinization {
namespace rhdpda {
 
/**
* Class for running second version of determinization algorithm on rhdpda.
*/
class RhdpdaDeterminizer2 : public Determinizer
{
private:
/** Real-time height-deterministic pushdown automaton */
PDA* rhdpda;
/** Real-time deterministic pushdown automaton */
PDA* rdpda;
/** Map of states of deterministic pda, where key is the name of state and value is data about this state */
map<string, StateData> states;
/** Set of internal transitions from rhdpda */
set<TransitionPDA> internalTransitions;
/** Set of push transitions from rhdpda */
set<TransitionPDA> pushTransitions;
/** Set of pop transitions from rhdpda */
set<TransitionPDA> popTransitions;
/** Set of all possible pairs of states and stack symbols */
set<StateSymbolPair> allStateSymbolPairs;
/** Vector with all possible S components of deterministic pda */
vector<SComponent> allSComponents;
/** Vector with all possible R components of deterministic pda */
vector<RComponent> allRComponents;
 
/**
* Divides transitions of rhdpda into internal, push and pop transitions.
*
* @return void
*/
void divideTransitions();
/**
* Returns name of stack symbol of deterministic pda which is created from given S and R component and input symbol.
* This method also ensures that this stack symbol is already added into deterministic pda.
*
* @param s S component of stack symbol
* @param r R component of stack symbol
* @param input input symbol
* @return name of stack symbol
*/
string buildStackSymbolName(const SComponent& s, const RComponent& r, const Symbol& input);
/**
* Returns state and symbol pairs that are created by combining state from given set of states and given symbol.
*
* @param states
* @param symbol
* @return state and symbol pairs that are created by combining given states and symbol
*/
set<StateSymbolPair> combineStatesWithSymbol(const set<State>& states, const Symbol& symbol);
/**
* Returns S component that contains pairs where both elements are same. These pairs are created from given set
* of state and symbol pairs.
*
* @param pairs set of state and symbol pairs from which to create identity pairs
* @return pairs where both elements are same
*/
const SComponent getSComponentWithPairsIdentity(const set<StateSymbolPair>& pairs);
/**
* Returns existing state from states map, if there is one with same name, or creates new one and adds it into
* states map and deterministic pda.
*
* @param s S component of state
* @param r R component of state
* @return state of deterministic pda
*/
const State& getOrCreateState(const SComponent& s, const RComponent& r);
/**
* Runs some initializiation stuff before determinization algorithm.
*/
void initDeterminization();
 
public:
/**
* @param rhdpda real-time height-deterministic pushdown automaton given for determinization
*/
RhdpdaDeterminizer2(PDA* rhdpda);
/**
* Runs determinization algorithm on rhdpda given in constructor.
*
* @return real-time deterministic pushdown automaton
*/
Automaton* determinize();
};
 
}
......
......@@ -9,7 +9,11 @@ namespace determinization {
namespace rhdpda {
 
 
struct StateSymbolPair {
/**
* Struct fot storing pair which consists of state and symbol.
*/
struct StateSymbolPair
{
State state;
Symbol symbol;
 
......@@ -33,7 +37,12 @@ struct StateSymbolPair {
}
};
 
struct PairOfPairs {
/**
* Struct for storing two pairs of state and symbol.
*/
struct PairOfPairs
{
StateSymbolPair pair1;
StateSymbolPair pair2;
......@@ -58,7 +67,11 @@ struct PairOfPairs {
};
 
 
struct SComponent {
/**
* Struct for storing S component of state from deterministic pda.
*/
struct SComponent
{
set<PairOfPairs> pairsOfPairs;
SComponent() {}
SComponent(const set<PairOfPairs>& pairsOfPairs)
......@@ -66,7 +79,11 @@ struct SComponent {
};
 
 
struct RComponent {
/**
* Struct for storing R component of state from deterministic pda.
*/
struct RComponent
{
set<StateSymbolPair> pairs;
RComponent() {}
RComponent(const set<StateSymbolPair>& pairs)
......@@ -74,10 +91,22 @@ struct RComponent {
};
 
 
struct StateData {
/**
* Struct for storing data about state from deterministic pda.
*/
struct StateData
{
/** State of deterministic pda */
State state;
/** S component of this state */
SComponent s;
/** R component of this state */
RComponent r;
/** Indicates if this state is already marked by determinization algorithm or not */
bool isMarked;
StateData(const State& state, const SComponent& s, const RComponent& r)
......
......@@ -21,22 +21,109 @@ using namespace alphabet;
namespace determinization {
namespace rhdpda {
 
/**
* Library class with some methods that can be used by all rhdpda determinization algorithms.
*/
class RhdpdaUtils
{
public:
/** Symbol which represents bottom of stack */
static const Symbol BOTTOM_OF_STACK_SYMBOL;
 
/**
* Returns string representation of given state and symbol pair.
*
* @param pair
* @return name of pair
*/
static string buildPairName(const StateSymbolPair& pair);
/**
* Returns name of state of deterministic pda which is created from given S and R component.
*
* @param s S component of state
* @param r R component of state
* @return name of state
*/
static string buildStateName(const SComponent& s, const RComponent& r);
/**
* Returns existing state from states map, if there is one with same name, or creates new one and adds it into
* given states map and given pda.
*
* @param s S component of state
* @param r R component of state
* @param states map of existing states, where key is the name of state and value is data about this state
* @param rdpda deterministic pda that contains given map of states
* @return state of deterministic pda
*/
static const State& getOrCreateState(const SComponent& s, const RComponent& r, map<string, StateData>& states,
PDA& rdpda);
/**
* Returns S component that contains pairs where both elements are same. These pairs are created from given set
* of state and symbol pairs.
*
* @param pairs set of state and symbol pairs from which to create identity pairs
* @return pairs where both elements are same
*/
static const SComponent getSComponentWithPairsIdentity(const set<StateSymbolPair>& pairs);
/**
* Returns name of stack symbol of deterministic pda which is created from given S and R component and input symbol.
* This method also ensures that this stack symbol is already added into given deterministic pda.
*
* @param s S component of stack symbol
* @param r R component of stack symbol
* @param input input symbol
* @param rdpda deterministic pda
* @return name of stack symbol
*/
static string buildStackSymbolName(const SComponent& s, const RComponent& r, const Symbol& input, PDA& rdpda);
/**
* Returns all possible S components of deterministic pda.
*
* @param pairs all possible pairs of state and symbol
* @return all possible S components
*/
static vector<SComponent> generateAllPossibleSComponents(set<StateSymbolPair>& pairs);
/**
* Returns all possible R components of deterministic pda.
*
* @param pairs all possible pairs of state and symbol
* @return all possible R components
*/
static vector<RComponent> generateAllPossibleRComponents(set<StateSymbolPair>& pairs);
/**
* Returns state data about first state in given states map that isn't marked yet. Returns NULL if all states
* are already marked.
*
* @param states map of all states in deterministic pda
* @return state data about first unmarked state
*/
static StateData* getUnmarkedState(map<string, StateData>& states);
/**
* Returns state and symbol pairs that are created by combining state from given set of states and given symbol.
*
* @param states
* @param symbol
* @return state and symbol pairs that are created by combining given states and symbol
*/
static set<StateSymbolPair> combineStatesWithSymbol(const set<State>& states, const Symbol& symbol);
/**
* Returns all possible state and symbol pairs created with states and symbols from given rhdpda.
*
* @param rhdpda real-time height-deterministic pda
* @return all possible state and symbol pairs
*/
static set<StateSymbolPair> buildAllStateSymbolPairs(PDA& rhdpda);
};
 
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment