Skip to content
Snippets Groups Projects
Commit 260ca7c1 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

fix run of RHDPDA

parent c5465969
No related branches found
No related tags found
1 merge request!102Merge jt
...@@ -650,7 +650,6 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS ...@@ -650,7 +650,6 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS
}; };
unsigned i = 0; unsigned i = 0;
ext::set < unsigned > occ; ext::set < unsigned > occ;
bool res = true;
   
if ( automaton.getFinalStates ( ).count ( state ) ) if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i ); occ.insert ( i );
...@@ -660,6 +659,8 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS ...@@ -660,6 +659,8 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS
   
for ( auto symbolIter = string.getContent ( ).begin ( ); symbolIter != string.getContent ( ).end ( ); ) { for ( auto symbolIter = string.getContent ( ).begin ( ); symbolIter != string.getContent ( ).end ( ); ) {
   
bool transitionFound = false;
auto callTransition = automaton.getCallTransitions ( ).find ( std::pair < StateType, common::symbol_or_epsilon < InputSymbolType > > ( state, * symbolIter ) ); auto callTransition = automaton.getCallTransitions ( ).find ( std::pair < StateType, common::symbol_or_epsilon < InputSymbolType > > ( state, * symbolIter ) );
   
if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) { if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) {
...@@ -672,11 +673,10 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS ...@@ -672,11 +673,10 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS
if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) { if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) {
pushdownStore.push_back ( callTransition->second.second ); pushdownStore.push_back ( callTransition->second.second );
state = callTransition->second.first; state = callTransition->second.first;
} else { transitionFound = true;
res = false;
} }
   
if ( !res ) { if ( ! transitionFound ) {
auto returnTransition = automaton.getReturnTransitions ( ).find ( std::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType > ( state, * symbolIter, pushdownStore.back ( ) ) ); auto returnTransition = automaton.getReturnTransitions ( ).find ( std::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType > ( state, * symbolIter, pushdownStore.back ( ) ) );
   
if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) { if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) {
...@@ -689,12 +689,11 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS ...@@ -689,12 +689,11 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS
if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) { if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) {
pushdownStore.pop_back ( ); pushdownStore.pop_back ( );
state = returnTransition->second; state = returnTransition->second;
} else { transitionFound = true;
res = false;
} }
} }
   
if ( !res ) { if ( ! transitionFound ) {
auto localTransition = automaton.getLocalTransitions ( ).find ( std::pair < StateType, common::symbol_or_epsilon < InputSymbolType > > ( state, * symbolIter ) ); auto localTransition = automaton.getLocalTransitions ( ).find ( std::pair < StateType, common::symbol_or_epsilon < InputSymbolType > > ( state, * symbolIter ) );
   
if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) { if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) {
...@@ -704,23 +703,64 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS ...@@ -704,23 +703,64 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS
localTransition = automaton.getLocalTransitions ( ).find ( std::make_pair ( state, common::symbol_or_epsilon < InputSymbolType > ( ) ) ); localTransition = automaton.getLocalTransitions ( ).find ( std::make_pair ( state, common::symbol_or_epsilon < InputSymbolType > ( ) ) );
} }
   
if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) {
state = localTransition->second; state = localTransition->second;
else transitionFound = true;
res = false; }
} }
   
if ( ! transitionFound )
return ext::make_tuple ( false, state, occ, pushdownStore );
if ( automaton.getFinalStates ( ).count ( state ) ) if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i ); occ.insert ( i );
   
if ( common::GlobalData::verbose ) if ( common::GlobalData::verbose )
common::Streams::log << state << std::endl; common::Streams::log << state << std::endl;
}
while ( true ) {
bool transitionFound = false;
auto callTransition = automaton.getCallTransitions ( ).find ( std::make_pair ( state, common::symbol_or_epsilon < InputSymbolType > ( ) ) );
if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) {
pushdownStore.push_back ( callTransition->second.second );
state = callTransition->second.first;
transitionFound = true;
}
if ( ! transitionFound ) {
auto returnTransition = automaton.getReturnTransitions ( ).find ( std::make_tuple ( state, common::symbol_or_epsilon < InputSymbolType > ( ), pushdownStore.back ( ) ) );
   
if ( res == false ) if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) {
pushdownStore.pop_back ( );
state = returnTransition->second;
transitionFound = true;
}
}
if ( ! transitionFound ) {
auto localTransition = automaton.getLocalTransitions ( ).find ( std::make_pair ( state, common::symbol_or_epsilon < InputSymbolType > ( ) ) );
if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) {
state = localTransition->second;
transitionFound = true;
}
}
if ( ! transitionFound )
break; break;
if ( automaton.getFinalStates ( ).count ( state ) )
occ.insert ( i );
if ( common::GlobalData::verbose )
common::Streams::log << state << std::endl;
} }
   
return ext::make_tuple ( res, state, occ, pushdownStore ); return ext::make_tuple ( true, state, occ, pushdownStore );
} }
   
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
......
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