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

RegExp::isEmpty is now correct if called on unoptimized regexp. closes #15

parent ec4db700
No related branches found
No related tags found
No related merge requests found
...@@ -106,5 +106,13 @@ bool Alternation::containsEmptyString() const { ...@@ -106,5 +106,13 @@ bool Alternation::containsEmptyString() const {
return false; return false;
} }
   
bool Alternation::isEmpty() const {
for(const auto& e : getElements())
if(!e->isEmpty())
return true;
return false;
}
} /* namespace regexp */ } /* namespace regexp */
   
...@@ -55,6 +55,11 @@ public: ...@@ -55,6 +55,11 @@ public:
* @copydoc RegExpElement::containsEmptyString() const * @copydoc RegExpElement::containsEmptyString() const
*/ */
bool containsEmptyString() const; bool containsEmptyString() const;
/**
* @copydoc RegExpElement::isEmpty() const
*/
bool isEmpty() const;
}; };
   
} /* namespace regexp */ } /* namespace regexp */
......
...@@ -95,11 +95,19 @@ bool Concatenation::operator==(const Concatenation& other) const { ...@@ -95,11 +95,19 @@ bool Concatenation::operator==(const Concatenation& other) const {
} }
   
bool Concatenation::containsEmptyString() const { bool Concatenation::containsEmptyString() const {
for( const auto& e : getElements()) for(const auto& e : getElements())
if( ! e->containsEmptyString()) if( ! e->containsEmptyString())
return false; return false;
   
return true; return true;
} }
   
bool Concatenation::isEmpty() const {
for(const auto& e : getElements())
if(!e->isEmpty())
return false;
return true;
}
} /* namespace regexp */ } /* namespace regexp */
...@@ -54,6 +54,11 @@ public: ...@@ -54,6 +54,11 @@ public:
* @copydoc RegExpElement::containsEmptyString() const * @copydoc RegExpElement::containsEmptyString() const
*/ */
bool containsEmptyString() const; bool containsEmptyString() const;
/**
* @copydoc RegExpElement::isEmpty() const
*/
bool isEmpty() const;
}; };
   
} /* namespace regexp */ } /* namespace regexp */
......
...@@ -97,5 +97,9 @@ bool Iteration::containsEmptyString() const { ...@@ -97,5 +97,9 @@ bool Iteration::containsEmptyString() const {
return true; return true;
} }
   
bool Iteration::isEmpty() const {
return false;
}
} /* namespace regexp */ } /* namespace regexp */
   
...@@ -62,6 +62,11 @@ public: ...@@ -62,6 +62,11 @@ public:
* @copydoc RegExpElement::containsEmptyString() const * @copydoc RegExpElement::containsEmptyString() const
*/ */
bool containsEmptyString() const; bool containsEmptyString() const;
/**
* @copydoc RegExpElement::isEmpty() const
*/
bool isEmpty() const;
}; };
   
} /* namespace regexp */ } /* namespace regexp */
......
...@@ -71,7 +71,7 @@ void RegExp::setRegExp(RegExpElement* regExp) { ...@@ -71,7 +71,7 @@ void RegExp::setRegExp(RegExpElement* regExp) {
} }
   
bool RegExp::isEmpty() const { bool RegExp::isEmpty() const {
return regExp == NULL || dynamic_cast<const RegExpEmpty*>(regExp); return regExp == NULL || regExp->isEmpty();
} }
   
bool RegExp::containsEmptyString() const { bool RegExp::containsEmptyString() const {
......
...@@ -59,6 +59,11 @@ public: ...@@ -59,6 +59,11 @@ public:
* @return true if this subtree of regexp matches empty string (epsilon) * @return true if this subtree of regexp matches empty string (epsilon)
*/ */
virtual bool containsEmptyString() const = 0; virtual bool containsEmptyString() const = 0;
/**
* @return true if this subtree describes empty language
*/
virtual bool isEmpty() const = 0;
}; };
   
} /* namespace regexp */ } /* namespace regexp */
......
...@@ -57,5 +57,9 @@ bool RegExpEmpty::containsEmptyString() const { ...@@ -57,5 +57,9 @@ bool RegExpEmpty::containsEmptyString() const {
return false; return false;
} }
   
bool RegExpEmpty::isEmpty() const {
return true;
}
} /* namespace regexp */ } /* namespace regexp */
   
...@@ -41,6 +41,11 @@ public: ...@@ -41,6 +41,11 @@ public:
* @copydoc RegExpElement::containsEmptyString() const * @copydoc RegExpElement::containsEmptyString() const
*/ */
bool containsEmptyString() const; bool containsEmptyString() const;
/**
* @copydoc RegExpElement::isEmpty() const
*/
bool isEmpty() const;
}; };
   
} /* namespace regexp */ } /* namespace regexp */
......
...@@ -53,5 +53,9 @@ bool RegExpEpsilon::containsEmptyString() const { ...@@ -53,5 +53,9 @@ bool RegExpEpsilon::containsEmptyString() const {
return true; return true;
} }
   
bool RegExpEpsilon::isEmpty() const {
return false;
}
} /* namespace regexp */ } /* namespace regexp */
   
...@@ -42,6 +42,11 @@ public: ...@@ -42,6 +42,11 @@ public:
* @copydoc RegExpElement::containsEmptyString() const * @copydoc RegExpElement::containsEmptyString() const
*/ */
bool containsEmptyString() const; bool containsEmptyString() const;
/**
* @copydoc RegExpElement::isEmpty() const
*/
bool isEmpty() const;
}; };
   
} /* namespace regexp */ } /* namespace regexp */
......
...@@ -58,6 +58,10 @@ bool RegExpSymbol::containsEmptyString() const { ...@@ -58,6 +58,10 @@ bool RegExpSymbol::containsEmptyString() const {
return false; return false;
} }
   
bool RegExpSymbol::isEmpty() const {
return false;
}
const string& RegExpSymbol::getSymbol() const { const string& RegExpSymbol::getSymbol() const {
return this->symbol; return this->symbol;
} }
......
...@@ -46,8 +46,13 @@ public: ...@@ -46,8 +46,13 @@ public:
* @copydoc RegExpElement::containsEmptyString() const * @copydoc RegExpElement::containsEmptyString() const
*/ */
bool containsEmptyString() const; bool containsEmptyString() const;
const string& getSymbol() const; const string& getSymbol() const;
/**
* @copydoc RegExpElement::isEmpty() const
*/
bool isEmpty() const;
}; };
   
} /* 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