Skip to content
Snippets Groups Projects
Commit d6ba871f authored by Jan Trávníček's avatar Jan Trávníček Committed by Tomáš Pecka
Browse files

fix for issue 12

parent 1ba3bc01
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
   
#include "Brzozowski.h" #include "Brzozowski.h"
#include <iostream>
   
using namespace alib; using namespace alib;
using namespace automaton; using namespace automaton;
...@@ -68,10 +69,7 @@ FSM Brzozowski::convert( void ) ...@@ -68,10 +69,7 @@ FSM Brzozowski::convert( void )
} }
} }
   
// FIXME sometimes crashes upon regexp comparsion - ?? issue #22 Q.insert( Qi.at( i ).begin( ), Qi.at( i ).end( ) );
// Q.insert( Qi.at( i ).begin( ), Qi.at( i ).end( ) );
for( const auto & r : Qi.at( i ) )
Q.insert( r );
   
i += 1; i += 1;
} }
...@@ -129,11 +127,9 @@ Brzozowski::StateBuilder::StateBuilder( const set<RegExp> & Q ) ...@@ -129,11 +127,9 @@ Brzozowski::StateBuilder::StateBuilder( const set<RegExp> & Q )
   
const State & Brzozowski::StateBuilder::getState( const RegExp & re ) const const State & Brzozowski::StateBuilder::getState( const RegExp & re ) const
{ {
// FIXME map::find() does not work! see gitlab issue #12 auto state = m_states.find( re );
for( const auto & kv : m_states ) if( state != m_states.end() ) return state->second;
if( kv.first == re )
return kv.second;
throw AlibException( "Brzozowski::StateBuilder - Regular expression not found!" ); throw AlibException( "Brzozowski::StateBuilder - Regular expression not found!" );
} }
   
......
...@@ -80,10 +80,11 @@ bool Alternation::operator<(const Alternation& other) const { ...@@ -80,10 +80,11 @@ bool Alternation::operator<(const Alternation& other) const {
auto thisIter = this->elements.begin(); auto thisIter = this->elements.begin();
auto otherIter = other.elements.begin(); auto otherIter = other.elements.begin();
for(; thisIter != this->elements.end(); thisIter++, otherIter++) { for(; thisIter != this->elements.end(); thisIter++, otherIter++) {
if(**thisIter < **otherIter) return true; if(**thisIter != **otherIter) break;
} }
if(thisIter == this->elements.end()) return false;
   
return false; return **thisIter < **otherIter;
} }
   
bool Alternation::operator==(const Alternation& other) const { bool Alternation::operator==(const Alternation& other) const {
...@@ -103,7 +104,7 @@ bool Alternation::containsEmptyString() const { ...@@ -103,7 +104,7 @@ bool Alternation::containsEmptyString() const {
if(e->containsEmptyString()) if(e->containsEmptyString())
return true; return true;
   
return false; return false; // alternation of zero regexps is empty
} }
   
bool Alternation::isEmpty() const { bool Alternation::isEmpty() const {
...@@ -111,7 +112,7 @@ bool Alternation::isEmpty() const { ...@@ -111,7 +112,7 @@ bool Alternation::isEmpty() const {
if(!e->isEmpty()) if(!e->isEmpty())
return false; return false;
   
return true; return true; // alternation of zero regexps is empty
} }
   
} /* namespace regexp */ } /* namespace regexp */
......
...@@ -76,10 +76,11 @@ bool Concatenation::operator<(const Concatenation& other) const { ...@@ -76,10 +76,11 @@ bool Concatenation::operator<(const Concatenation& other) const {
auto thisIter = this->elements.begin(); auto thisIter = this->elements.begin();
auto otherIter = other.elements.begin(); auto otherIter = other.elements.begin();
for(; thisIter != this->elements.end(); thisIter++, otherIter++) { for(; thisIter != this->elements.end(); thisIter++, otherIter++) {
if(**thisIter < **otherIter) return true; if(**thisIter != **otherIter) break;
} }
if(thisIter == this->elements.end()) return false;
   
return false; return **thisIter < **otherIter;
} }
   
bool Concatenation::operator==(const Concatenation& other) const { bool Concatenation::operator==(const Concatenation& other) const {
...@@ -99,7 +100,7 @@ bool Concatenation::containsEmptyString() const { ...@@ -99,7 +100,7 @@ bool Concatenation::containsEmptyString() const {
if( ! e->containsEmptyString()) if( ! e->containsEmptyString())
return false; return false;
   
return true; return true; // concatenation of zero regexps is epsilon
} }
   
bool Concatenation::isEmpty() const { bool Concatenation::isEmpty() const {
...@@ -107,7 +108,7 @@ bool Concatenation::isEmpty() const { ...@@ -107,7 +108,7 @@ bool Concatenation::isEmpty() const {
if(e->isEmpty()) if(e->isEmpty())
return true; return true;
   
return false; return false; // concatenation of zero regexps is epsilon
} }
   
} /* namespace regexp */ } /* namespace regexp */
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