From a7ecb1d602f6cc83a9685d85c369294c8e93d888 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Thu, 27 Feb 2014 13:00:44 +0100 Subject: [PATCH] Revert "implementation of y + x = x + y transformation" This reverts commit 832a57e717cb56e7616889290bd8d65713ab460f. Conflicts: aconversions/src/re2fa/Brzozowski.cpp libaregexptree/src/RegExpOptimize.cpp --- aconversions/src/re2fa/Brzozowski.cpp | 2 +- aconvert.regexp/src/RegExpParser.cpp | 33 ++++++++++++++----------- aconvert.regexp/src/RegExpParser.h | 4 +-- aderivation/src/aderivation.cpp | 2 +- aintegral/src/aintegral.cpp | 2 +- alib/src/RegExpFactory.h | 2 -- alib/src/regexp/Alternation.cpp | 4 +-- alib/src/regexp/Alternation.h | 8 +++--- alib/src/regexp/Concatenation.cpp | 4 +-- alib/src/regexp/Concatenation.h | 8 +++--- alib/src/regexp/Iteration.h | 1 + alib/src/regexp/RegExp.cpp | 2 ++ alib/src/regexp/RegExp.h | 5 ++-- alib/src/regexp/RegExpParser.cpp | 2 +- alib/src/regexp/RegExpParser.h | 4 +-- alib/src/regexp/RegExpPrinter.cpp | 2 +- alib/src/regexp/RegExpPrinter.h | 2 +- libaderivation/src/RegExpDerivation.cpp | 2 +- libaderivation/src/RegExpDerivation.h | 2 +- libaderivation/src/RegExpIntegral.cpp | 2 +- libaderivation/src/RegExpIntegral.h | 2 +- libaregexptree/src/RegExpOptimize.cpp | 4 +-- 22 files changed, 50 insertions(+), 49 deletions(-) diff --git a/aconversions/src/re2fa/Brzozowski.cpp b/aconversions/src/re2fa/Brzozowski.cpp index 1f941f750f..6736176ac6 100644 --- a/aconversions/src/re2fa/Brzozowski.cpp +++ b/aconversions/src/re2fa/Brzozowski.cpp @@ -42,7 +42,7 @@ FSM Brzozowski::convert( void ) for( const auto & symbol : alphabet ) { RegExpElement* dSymbol = new RegExpSymbol( symbol.getSymbol( ) ); - RegExp derived = deriv.derivation( vector<RegExpElement*>( 1, dSymbol ) ); + RegExp derived = deriv.derivation( list<RegExpElement*>( 1, dSymbol ) ); derived = opt.optimize( derived ); if( ! isInSet( derived, Q ) ) // if this state has already been found, do not add diff --git a/aconvert.regexp/src/RegExpParser.cpp b/aconvert.regexp/src/RegExpParser.cpp index 8ba459c5c1..cf070c07a5 100644 --- a/aconvert.regexp/src/RegExpParser.cpp +++ b/aconvert.regexp/src/RegExpParser.cpp @@ -19,23 +19,25 @@ regexp::RegExpElement* RegExpParser::AlternationCont(regexp::RegExpElement* left RegExpLexer::Token token = m_Lexer.token(); if(token.type == RegExpLexer::PLUS) { m_Lexer.next(); - regexp::Alternation* res = new regexp::Alternation(); - res->getElements().push_back(left); - this->AlternationContCont(res, this->Concatenation()); + regexp::Alternation* res = this->AlternationContCont(this->Concatenation()); + res->getElements().push_front(left); return res; } else { return left; } } -void RegExpParser::AlternationContCont(regexp::Alternation* res, regexp::RegExpElement* left) { +regexp::Alternation* RegExpParser::AlternationContCont(regexp::RegExpElement* left) { RegExpLexer::Token token = m_Lexer.token(); if(token.type == RegExpLexer::PLUS) { m_Lexer.next(); - res->getElements().push_back(left); - this->AlternationContCont(res, this->Concatenation()); + regexp::Alternation* res = this->AlternationContCont(this->Concatenation()); + res->getElements().push_front(left); + return res; } else { - res->getElements().push_back(left); + regexp::Alternation* res = new regexp::Alternation(); + res->getElements().push_front(left); + return res; } } @@ -48,24 +50,25 @@ regexp::RegExpElement* RegExpParser::ConcatenationCont(regexp::RegExpElement* le RegExpLexer::Token token = m_Lexer.token(); if(token.type == RegExpLexer::SYMBOL || token.type == RegExpLexer::LPAR || token.type == RegExpLexer::EPS || token.type == RegExpLexer::EMPTY) { - regexp::Concatenation* res = new regexp::Concatenation(); - res->getElements().push_back(left); - this->ConcatenationContCont(res, this->Factor()); + regexp::Concatenation* res = this->ConcatenationContCont(this->Factor()); + res->getElements().push_front(left); return res; } else { return left; } } -void RegExpParser::ConcatenationContCont(regexp::Concatenation* res, regexp::RegExpElement* left) { +regexp::Concatenation* RegExpParser::ConcatenationContCont(regexp::RegExpElement* left) { RegExpLexer::Token token = m_Lexer.token(); if(token.type == RegExpLexer::SYMBOL || token.type == RegExpLexer::LPAR || token.type == RegExpLexer::EPS || token.type == RegExpLexer::EMPTY) { - res->getElements().push_back(left); - this->ConcatenationContCont(res, this->Factor()); + regexp::Concatenation* res = this->ConcatenationContCont(this->Factor()); + res->getElements().push_front(left); + return res; } else { - - res->getElements().push_back(left); + regexp::Concatenation* res = new regexp::Concatenation(); + res->getElements().push_front(left); + return res; } } diff --git a/aconvert.regexp/src/RegExpParser.h b/aconvert.regexp/src/RegExpParser.h index 0177ccaaaa..37e161181e 100644 --- a/aconvert.regexp/src/RegExpParser.h +++ b/aconvert.regexp/src/RegExpParser.h @@ -26,11 +26,11 @@ public: private: regexp::RegExpElement* Alternation(); regexp::RegExpElement* AlternationCont(regexp::RegExpElement* left); - void AlternationContCont(regexp::Alternation* res, regexp::RegExpElement* left); + regexp::Alternation* AlternationContCont(regexp::RegExpElement* left); regexp::RegExpElement* Concatenation(); regexp::RegExpElement* ConcatenationCont(regexp::RegExpElement* left); - void ConcatenationContCont(regexp::Concatenation* res, regexp::RegExpElement* left); + regexp::Concatenation* ConcatenationContCont(regexp::RegExpElement* left); regexp::RegExpElement* Factor(); regexp::RegExpElement* Star(regexp::RegExpElement* elem); diff --git a/aderivation/src/aderivation.cpp b/aderivation/src/aderivation.cpp index 972a1f702f..018c8da654 100644 --- a/aderivation/src/aderivation.cpp +++ b/aderivation/src/aderivation.cpp @@ -27,7 +27,7 @@ int main(int argc, char** argv) SaxInterface::parseMemory(input, tokens); RegExp re = RegExpParser::parse(tokens); - vector<RegExpElement*> dString; + list<RegExpElement*> dString; for( int i = 1; i < argc ; i++ ) { string symbol( argv[ i ] ); diff --git a/aintegral/src/aintegral.cpp b/aintegral/src/aintegral.cpp index d460ab967e..c5599a0a94 100644 --- a/aintegral/src/aintegral.cpp +++ b/aintegral/src/aintegral.cpp @@ -27,7 +27,7 @@ int main(int argc, char** argv) SaxInterface::parseMemory(input, tokens); RegExp re = RegExpParser::parse(tokens); - vector<RegExpElement*> dString; + list<RegExpElement*> dString; for( int i = 1; i < argc ; i++ ) { string symbol( argv[ i ] ); diff --git a/alib/src/RegExpFactory.h b/alib/src/RegExpFactory.h index de6d8f6430..510ddddc1d 100644 --- a/alib/src/RegExpFactory.h +++ b/alib/src/RegExpFactory.h @@ -8,8 +8,6 @@ #ifndef REGEXPFACTORY_H_ #define REGEXPFACTORY_H_ -#include <list> - #include "sax/Token.h" #include "regexp/RegExp.h" diff --git a/alib/src/regexp/Alternation.cpp b/alib/src/regexp/Alternation.cpp index 2bd801d82e..1c557224ef 100644 --- a/alib/src/regexp/Alternation.cpp +++ b/alib/src/regexp/Alternation.cpp @@ -42,11 +42,11 @@ Alternation::~Alternation() { elements.clear(); } -vector<RegExpElement*>& Alternation::getElements() { +list<RegExpElement*>& Alternation::getElements() { return elements; } -const vector<RegExpElement*>& Alternation::getElements() const { +const list<RegExpElement*>& Alternation::getElements() const { return elements; } diff --git a/alib/src/regexp/Alternation.h b/alib/src/regexp/Alternation.h index 3ce18a9049..52b8f8c184 100644 --- a/alib/src/regexp/Alternation.h +++ b/alib/src/regexp/Alternation.h @@ -8,7 +8,7 @@ #ifndef ALTERNATION_H_ #define ALTERNATION_H_ -#include <vector> +#include <list> #include "RegExpElement.h" namespace regexp { @@ -21,7 +21,7 @@ using namespace std; */ class Alternation: public RegExpElement { private: - vector<RegExpElement*> elements; + list<RegExpElement*> elements; public: Alternation(); Alternation(const Alternation& other); @@ -31,12 +31,12 @@ public: /** * @return list of operands */ - vector<RegExpElement*>& getElements(); + list<RegExpElement*>& getElements(); /** * @return list of operands */ - const vector<RegExpElement*>& getElements() const; + const list<RegExpElement*>& getElements() const; /** * @copydoc RegExpElement::clone() const diff --git a/alib/src/regexp/Concatenation.cpp b/alib/src/regexp/Concatenation.cpp index 0387d454fb..c43e767dfd 100644 --- a/alib/src/regexp/Concatenation.cpp +++ b/alib/src/regexp/Concatenation.cpp @@ -42,11 +42,11 @@ Concatenation::~Concatenation() { elements.clear(); } -vector<RegExpElement*>& Concatenation::getElements() { +list<RegExpElement*>& Concatenation::getElements() { return elements; } -const vector<RegExpElement*>& Concatenation::getElements() const { +const list<RegExpElement*>& Concatenation::getElements() const { return elements; } diff --git a/alib/src/regexp/Concatenation.h b/alib/src/regexp/Concatenation.h index 2e4713875f..9fead277d3 100644 --- a/alib/src/regexp/Concatenation.h +++ b/alib/src/regexp/Concatenation.h @@ -8,7 +8,7 @@ #ifndef CONCATENATION_H_ #define CONCATENATION_H_ -#include <vector> +#include <list> #include "RegExpElement.h" namespace regexp { @@ -21,7 +21,7 @@ using namespace std; */ class Concatenation: public RegExpElement { private: - vector<RegExpElement*> elements; + list<RegExpElement*> elements; public: Concatenation(); Concatenation(const Concatenation& other); @@ -31,12 +31,12 @@ public: /** * @return list of operands */ - vector<RegExpElement*>& getElements(); + list<RegExpElement*>& getElements(); /** * @return list of operands */ - const vector<RegExpElement*>& getElements() const; + const list<RegExpElement*>& getElements() const; /** * @copydoc RegExpElement::clone() const diff --git a/alib/src/regexp/Iteration.h b/alib/src/regexp/Iteration.h index 4bca308eab..7466b2aedc 100644 --- a/alib/src/regexp/Iteration.h +++ b/alib/src/regexp/Iteration.h @@ -8,6 +8,7 @@ #ifndef ITERATION_H_ #define ITERATION_H_ +#include <list> #include "RegExpElement.h" namespace regexp { diff --git a/alib/src/regexp/RegExp.cpp b/alib/src/regexp/RegExp.cpp index 27afc0cb91..621b004152 100644 --- a/alib/src/regexp/RegExp.cpp +++ b/alib/src/regexp/RegExp.cpp @@ -8,6 +8,8 @@ #include "RegExp.h" #include "RegExpPrinter.h" +#include <iostream> + namespace regexp { RegExp::RegExp() { diff --git a/alib/src/regexp/RegExp.h b/alib/src/regexp/RegExp.h index ef21bad4b5..f16133cc5f 100644 --- a/alib/src/regexp/RegExp.h +++ b/alib/src/regexp/RegExp.h @@ -8,8 +8,9 @@ #ifndef REGEXP_H_ #define REGEXP_H_ -#include <iostream> - +#include <vector> +#include <list> +#include <string> #include "RegExpElement.h" #include "RegExpEmpty.h" diff --git a/alib/src/regexp/RegExpParser.cpp b/alib/src/regexp/RegExpParser.cpp index 81d52a3987..5bcad37145 100644 --- a/alib/src/regexp/RegExpParser.cpp +++ b/alib/src/regexp/RegExpParser.cpp @@ -68,7 +68,7 @@ Iteration* RegExpParser::parseIteration(list<Token>& input) { return iteration; } -void RegExpParser::parseContent(list<Token>& input, vector<RegExpElement*>& elements) { +void RegExpParser::parseContent(list<Token>& input, list<RegExpElement*>& elements) { while (true) { RegExpElement* element = parseElement(input); if(!element) return; diff --git a/alib/src/regexp/RegExpParser.h b/alib/src/regexp/RegExpParser.h index 808ad17d24..126f20ee5d 100644 --- a/alib/src/regexp/RegExpParser.h +++ b/alib/src/regexp/RegExpParser.h @@ -8,8 +8,6 @@ #ifndef REGEXPPARSER_H_ #define REGEXPPARSER_H_ -#include <list> - #include "RegExp.h" #include "../sax/Token.h" #include "RegExpSymbol.h" @@ -29,7 +27,7 @@ using namespace sax; */ class RegExpParser { protected: - static void parseContent(list<Token>& input, vector<RegExpElement*>& elements); + static void parseContent(list<Token>& input, list<RegExpElement*>& elements); static RegExpElement* parseElement(list<Token>& input); static RegExpEpsilon* parseEpsilon(list<Token>& input); diff --git a/alib/src/regexp/RegExpPrinter.cpp b/alib/src/regexp/RegExpPrinter.cpp index f3757b3025..223ab54691 100644 --- a/alib/src/regexp/RegExpPrinter.cpp +++ b/alib/src/regexp/RegExpPrinter.cpp @@ -56,7 +56,7 @@ void RegExpPrinter::printElement(RegExpElement* element, ostream& out, string pr } -void RegExpPrinter::printContent(vector<RegExpElement*>& content, ostream& out, string prefix) { +void RegExpPrinter::printContent(list<RegExpElement*>& content, ostream& out, string prefix) { for (auto element : content) { printElement(element, out, prefix); } diff --git a/alib/src/regexp/RegExpPrinter.h b/alib/src/regexp/RegExpPrinter.h index 33c21f8da4..49ba46d027 100644 --- a/alib/src/regexp/RegExpPrinter.h +++ b/alib/src/regexp/RegExpPrinter.h @@ -28,7 +28,7 @@ class RegExpPrinter { protected: static const string INDENTATION; static void printElement(RegExpElement* element, ostream& out, string prefix); - static void printContent(vector<RegExpElement*>& content, ostream& out, string prefix); + static void printContent(list<RegExpElement*>& content, ostream& out, string prefix); static void printAlternation(Alternation* alternation, ostream& out, string prefix); static void printConcatenation(Concatenation* concatenation, ostream& out, string prefix); diff --git a/libaderivation/src/RegExpDerivation.cpp b/libaderivation/src/RegExpDerivation.cpp index 2e3aca7c21..54d5b04c60 100644 --- a/libaderivation/src/RegExpDerivation.cpp +++ b/libaderivation/src/RegExpDerivation.cpp @@ -16,7 +16,7 @@ RegExpDerivation::RegExpDerivation( const RegExp & re ) : m_re( re ) } -RegExp RegExpDerivation::derivation ( const vector<RegExpElement*> & dString ) const +RegExp RegExpDerivation::derivation ( const list<RegExpElement*> & dString ) const { const RegExpElement * oldRegExp = m_re.getRegExp( )->clone( ), * derivedRegExp; diff --git a/libaderivation/src/RegExpDerivation.h b/libaderivation/src/RegExpDerivation.h index d733773cb2..e840bfd4e2 100644 --- a/libaderivation/src/RegExpDerivation.h +++ b/libaderivation/src/RegExpDerivation.h @@ -33,7 +33,7 @@ class RegExpDerivation { public: RegExpDerivation( const regexp::RegExp & re ); - regexp::RegExp derivation( const std::vector<regexp::RegExpElement*> & dString ) const; + regexp::RegExp derivation( const std::list<regexp::RegExpElement*> & dString ) const; private: regexp::RegExpElement * derivation( const regexp::RegExpElement * element, const regexp::RegExpSymbol & dSymbol ) const; diff --git a/libaderivation/src/RegExpIntegral.cpp b/libaderivation/src/RegExpIntegral.cpp index 25b8ce5b79..edbd68cfbf 100644 --- a/libaderivation/src/RegExpIntegral.cpp +++ b/libaderivation/src/RegExpIntegral.cpp @@ -15,7 +15,7 @@ RegExpIntegral::RegExpIntegral( const RegExp & re ) : m_re( re ) } -RegExp RegExpIntegral::integral( const vector<RegExpElement*> & dString ) const +RegExp RegExpIntegral::integral( const list<RegExpElement*> & dString ) const { const RegExpElement * oldRegExp = m_re.getRegExp( )->clone( ), * integralRegExp; diff --git a/libaderivation/src/RegExpIntegral.h b/libaderivation/src/RegExpIntegral.h index cbc3a01084..4e0b2b549d 100644 --- a/libaderivation/src/RegExpIntegral.h +++ b/libaderivation/src/RegExpIntegral.h @@ -22,7 +22,7 @@ class RegExpIntegral { public: RegExpIntegral( const regexp::RegExp & re ); - regexp::RegExp integral( const std::vector<regexp::RegExpElement*> & dString ) const; + regexp::RegExp integral( const std::list<regexp::RegExpElement*> & dString ) const; private: regexp::RegExpElement * integral( const regexp::RegExpElement * node, const regexp::RegExpSymbol & dSymbol ) const; diff --git a/libaregexptree/src/RegExpOptimize.cpp b/libaregexptree/src/RegExpOptimize.cpp index 8755564551..36ea5c56ea 100644 --- a/libaregexptree/src/RegExpOptimize.cpp +++ b/libaregexptree/src/RegExpOptimize.cpp @@ -6,7 +6,6 @@ */ #include "RegExpOptimize.h" -#include <algorithm> using namespace alib; using namespace regexp; @@ -74,8 +73,7 @@ RegExpElement * RegExpOptimize::optimize( const Alternation * node ) } // A2: x + y = y + x - - std::sort (alt->getElements( ).begin( ), alt->getElements( ).end( ), [](RegExpElement const * const & a, RegExpElement const * const & b) -> bool { + alt->getElements().sort([](RegExpElement const * const & a, RegExpElement const * const & b) -> bool { return *a < *b; }); -- GitLab