Skip to content
Snippets Groups Projects
Commit 73edebde authored by Tomáš Pecka's avatar Tomáš Pecka
Browse files

aconversions fixes and allow to call RG->RE

parent 1ca00889
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,14 @@ ConversionHandler::ConversionHandler( list<Token> & tokens, const string & targe ...@@ -21,7 +21,14 @@ ConversionHandler::ConversionHandler( list<Token> & tokens, const string & targe
{ {
m_source = parseFormalismFromString( m_tokens.front( ).getData( ) ); m_source = parseFormalismFromString( m_tokens.front( ).getData( ) );
m_target = parseFormalismFromString( target ); m_target = parseFormalismFromString( target );
if( m_source == m_target )
throw AlibException( "Cannot convert between same formalisms." );
m_algorithm = parseAlgorithmFromString( algorithm ); m_algorithm = parseAlgorithmFromString( algorithm );
if( m_algorithm == DEFAULT )
m_algorithm = getDefaultAlgorithm( );
if( ! checkAlgorithm( ) ) if( ! checkAlgorithm( ) )
throw AlibException( "Invalid conversion. See help." ); throw AlibException( "Invalid conversion. See help." );
} }
...@@ -73,7 +80,34 @@ void ConversionHandler::convertGrammar( ostream & out ) ...@@ -73,7 +80,34 @@ void ConversionHandler::convertGrammar( ostream & out )
} }
else if( m_target == REGULAR_EXPRESSION ) else if( m_target == REGULAR_EXPRESSION )
{ {
// TODO: AbstractRGtoREConverter* conv;
RightRegularGrammar rrg;
LeftRegularGrammar lrg;
bool rightGrammar = true;
try
{
GrammarFactory::buildRightRegularGrammar( ug );
}
catch( AlibException & e )
{
rightGrammar = false;
}
if( m_algorithm == BRZOZOWSKI_ALGEBRAIC && rightGrammar )
{
rrg = GrammarFactory::buildRightRegularGrammar( ug );
conv = new RRGAlgebraic( rrg );
}
else if( m_algorithm == BRZOZOWSKI_ALGEBRAIC && ! rightGrammar )
{
lrg = GrammarFactory::buildLeftRegularGrammar( ug );
conv = new LRGAlgebraic( lrg );
}
else throw AlibException( "wtf?" );
conv->convert( ).toXML( out );
delete conv;
} }
} }
void ConversionHandler::convertRegExp( ostream & out ) void ConversionHandler::convertRegExp( ostream & out )
...@@ -158,6 +192,7 @@ ConversionHandler::TAlgorithm ConversionHandler::parseAlgorithmFromString( const ...@@ -158,6 +192,7 @@ ConversionHandler::TAlgorithm ConversionHandler::parseAlgorithmFromString( const
if( algorithm == "" ) return DEFAULT; if( algorithm == "" ) return DEFAULT;
   
/* FA to RE */ /* FA to RE */
/* RG to RE */
if( algorithm == "elimination" ) return STATE_ELIMINATION; if( algorithm == "elimination" ) return STATE_ELIMINATION;
if( algorithm == "algebraic" ) return BRZOZOWSKI_ALGEBRAIC; if( algorithm == "algebraic" ) return BRZOZOWSKI_ALGEBRAIC;
   
...@@ -175,8 +210,6 @@ ConversionHandler::TAlgorithm ConversionHandler::parseAlgorithmFromString( const ...@@ -175,8 +210,6 @@ ConversionHandler::TAlgorithm ConversionHandler::parseAlgorithmFromString( const
/* RG to FA */ /* RG to FA */
if( algorithm == "rg" ) return RG_FA; if( algorithm == "rg" ) return RG_FA;
   
/* RG to RE */
throw AlibException( "Invalid conversion. See help." ); throw AlibException( "Invalid conversion. See help." );
} }
   
...@@ -187,7 +220,7 @@ ConversionHandler::TAlgorithm ConversionHandler::getDefaultAlgorithm( void ) con ...@@ -187,7 +220,7 @@ ConversionHandler::TAlgorithm ConversionHandler::getDefaultAlgorithm( void ) con
if( m_source == REGULAR_EXPRESSION && m_target == FINITE_AUTOMATA ) return GLUSHKOV; if( m_source == REGULAR_EXPRESSION && m_target == FINITE_AUTOMATA ) return GLUSHKOV;
if( m_source == REGULAR_EXPRESSION && m_target == REGULAR_GRAMMAR ) return DEFAULT; if( m_source == REGULAR_EXPRESSION && m_target == REGULAR_GRAMMAR ) return DEFAULT;
if( m_source == REGULAR_GRAMMAR && m_target == FINITE_AUTOMATA ) return RG_FA; if( m_source == REGULAR_GRAMMAR && m_target == FINITE_AUTOMATA ) return RG_FA;
if( m_source == REGULAR_GRAMMAR && m_target == REGULAR_EXPRESSION ) return DEFAULT; if( m_source == REGULAR_GRAMMAR && m_target == REGULAR_EXPRESSION ) return BRZOZOWSKI_ALGEBRAIC;
   
throw AlibException( "ConversionHandler::getDefaultAlgorithm - unreachable code" ); throw AlibException( "ConversionHandler::getDefaultAlgorithm - unreachable code" );
} }
...@@ -206,7 +239,6 @@ bool ConversionHandler::checkAlgorithm( void ) const ...@@ -206,7 +239,6 @@ bool ConversionHandler::checkAlgorithm( void ) const
   
/* RE to FA */ /* RE to FA */
/* RE to RG */ /* RE to RG */
if( m_source == REGULAR_EXPRESSION ) if( m_source == REGULAR_EXPRESSION )
return ( m_target == FINITE_AUTOMATA && return ( m_target == FINITE_AUTOMATA &&
( m_algorithm == BRZOZOWSKI_DERIVATION || m_algorithm == GLUSHKOV || m_algorithm == THOMPSON ) ) || ( m_algorithm == BRZOZOWSKI_DERIVATION || m_algorithm == GLUSHKOV || m_algorithm == THOMPSON ) ) ||
...@@ -219,7 +251,7 @@ bool ConversionHandler::checkAlgorithm( void ) const ...@@ -219,7 +251,7 @@ bool ConversionHandler::checkAlgorithm( void ) const
return ( m_target == FINITE_AUTOMATA && return ( m_target == FINITE_AUTOMATA &&
( m_algorithm == RG_FA ) ) || ( m_algorithm == RG_FA ) ) ||
( m_target == REGULAR_EXPRESSION && ( m_target == REGULAR_EXPRESSION &&
( false ) ); ( m_algorithm == BRZOZOWSKI_ALGEBRAIC ) );
   
return false; return false;
} }
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include "../fa2rg/fa2rrg/FAtoRRGConverter.h" #include "../fa2rg/fa2rrg/FAtoRRGConverter.h"
#include "../rg2fa/LRGtoFAConverter.h" #include "../rg2fa/LRGtoFAConverter.h"
#include "../rg2fa/RRGtoFAConverter.h" #include "../rg2fa/RRGtoFAConverter.h"
#include "../rg2re/RRGAlgebraic.h"
#include "../rg2re/LRGAlgebraic.h"
   
namespace conversions namespace conversions
{ {
...@@ -56,6 +58,8 @@ public: ...@@ -56,6 +58,8 @@ public:
RG_FA, RG_FA,
   
/* RG to RE */ /* RG to RE */
// BRZOZOWSKI_ALGEBRAIC,
// STATE_ELIMINATION,
}; };
   
enum TFormalism enum TFormalism
......
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