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

Small code adjustm.

parent fec47132
No related branches found
No related tags found
No related merge requests found
...@@ -14,8 +14,6 @@ using namespace regexp; ...@@ -14,8 +14,6 @@ using namespace regexp;
namespace conversions namespace conversions
{ {
   
#define DEBUG false
Brzozowski::Brzozowski( const RegExp & re ) : AbstractREtoFAConverter( re ) Brzozowski::Brzozowski( const RegExp & re ) : AbstractREtoFAConverter( re )
{ {
   
...@@ -29,34 +27,28 @@ const FSM Brzozowski::convert( void ) ...@@ -29,34 +27,28 @@ const FSM Brzozowski::convert( void )
int i = 1; int i = 1;
while( true ) while( true )
{ {
if( DEBUG ) std::cout << "Round " << i << std::endl; // std::cout << "Round " << i << std::endl;
for( const auto & regexp : Qprev ) for( const auto & regexp : Qprev )
{ {
auto itFrom = Q.find( regexp );
if( DEBUG ) std::cout << "DERIVUJI:" << std::endl;
if( DEBUG ) const_cast<RegExp&>(regexp).toXML( cout );
BrzozowskiDerivative bd( regexp ); BrzozowskiDerivative bd( regexp );
if( DEBUG ) std::cout << "----" << std::endl; auto itFrom = Q.find( regexp );
// std::cout << "DERIVUJI:" << std::endl <<const_cast<RegExp&>(regexp).toXML( cout ) << std::endl << "----" << std::endl;
for( const auto & symbol : alphabet ) for( const auto & symbol : alphabet )
{ {
if( DEBUG ) std::cout << "Podle: " << symbol.getSymbol() << std::endl;
const RegExp re = bd.derivative( list<RegExpElement*>( 1, new RegExpSymbol( symbol.getSymbol( ) ) ) ); const RegExp re = bd.derivative( list<RegExpElement*>( 1, new RegExpSymbol( symbol.getSymbol( ) ) ) );
if( DEBUG ) const_cast<RegExp&>(re).toXML( cout ); // std::cout << "Podle: " << symbol.getSymbol() << std::endl;
// const_cast<RegExp&>(re).toXML( cout );
if( ! RegExpUtils::isRegExpEmpty( re ) ) if( ! RegExpUtils::isRegExpEmpty( re ) )
{ {
if( ! isInSet( re, Q ) ) if( ! isInSet( re, Q ) )
{ {
Qcurr.insert( re ); Qcurr.insert( re );
Q.insert( re ); Q.insert( re );
auto itTo = Q.find( re );
m_transitions.push_back( BrzozowskiTransition( * itFrom, symbol, * itTo ) );
}
else
{
auto itTo = Q.find( re );
m_transitions.push_back( BrzozowskiTransition( * itFrom, symbol, * itTo ) );
} }
auto itTo = Q.find( re );
m_transitions.push_back( BrzozowskiTransition( * itFrom, symbol, * itTo ) );
} }
} }
} }
...@@ -67,7 +59,7 @@ const FSM Brzozowski::convert( void ) ...@@ -67,7 +59,7 @@ const FSM Brzozowski::convert( void )
Qprev = Qcurr; Qprev = Qcurr;
Qcurr.clear( ); Qcurr.clear( );
   
if( DEBUG ) std::cout << "-------------------------------------------------------" << std::endl; // std::cout << "-------------------------------------------------------" << std::endl;
i += 1; i += 1;
   
} }
......
...@@ -23,15 +23,6 @@ bool RegExpComparator::operator() ( const RegExp & lhs, const RegExp & rhs ) //c ...@@ -23,15 +23,6 @@ bool RegExpComparator::operator() ( const RegExp & lhs, const RegExp & rhs ) //c
RegExpElement * leftRoot = const_cast<RegExp&>( lhs ).getRegExp( ); RegExpElement * leftRoot = const_cast<RegExp&>( lhs ).getRegExp( );
RegExpElement * rightRoot = const_cast<RegExp&>( rhs ).getRegExp( ); RegExpElement * rightRoot = const_cast<RegExp&>( rhs ).getRegExp( );
   
if( ! leftRoot ){
std::cout << "NOLEFT" << std::endl;
const_cast<RegExp&>(lhs).toXML( cout );
}
if( ! rightRoot ){
std::cout << "NORIGHT" << std::endl;
const_cast<RegExp&>(rhs).toXML( cout );
}
return compare( leftRoot, rightRoot ) == -1; return compare( leftRoot, rightRoot ) == -1;
} }
   
...@@ -62,28 +53,28 @@ int RegExpComparator::compare( RegExpElement * lhs, RegExpElement * rhs ) const ...@@ -62,28 +53,28 @@ int RegExpComparator::compare( RegExpElement * lhs, RegExpElement * rhs ) const
} }
else else
{ {
int leftOrder = 0, rightOrder = 0; NodeType leftNodeType = UNKNOWN, rightNodeType = UNKNOWN;
if( lhsAlt ) leftOrder = 1; if( lhsAlt ) leftNodeType = ALTERNATION;
if( lhsConcat ) leftOrder = 2; if( lhsConcat ) leftNodeType = CONCATENATION;
if( lhsIter ) leftOrder = 3; if( lhsIter ) leftNodeType = ITERATION;
if( lhsSymb ) leftOrder = 4; if( lhsSymb ) leftNodeType = SYMBOL;
if( lhsEmpty ) leftOrder = 5; if( lhsEmpty ) leftNodeType = EMPTY;
if( lhsEps ) leftOrder = 6; if( lhsEps ) leftNodeType = EPSILON;
if( rhsAlt ) rightOrder = 1; if( rhsAlt ) rightNodeType = ALTERNATION;
if( rhsConcat ) rightOrder = 2; if( rhsConcat ) rightNodeType = CONCATENATION;
if( rhsIter ) rightOrder = 3; if( rhsIter ) rightNodeType = ITERATION;
if( rhsSymb ) rightOrder = 4; if( rhsSymb ) rightNodeType = SYMBOL;
if( rhsEmpty ) rightOrder = 5; if( rhsEmpty ) rightNodeType = EMPTY;
if( rhsEps ) rightOrder = 6; if( rhsEps ) rightNodeType = EPSILON;
if ( leftOrder < rightOrder ) return -1; if ( leftNodeType < rightNodeType ) return -1;
if ( leftOrder > rightOrder ) return 1; if ( leftNodeType > rightNodeType ) return 1;
return 0; return 0;
} }
   
throw ConversionException( "such exception, many errors" ); throw ConversionException( "RegExpComparator::compare - Don't know how to compare subtrees." );
} }
   
int RegExpComparator::compare( Alternation * lhs, Alternation * rhs ) const int RegExpComparator::compare( Alternation * lhs, Alternation * rhs ) const
......
...@@ -39,6 +39,16 @@ private: ...@@ -39,6 +39,16 @@ private:
int compare( regexp::RegExpSymbol * lhs, regexp::RegExpSymbol * rhs ) const; int compare( regexp::RegExpSymbol * lhs, regexp::RegExpSymbol * rhs ) const;
int compare( regexp::RegExpEmpty * lhs, regexp::RegExpEmpty * rhs ) const; int compare( regexp::RegExpEmpty * lhs, regexp::RegExpEmpty * rhs ) const;
int compare( regexp::RegExpEpsilon * lhs, regexp::RegExpEpsilon * rhs ) const; int compare( regexp::RegExpEpsilon * lhs, regexp::RegExpEpsilon * rhs ) const;
enum NodeType {
UNKNOWN = 0,
ALTERNATION = 1,
CONCATENATION = 2,
ITERATION = 3,
SYMBOL = 4,
EMPTY = 5,
EPSILON = 6
};
}; };
   
} /* namespace conversions */ } /* namespace conversions */
......
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