diff --git a/aconversions2/src/ConversionHandler.cpp b/aconversions2/src/ConversionHandler.cpp index 151baa083df70440edda966e9ade15aee8f92697..d97f20a16e52bacb6f07540badb3b85b1f17bb32 100644 --- a/aconversions2/src/ConversionHandler.cpp +++ b/aconversions2/src/ConversionHandler.cpp @@ -7,6 +7,29 @@ #include "ConversionHandler.h" +//#include "conversions/fa2re/StateElimination.h" +#include "conversions/fa2re/BrzozowskiAlgebraic.h" + +#include "conversions/re2fa/Glushkov.h" +//#include "conversions/re2fa/Thompson.h" +//#include "conversions/re2fa/Brzozowski.h" + +//#include "conversions/fa2rg/fa2lrg/FAtoLRGConverter.h" +//#include "conversions/fa2rg/fa2rrg/FAtoRRGConverter.h" + +//#include "conversions/rg2fa/lrg2fa/LRGtoFAConverter.h" +//#include "conversions/rg2fa/rrg2fa/RRGtoFAConverter.h" + +//#include "conversions/rg2re/rrg2re/RRGAlgebraic.h" +//#include "conversions/rg2re/lrg2re/LRGAlgebraic.h" + +//#include "conversions/re2rg/re2rrg/GlushkovRRG.h" +//#include "conversions/re2rg/re2rrg/BrzozowskiDerivationRRG.h" + +#include "conversions/rg2rg/lrg2rrg/LeftToRightRegularGrammar.h" +#include "conversions/rg2rg/rrg2lrg/RightToLeftRegularGrammar.h" + + using namespace alib; using namespace automaton; using namespace grammar; diff --git a/aconversions2/src/ConversionHandler.h b/aconversions2/src/ConversionHandler.h index 321ca7e15bc8bc10e9734bfaef7d4a2bc4a425dc..8c1a38375483c5673208172eb2a78e1263e192f9 100644 --- a/aconversions2/src/ConversionHandler.h +++ b/aconversions2/src/ConversionHandler.h @@ -13,28 +13,6 @@ #include <exception/AlibException.h> #include <factory/DataFactory.hpp> -// #include "fa2re/StateElimination.h" -#include "fa2re/BrzozowskiAlgebraic.h" - -#include "re2fa/Glushkov.h" -//#include "re2fa/Thompson.h" -//#include "re2fa/Brzozowski.h" - -//#include "fa2rg/fa2lrg/FAtoLRGConverter.h" -//#include "fa2rg/fa2rrg/FAtoRRGConverter.h" - -//#include "rg2fa/lrg2fa/LRGtoFAConverter.h" -//#include "rg2fa/rrg2fa/RRGtoFAConverter.h" - -//#include "rg2re/rrg2re/RRGAlgebraic.h" -//#include "rg2re/lrg2re/LRGAlgebraic.h" - -//#include "re2rg/re2rrg/GlushkovRRG.h" -//#include "re2rg/re2rrg/BrzozowskiDerivationRRG.h" - -#include "rg2rg/lrg2rrg/LeftToRightRegularGrammar.h" -#include "rg2rg/rrg2lrg/RightToLeftRegularGrammar.h" - namespace conversions { diff --git a/aderivation/makefile b/aderivation/makefile deleted file mode 100644 index a5a5a3d7e843d2bb6d79246ef39454ef3c63a750..0000000000000000000000000000000000000000 --- a/aderivation/makefile +++ /dev/null @@ -1,20 +0,0 @@ -CC=g++ -EXECUTABLE=aderivation -CCFLAGS= -std=c++11 -O2 -c -Wall -I/usr/include/libxml2 -I../alib/src -I../libaregexptree/src -LDFLAGS= -L../alib/lib -L../libaregexptree/lib -lxml2 -lalib -laregexptree -Wl,-rpath,. - -SOURCES=$(shell find src/ -name *cpp) -OBJECTS=$(patsubst src/%.cpp, obj/%.o, $(SOURCES)) - -all: $(SOURCES) bin/$(EXECUTABLE) - -bin/$(EXECUTABLE): $(OBJECTS) - mkdir -p bin - $(CC) $(OBJECTS) -o $@ $(LDFLAGS) - -obj/%.o: src/%.cpp - mkdir -p $(dir $@) - $(CC) $(CCFLAGS) $< -o $@ - -clean: - $(RM) -r *.o *.d bin obj diff --git a/aderivation/src/aderivation.cpp b/aderivation/src/aderivation.cpp deleted file mode 100644 index 27d31b2084799a943d7757d631a5e407f6d2e0bf..0000000000000000000000000000000000000000 --- a/aderivation/src/aderivation.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include <iostream> -#include <cstring> - - -#include <AlibException.h> -#include <regexp/RegExp.h> -#include <regexp/RegExpParser.h> -#include <regexp/RegExpSymbol.h> -#include <sax/SaxInterface.h> - -#include "RegExpDerivation.h" - - -using namespace alib; -using namespace regexp; -using namespace std; - -void help( void ) -{ - cout << "aderivation 0.01" << endl; - cout << "Returns derivation of regexp over given string of symbols." << endl; - cout << "Usage: aintegral SYMBOL-1 SYMBOL-2 ... SYMBOL-n" << endl; -} - -int main(int argc, char** argv) -{ - for( int i = 0; i < argc; i++ ) - { - if( strcmp( argv[ i ], "--help" ) == 0 || strcmp( argv[ i ], "-h" ) == 0 ) - { - help( ); - return 0; - } - } - - try - { - list<Token> tokens; - string input(istreambuf_iterator<char>(cin), (istreambuf_iterator<char>())); - SaxInterface::parseMemory(input, tokens); - RegExp re = RegExpParser::parse(tokens); - - list<Symbol> dString; - for( int i = 1; i < argc ; i++ ) - { - string symbol( argv[ i ] ); - // cout << "'" << symbol << "'" << endl; - dString.push_back( Symbol( symbol ) ); - } - RegExpDerivation d( re ); - d.derivation( dString ).toXML( cout ); - } - catch( AlibException & e ) - { - cout << e.what() << endl; - return 1; - } - - return 0; -} diff --git a/aderivation2/makefile b/aderivation2/makefile new file mode 100644 index 0000000000000000000000000000000000000000..a9755f66eabe0c4afb30a30e72e8043d75deb064 --- /dev/null +++ b/aderivation2/makefile @@ -0,0 +1,73 @@ +SHELL:=/bin/bash +EXECUTABLE:=aderivation2 + +LDFLAGS= -L../alib2data/lib -L../alib2algo/lib -rdynamic -lxml2 -lalib2data -lalib2algo -Wl,-rpath,. + +OBJECTS:=$(patsubst src/%.cpp, obj/%.o, $(shell find src/ -name *cpp)) + +.PHONY: all build clean + +all: build + + + +bin/$(EXECUTABLE): obj/ $(OBJECTS) + mkdir -p bin + $(CXX) $(OBJECTS) -o $@ $(LDFLAGS) + +obj/makefile: makefile + mkdir -p $(dir $@) + echo "SHELL:=/bin/bash" >> $@ + echo "SRCDIR:=" >> $@ + echo "DEPTH:=" >> $@ + echo "" >> $@ + echo "CXXFLAGS:= -std=c++11 -Og -g -c -Wall -pedantic -Wextra -I../../\$$(DEPTH)alib2data/src/ -I../../\$$(DEPTH)alib2algo/src -I/usr/include/libxml2/" >> $@ + echo "" >> $@ + echo "SOURCES:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")" >> $@ + echo "DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)obj/\$$(SRCDIR)%.d, \$$(SOURCES))" >> $@ + echo "OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))" >> $@ + echo "SOURCES_DIRS:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)" >> $@ + echo "OBJECTS_DIRS:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))" >> $@ + echo "OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))" >> $@ + echo "" >> $@ + echo ".PHONY: all" >> $@ + echo ".PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)" >> $@ + echo "" >> $@ + echo "all: \$$(OBJECTS_DIRS) \$$(OBJECTS)" >> $@ + echo "" >> $@ + echo "%.d:" >> $@ + echo " @echo \"\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -MM \\$$\$$(CXXFLAGS) \$$(patsubst ../\$$(DEPTH)obj/\$$(SRCDIR)%.d,../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst ../\$$(DEPTH)obj/\$$(SRCDIR)%.d,../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\" >> \$$@" >> $@ + echo " @echo \"\$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\"))\" >> \$$@" >> $@ + echo " @echo \" \\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\" >> \$$@" >> $@ + echo "" >> $@ + echo "%/makefile:" >> $@ + echo " mkdir -p \$$(dir \$$@)" >> $@ + echo " cp makefile \$$@" >> $@ + echo "" >> $@ + echo "%/: FORCE | %/makefile" >> $@ + echo " @accesstime=\`stat -c %Y \$$@\` && \\" >> $@ + echo " \$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ DEPTH=\$$(DEPTH)../ && \\" >> $@ + echo " accesstime2=\`stat -c %Y \$$@\` && \\" >> $@ + echo " if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\" >> $@ + echo " touch .; \\" >> $@ + echo " fi" >> $@ + echo "" >> $@ + echo "FORCE:" >> $@ + echo "" >> $@ + echo "-include \$$(DEPENDENCIES)" >> $@ + +obj/: FORCE | obj/makefile + $(MAKE) -C $@ + +$(OBJECTS): obj/ + + +build: bin/$(EXECUTABLE) + + + +clean: + $(RM) -r *.o *.d bin lib obj test-bin test-obj + +FORCE: + diff --git a/aderivation2/src/aderivation.cpp b/aderivation2/src/aderivation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d10a18d796ce75c34c9c2d4d9773be6e2400ea6 --- /dev/null +++ b/aderivation2/src/aderivation.cpp @@ -0,0 +1,46 @@ +/* + * aintegral.cpp + * + * Created on: 19. 1. 2014 + * Author: Tomas Pecka + */ + +#include <iostream> + +#include <factory/DataFactory.hpp> +#include <exception/AlibException.h> + +#include "regexp/RegExpDerivation.h" + +int main(int argc, char** argv) +{ + try + { + if(argc == 2 && std::string("-h").compare(argv[1]) == 0) + { + std::cout << "aderivation. Derivates regular expression by given string." << std::endl; + std::cout << "Usage: aderivation regexp.xml string.xml" << std::endl; + return -1; + } + + if(argc == 3) + { + regexp::RegExp regexp = alib::DataFactory::fromFile<regexp::RegExp>(argv[1]); + string::LinearString* string = static_cast<string::LinearString*>(std::move(alib::DataFactory::fromFile<string::LinearString>(argv[2])).plunder()); + + RegExpDerivation derive; + alib::DataFactory::toStdout(derive.derivation(regexp, *string)); + + return 0; + } + } + catch(const exception::AlibException& exception) + { + alib::DataFactory::toStdout(exception); + return 1; + } + catch(...) + { + return 127; + } +} diff --git a/aintegral/makefile b/aintegral/makefile deleted file mode 100644 index d734d66fb68acc46ba3ee3910f19151122d5530e..0000000000000000000000000000000000000000 --- a/aintegral/makefile +++ /dev/null @@ -1,20 +0,0 @@ -CC=g++ -EXECUTABLE=aintegral -CCFLAGS= -std=c++11 -O2 -c -Wall -I/usr/include/libxml2 -I../alib/src -I../libaregexptree/src -LDFLAGS= -L../alib/lib -L../libaregexptree/lib -lxml2 -lalib -laregexptree -Wl,-rpath,. - -SOURCES=$(shell find src/ -name *cpp) -OBJECTS=$(patsubst src/%.cpp, obj/%.o, $(SOURCES)) - -all: $(SOURCES) bin/$(EXECUTABLE) - -bin/$(EXECUTABLE): $(OBJECTS) - mkdir -p bin - $(CC) $(OBJECTS) -o $@ $(LDFLAGS) - -obj/%.o: src/%.cpp - mkdir -p $(dir $@) - $(CC) $(CCFLAGS) $< -o $@ - -clean: - $(RM) -r *.o *.d bin obj diff --git a/aintegral/src/aintegral.cpp b/aintegral/src/aintegral.cpp deleted file mode 100644 index 45953f07502d01514720372a2b3d8649ca521e49..0000000000000000000000000000000000000000 --- a/aintegral/src/aintegral.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include <iostream> -#include <cstring> - -#include <AlibException.h> -#include <regexp/RegExp.h> -#include <regexp/RegExpParser.h> -#include <regexp/RegExpSymbol.h> -#include <sax/SaxInterface.h> - -#include "RegExpIntegral.h" - - -using namespace alib; -using namespace regexp; -using namespace std; - - - -void help( void ) -{ - cout << "aintegral 0.01" << endl; - cout << "Returns integral of regexp over given string of symbols." << endl; - cout << "Usage: aintegral SYMBOL-1 SYMBOL-2 ... SYMBOL-n" << endl; -} - -int main(int argc, char** argv) -{ - for( int i = 0; i < argc; i++ ) - { - if( strcmp( argv[ i ], "--help" ) == 0 || strcmp( argv[ i ], "-h" ) == 0 ) - { - help( ); - return 0; - } - } - - try - { - list<Token> tokens; - string input(istreambuf_iterator<char>(cin), (istreambuf_iterator<char>())); - SaxInterface::parseMemory(input, tokens); - RegExp re = RegExpParser::parse(tokens); - - list<Symbol> dString; - for( int i = 1; i < argc ; i++ ) - { - string symbol( argv[ i ] ); - // cout << "'" << symbol << "'" << endl; - dString.push_back( Symbol( symbol ) ); - } - RegExpIntegral i( re ); - i.integral( dString ).toXML( cout ); - } - catch( AlibException & e ) - { - cout << e.what() << endl; - return 1; - } - - return 0; -} diff --git a/aintegral2/makefile b/aintegral2/makefile new file mode 100644 index 0000000000000000000000000000000000000000..6d59646d2aeb5059c99cf6ed2f4a8dbea4018778 --- /dev/null +++ b/aintegral2/makefile @@ -0,0 +1,73 @@ +SHELL:=/bin/bash +EXECUTABLE:=aintegral2 + +LDFLAGS= -L../alib2data/lib -L../alib2algo/lib -rdynamic -lxml2 -lalib2data -lalib2algo -Wl,-rpath,. + +OBJECTS:=$(patsubst src/%.cpp, obj/%.o, $(shell find src/ -name *cpp)) + +.PHONY: all build clean + +all: build + + + +bin/$(EXECUTABLE): obj/ $(OBJECTS) + mkdir -p bin + $(CXX) $(OBJECTS) -o $@ $(LDFLAGS) + +obj/makefile: makefile + mkdir -p $(dir $@) + echo "SHELL:=/bin/bash" >> $@ + echo "SRCDIR:=" >> $@ + echo "DEPTH:=" >> $@ + echo "" >> $@ + echo "CXXFLAGS:= -std=c++11 -Og -g -c -Wall -pedantic -Wextra -I../../\$$(DEPTH)alib2data/src/ -I../../\$$(DEPTH)alib2algo/src -I/usr/include/libxml2/" >> $@ + echo "" >> $@ + echo "SOURCES:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")" >> $@ + echo "DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)obj/\$$(SRCDIR)%.d, \$$(SOURCES))" >> $@ + echo "OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))" >> $@ + echo "SOURCES_DIRS:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)" >> $@ + echo "OBJECTS_DIRS:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))" >> $@ + echo "OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))" >> $@ + echo "" >> $@ + echo ".PHONY: all" >> $@ + echo ".PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)" >> $@ + echo "" >> $@ + echo "all: \$$(OBJECTS_DIRS) \$$(OBJECTS)" >> $@ + echo "" >> $@ + echo "%.d:" >> $@ + echo " @echo \"\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -MM \\$$\$$(CXXFLAGS) \$$(patsubst ../\$$(DEPTH)obj/\$$(SRCDIR)%.d,../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst ../\$$(DEPTH)obj/\$$(SRCDIR)%.d,../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\" >> \$$@" >> $@ + echo " @echo \"\$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\"))\" >> \$$@" >> $@ + echo " @echo \" \\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\" >> \$$@" >> $@ + echo "" >> $@ + echo "%/makefile:" >> $@ + echo " mkdir -p \$$(dir \$$@)" >> $@ + echo " cp makefile \$$@" >> $@ + echo "" >> $@ + echo "%/: FORCE | %/makefile" >> $@ + echo " @accesstime=\`stat -c %Y \$$@\` && \\" >> $@ + echo " \$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ DEPTH=\$$(DEPTH)../ && \\" >> $@ + echo " accesstime2=\`stat -c %Y \$$@\` && \\" >> $@ + echo " if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\" >> $@ + echo " touch .; \\" >> $@ + echo " fi" >> $@ + echo "" >> $@ + echo "FORCE:" >> $@ + echo "" >> $@ + echo "-include \$$(DEPENDENCIES)" >> $@ + +obj/: FORCE | obj/makefile + $(MAKE) -C $@ + +$(OBJECTS): obj/ + + +build: bin/$(EXECUTABLE) + + + +clean: + $(RM) -r *.o *.d bin lib obj test-bin test-obj + +FORCE: + diff --git a/aintegral2/src/aintegral.cpp b/aintegral2/src/aintegral.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5109c6cff7b82dd8e622004926617984ad43a575 --- /dev/null +++ b/aintegral2/src/aintegral.cpp @@ -0,0 +1,46 @@ +/* + * aintegral.cpp + * + * Created on: 24. 2. 2014 + * Author: Tomas Pecka + */ + +#include <iostream> + +#include <factory/DataFactory.hpp> +#include <exception/AlibException.h> + +#include "regexp/RegExpIntegral.h" + +int main(int argc, char** argv) +{ + try + { + if(argc == 2 && std::string("-h").compare(argv[1]) == 0) + { + std::cout << "aintegral. Integrates regular expression by given string." << std::endl; + std::cout << "Usage: aintegral regexp.xml string.xml" << std::endl; + return -1; + } + + if(argc == 3) + { + regexp::RegExp regexp = alib::DataFactory::fromFile<regexp::RegExp>(argv[1]); + string::LinearString* string = static_cast<string::LinearString*>(std::move(alib::DataFactory::fromFile<string::LinearString>(argv[2])).plunder()); + + RegExpIntegral i; + alib::DataFactory::toStdout(i.integral(regexp, *string)); + + return 0; + } + } + catch(const exception::AlibException& exception) + { + alib::DataFactory::toStdout(exception); + return 1; + } + catch(...) + { + return 127; + } +} diff --git a/alib2algo/makefile b/alib2algo/makefile index d4c904959dddcfa943b49fab26de937e943db7cb..d9afb63a5aa6564df0965883fa02f142e71fed95 100644 --- a/alib2algo/makefile +++ b/alib2algo/makefile @@ -79,7 +79,7 @@ test-obj/makefile: makefile echo "SRCDIR:=" >> $@ echo "DEPTH:=" >> $@ echo "" >> $@ - echo "CXXFLAGS:= -std=c++11 -O0 -g -c -Wall -pedantic -Wextra -I../\$$(DEPTH)src/ -I../../\$$(DEPTH)alib2data/src" >> $@ + echo "CXXFLAGS:= -std=c++11 -O0 -g -c -Wall -pedantic -Wextra -I/usr/include/libxml2 -I../\$$(DEPTH)src/ -I../../\$$(DEPTH)alib2data/src" >> $@ echo "" >> $@ echo "SOURCES:= \$$(shell find ../\$$(DEPTH)test-src/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")" >> $@ echo "DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)test-src/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)test-obj/\$$(SRCDIR)%.d, \$$(SOURCES))" >> $@ diff --git a/alib2algo/src/fa2re/BrzozowskiAlgebraic.cpp b/alib2algo/src/conversions/fa2re/BrzozowskiAlgebraic.cpp similarity index 100% rename from alib2algo/src/fa2re/BrzozowskiAlgebraic.cpp rename to alib2algo/src/conversions/fa2re/BrzozowskiAlgebraic.cpp diff --git a/alib2algo/src/fa2re/BrzozowskiAlgebraic.h b/alib2algo/src/conversions/fa2re/BrzozowskiAlgebraic.h similarity index 95% rename from alib2algo/src/fa2re/BrzozowskiAlgebraic.h rename to alib2algo/src/conversions/fa2re/BrzozowskiAlgebraic.h index 9e52cabacebb38073bc642b3119324486e5abf31..4f83815847f6aee6252f3afc1593e3919d363183 100644 --- a/alib2algo/src/fa2re/BrzozowskiAlgebraic.h +++ b/alib2algo/src/conversions/fa2re/BrzozowskiAlgebraic.h @@ -16,7 +16,7 @@ #include <automaton/FSM/NFA.h> #include "common/macros.h" -#include "../equations/RightRegularEquationSolver.h" +#include "../../equations/RightRegularEquationSolver.h" namespace fa2re { diff --git a/alib2algo/src/re2fa/Glushkov.cpp b/alib2algo/src/conversions/re2fa/Glushkov.cpp similarity index 100% rename from alib2algo/src/re2fa/Glushkov.cpp rename to alib2algo/src/conversions/re2fa/Glushkov.cpp diff --git a/alib2algo/src/re2fa/Glushkov.h b/alib2algo/src/conversions/re2fa/Glushkov.h similarity index 96% rename from alib2algo/src/re2fa/Glushkov.h rename to alib2algo/src/conversions/re2fa/Glushkov.h index 136d4febbb8829ad919c71dd9dbc63774832b3f9..7b7f01f6c1c32b1dfe2c234eb4efba35d2be28d7 100644 --- a/alib2algo/src/re2fa/Glushkov.h +++ b/alib2algo/src/conversions/re2fa/Glushkov.h @@ -15,7 +15,7 @@ #include <regexp/unbounded/UnboundedRegExp.h> #include <regexp/unbounded/UnboundedRegExpElements.h> -#include "../regexp/GlushkovTraversal.h" +#include "../../regexp/GlushkovTraversal.h" #include "std/hexavigesimal.h" #include <automaton/FSM/NFA.h> diff --git a/alib2algo/src/rg2rg/lrg2rrg/LeftToRightRegularGrammar.cpp b/alib2algo/src/conversions/rg2rg/lrg2rrg/LeftToRightRegularGrammar.cpp similarity index 100% rename from alib2algo/src/rg2rg/lrg2rrg/LeftToRightRegularGrammar.cpp rename to alib2algo/src/conversions/rg2rg/lrg2rrg/LeftToRightRegularGrammar.cpp diff --git a/alib2algo/src/rg2rg/lrg2rrg/LeftToRightRegularGrammar.h b/alib2algo/src/conversions/rg2rg/lrg2rrg/LeftToRightRegularGrammar.h similarity index 100% rename from alib2algo/src/rg2rg/lrg2rrg/LeftToRightRegularGrammar.h rename to alib2algo/src/conversions/rg2rg/lrg2rrg/LeftToRightRegularGrammar.h diff --git a/alib2algo/src/rg2rg/rrg2lrg/RightToLeftRegularGrammar.cpp b/alib2algo/src/conversions/rg2rg/rrg2lrg/RightToLeftRegularGrammar.cpp similarity index 100% rename from alib2algo/src/rg2rg/rrg2lrg/RightToLeftRegularGrammar.cpp rename to alib2algo/src/conversions/rg2rg/rrg2lrg/RightToLeftRegularGrammar.cpp diff --git a/alib2algo/src/rg2rg/rrg2lrg/RightToLeftRegularGrammar.h b/alib2algo/src/conversions/rg2rg/rrg2lrg/RightToLeftRegularGrammar.h similarity index 100% rename from alib2algo/src/rg2rg/rrg2lrg/RightToLeftRegularGrammar.h rename to alib2algo/src/conversions/rg2rg/rrg2lrg/RightToLeftRegularGrammar.h diff --git a/alib2algo/src/regexp/RegExpDerivation.cpp b/alib2algo/src/regexp/RegExpDerivation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c882371bee1caf42d14627a6fb7e76500b1715c1 --- /dev/null +++ b/alib2algo/src/regexp/RegExpDerivation.cpp @@ -0,0 +1,209 @@ +/* + * RegExpDerivation.cpp + * + * Created on: 19. 1. 2014 + * Author: Tomas Pecka + */ + +#include "RegExpDerivation.h" + +RegExpDerivation::RegExpDerivation(){} +RegExpDerivation::~RegExpDerivation(){} + +regexp::RegExp RegExpDerivation::derivation(const regexp::RegExp& regexp, const string::LinearString& string) +{ + std::pair<regexp::RegExp, string::LinearString> out(regexp, string); + regexp.getData().Accept((void*) &out, *this); + return out.first; +} + +void RegExpDerivation::Visit(void* userData, const regexp::FormalRegExp& regexp) +{ + std::pair<regexp::RegExp, string::LinearString> &ret = *(std::pair<regexp::RegExp, string::LinearString>*) userData; + + const regexp::FormalRegExpElement* newRegExp = regexp.getRegExp().clone(); + + for(const auto& symbol : ret.second.getContent()) + { + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> out(symbol, nullptr); + newRegExp->Accept((void*) &out, *this); + delete newRegExp; + newRegExp = out.second; + } + + ret.first = regexp::RegExp{regexp::FormalRegExp(std::move(*newRegExp))}; + delete newRegExp; +} + +void RegExpDerivation::Visit(void* userData, const regexp::FormalRegExpAlternation& alternation) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + + static_cast<const regexp::FormalRegExpElement&>(alternation.getLeftElement()).Accept(userData, *this); + const regexp::FormalRegExpElement* leftDerivative = out.second; + + static_cast<const regexp::FormalRegExpElement&>(alternation.getRightElement()).Accept(userData, *this); + const regexp::FormalRegExpElement* rightDerivative = out.second; + + out.second = new regexp::FormalRegExpAlternation(std::move(*leftDerivative), std::move(*rightDerivative)); + delete leftDerivative; + delete rightDerivative; +} + +void RegExpDerivation::Visit(void* userData, const regexp::FormalRegExpConcatenation& concatenation) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + + static_cast<const regexp::FormalRegExpElement&>(concatenation.getLeftElement()).Accept(userData, *this); + const regexp::FormalRegExpElement* leftDerivative = out.second; + const regexp::FormalRegExpElement* rightElement = concatenation.getRightElement().clone(); + out.second = new regexp::FormalRegExpConcatenation(std::move(*leftDerivative), std::move(*rightElement)); + delete leftDerivative; + delete rightElement; + + if(concatenation.getLeftElement().containsEmptyString()) + { + const regexp::FormalRegExpElement *alternation = out.second, *rightDerivative = nullptr; + static_cast<const regexp::FormalRegExpElement&>(concatenation.getRightElement()).Accept(userData, *this); + rightDerivative = out.second; + + out.second = new regexp::FormalRegExpAlternation(std::move(*alternation), std::move(*rightDerivative)); + delete alternation; + delete rightDerivative; + } +} + +void RegExpDerivation::Visit(void* userData, const regexp::FormalRegExpIteration& iteration) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + + static_cast<const regexp::FormalRegExpElement&>(iteration.getElement()).Accept(userData, *this); + const regexp::FormalRegExpElement* iterDerivative = out.second; + const regexp::FormalRegExpElement* iter = iteration.clone(); + + out.second = new regexp::FormalRegExpConcatenation(std::move(*iterDerivative), std::move(*iter)); + delete iterDerivative; + delete iter; +} + +void RegExpDerivation::Visit(void* userData, const regexp::FormalRegExpSymbol& symbol) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + + if(out.first == symbol.getSymbol()) + out.second = new regexp::FormalRegExpEpsilon(); + else + out.second = new regexp::FormalRegExpEmpty(); +} + + +void RegExpDerivation::Visit(void* userData, const regexp::FormalRegExpEpsilon& epsilon) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + out.second = new regexp::FormalRegExpEmpty(); +} + +void RegExpDerivation::Visit(void* userData, const regexp::FormalRegExpEmpty& empty) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + out.second = new regexp::FormalRegExpEmpty(); +} + +void RegExpDerivation::Visit(void* userData, const regexp::UnboundedRegExp& regexp) +{ + std::pair<regexp::RegExp, string::LinearString> &ret = *(std::pair<regexp::RegExp, string::LinearString>*) userData; + + const regexp::UnboundedRegExpElement* newRegExp = regexp.getRegExp().clone(); + + for(const auto& symbol : ret.second.getContent()) + { + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> out(symbol, nullptr); + newRegExp->Accept((void*) &out, *this); + delete newRegExp; + newRegExp = out.second; + } + + ret.first = regexp::RegExp{regexp::UnboundedRegExp(std::move(*newRegExp))}; + delete newRegExp; +} + +void RegExpDerivation::Visit(void* userData, const regexp::UnboundedRegExpAlternation& alternation) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + regexp::UnboundedRegExpAlternation* ret = new regexp::UnboundedRegExpAlternation(); + + for(const auto& child : alternation.getElements()) + { + static_cast<const regexp::UnboundedRegExpElement&>(*child).Accept(userData, *this); + ret->appendElement(std::move(*out.second)); + delete out.second; + } + + out.second = ret; +} + +void RegExpDerivation::Visit(void* userData, const regexp::UnboundedRegExpConcatenation& concatenation) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + regexp::UnboundedRegExpAlternation* ret = new regexp::UnboundedRegExpAlternation(); + + for(auto child = concatenation.getElements().begin(); child != concatenation.getElements().end(); child ++) + { + regexp::UnboundedRegExpConcatenation* concat = new regexp::UnboundedRegExpConcatenation(); + static_cast<const regexp::UnboundedRegExpElement&>(**child).Accept(userData, *this); + concat->appendElement(std::move(*out.second)); + delete out.second; + + auto succeedingElement = child; + while(++succeedingElement != concatenation.getElements().end()) + concat->appendElement(std::move(*(*succeedingElement)->clone())); + + ret->appendElement(std::move(*concat)); + delete concat; + + if((*child)->containsEmptyString()) + continue; // this IF construct is intentional "to match algorithm" + break; + } + + out.second = ret; +} + +void RegExpDerivation::Visit(void* userData, const regexp::UnboundedRegExpIteration& iteration) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + + static_cast<const regexp::UnboundedRegExpElement&>(iteration.getElement()).Accept(userData, *this); + const regexp::UnboundedRegExpElement* iterDerivative = out.second; + const regexp::UnboundedRegExpElement* iter = iteration.clone(); + + regexp::UnboundedRegExpConcatenation* ret = new regexp::UnboundedRegExpConcatenation(); + ret->appendElement(std::move(*iterDerivative)); + ret->appendElement(std::move(*iter)); + delete iterDerivative; + delete iter; + + out.second = ret; +} + +void RegExpDerivation::Visit(void* userData, const regexp::UnboundedRegExpSymbol& symbol) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + + if(out.first == symbol.getSymbol()) + out.second = new regexp::UnboundedRegExpEpsilon(); + else + out.second = new regexp::UnboundedRegExpEmpty(); +} + +void RegExpDerivation::Visit(void* userData, const regexp::UnboundedRegExpEpsilon& epsilon) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + out.second = new regexp::UnboundedRegExpEmpty(); +} + +void RegExpDerivation::Visit(void* userData, const regexp::UnboundedRegExpEmpty& empty) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + out.second = new regexp::UnboundedRegExpEmpty(); +} diff --git a/alib2algo/src/regexp/RegExpDerivation.h b/alib2algo/src/regexp/RegExpDerivation.h new file mode 100644 index 0000000000000000000000000000000000000000..e47e80b22b39484e934f3a16aaf6af092dcf1213 --- /dev/null +++ b/alib2algo/src/regexp/RegExpDerivation.h @@ -0,0 +1,51 @@ +/* + * RegExpDerivation.h + * + * Created on: 19. 1. 2014 + * Author: Tomas Pecka + */ + +#ifndef REGEXPDERIVATION_H_ +#define REGEXPDERIVATION_H_ + +#include <regexp/RegExp.h> +#include <regexp/formal/FormalRegExpElements.h> +#include <regexp/unbounded/UnboundedRegExpElements.h> + +#include <string/LinearString.h> +#include <string/StringBase.h> + +/** + * Calculates derivation of regular expression. + * + * Sources: + * - Melichar, definition 2.91 in chapter 2.4.3 + * - Brzozowski, J. A. - Derivatives of regular expressions (1964) + */ +class RegExpDerivation : public regexp::VisitableRegExpBase::visitor_type, regexp::FormalRegExpElement::visitor_type, regexp::UnboundedRegExpElement::visitor_type +{ +public: + RegExpDerivation(); + ~RegExpDerivation(); + regexp::RegExp derivation(const regexp::RegExp& regexp, const string::LinearString& string); + +private: + void Visit(void*, const regexp::UnboundedRegExpAlternation& alternation); + void Visit(void*, const regexp::UnboundedRegExpConcatenation& concatenation); + void Visit(void*, const regexp::UnboundedRegExpIteration& iteration); + void Visit(void*, const regexp::UnboundedRegExpSymbol& symbol); + void Visit(void*, const regexp::UnboundedRegExpEpsilon& epsilon); + void Visit(void*, const regexp::UnboundedRegExpEmpty& empty); + + void Visit(void*, const regexp::FormalRegExpAlternation& alternation); + void Visit(void*, const regexp::FormalRegExpConcatenation& concatenation); + void Visit(void*, const regexp::FormalRegExpIteration& iteration); + void Visit(void*, const regexp::FormalRegExpSymbol& symbol); + void Visit(void*, const regexp::FormalRegExpEpsilon& epsilon); + void Visit(void*, const regexp::FormalRegExpEmpty& empty); + + void Visit(void*, const regexp::UnboundedRegExp& empty); + void Visit(void*, const regexp::FormalRegExp& empty); +}; + +#endif /* REGEXPDERIVATION_H_ */ diff --git a/alib2algo/src/regexp/RegExpIntegral.cpp b/alib2algo/src/regexp/RegExpIntegral.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dcc9f4f5d7cacd84b7ccebf473dd9ee61cf01e31 --- /dev/null +++ b/alib2algo/src/regexp/RegExpIntegral.cpp @@ -0,0 +1,207 @@ +/* + * RegExpIntegral.cpp + * + * Created on: 24. 2. 2014 + * Author: Tomas Pecka + */ + +#include "RegExpIntegral.h" + +RegExpIntegral::RegExpIntegral(){} +RegExpIntegral::~RegExpIntegral(){} + +regexp::RegExp RegExpIntegral::integral(const regexp::RegExp& regexp, const string::LinearString& string) +{ + std::pair<regexp::RegExp, string::LinearString> out(regexp, string); + regexp.getData().Accept((void*) &out, *this); + return out.first; +} + +void RegExpIntegral::Visit(void* userData, const regexp::FormalRegExp& regexp) +{ + std::pair<regexp::RegExp, string::LinearString> &ret = *(std::pair<regexp::RegExp, string::LinearString>*) userData; + + const regexp::FormalRegExpElement* newRegExp = regexp.getRegExp().clone(); + + for(auto it = ret.second.getContent().begin(); it != ret.second.getContent().end(); it ++) + { + const auto& symbol = *it; + + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> out(symbol, nullptr); + newRegExp->Accept((void*) &out, *this); + delete newRegExp; + newRegExp = out.second; + } + + ret.first = regexp::RegExp{regexp::FormalRegExp(std::move(*newRegExp))}; + delete newRegExp; +} + +void RegExpIntegral::Visit(void* userData, const regexp::FormalRegExpAlternation& alternation) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + + static_cast<const regexp::FormalRegExpElement&>(alternation.getLeftElement()).Accept(userData, *this); + const regexp::FormalRegExpElement* leftIntegral = out.second; + + static_cast<const regexp::FormalRegExpElement&>(alternation.getRightElement()).Accept(userData, *this); + const regexp::FormalRegExpElement* rightIntegral = out.second; + + out.second = new regexp::FormalRegExpAlternation(std::move(*leftIntegral), std::move(*rightIntegral)); + delete leftIntegral; + delete rightIntegral; +} + +void RegExpIntegral::Visit(void* userData, const regexp::FormalRegExpConcatenation& concatenation) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + + regexp::FormalRegExpSymbol* symb = new regexp::FormalRegExpSymbol(out.first); + regexp::FormalRegExpElement* concat = concatenation.clone(); + regexp::FormalRegExpConcatenation* ret = new regexp::FormalRegExpConcatenation(std::move(*symb), std::move(*concat)); + + delete concat; + delete symb; + + out.second = ret; +} + +void RegExpIntegral::Visit(void* userData, const regexp::FormalRegExpIteration& iteration) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + + regexp::FormalRegExpSymbol* symb = new regexp::FormalRegExpSymbol(out.first); + regexp::FormalRegExpElement* iter = iteration.clone(); + regexp::FormalRegExpConcatenation* ret = new regexp::FormalRegExpConcatenation(std::move(*symb), std::move(*iter)); + + delete iter; + delete symb; + + out.second = ret; +} + +void RegExpIntegral::Visit(void* userData, const regexp::FormalRegExpSymbol& symbol) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + + regexp::FormalRegExpSymbol* symb = new regexp::FormalRegExpSymbol(out.first); + regexp::FormalRegExpElement* symb2 = symbol.clone(); + regexp::FormalRegExpConcatenation* ret = new regexp::FormalRegExpConcatenation(std::move(*symb), std::move(*symb2)); + + delete symb2; + delete symb; + + out.second = ret; +} + + +void RegExpIntegral::Visit(void* userData, const regexp::FormalRegExpEpsilon& epsilon) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + regexp::FormalRegExpSymbol* symb = new regexp::FormalRegExpSymbol(out.first); + out.second = symb; +} + +void RegExpIntegral::Visit(void* userData, const regexp::FormalRegExpEmpty& empty) +{ + std::pair<alphabet::Symbol, regexp::FormalRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::FormalRegExpElement*>*) userData); + out.second = new regexp::FormalRegExpEmpty(); +} + + +void RegExpIntegral::Visit(void* userData, const regexp::UnboundedRegExp& regexp) +{ + std::pair<regexp::RegExp, string::LinearString> &ret = *(std::pair<regexp::RegExp, string::LinearString>*) userData; + + const regexp::UnboundedRegExpElement* newRegExp = regexp.getRegExp().clone(); + + for(auto it = ret.second.getContent().begin(); it != ret.second.getContent().end(); it ++) + { + const auto& symbol = *it; + + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> out(symbol, nullptr); + newRegExp->Accept((void*) &out, *this); + delete newRegExp; + newRegExp = out.second; + } + + ret.first = regexp::RegExp{regexp::UnboundedRegExp(std::move(*newRegExp))}; + delete newRegExp; +} + +void RegExpIntegral::Visit(void* userData, const regexp::UnboundedRegExpAlternation& alternation) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + regexp::UnboundedRegExpAlternation* ret = new regexp::UnboundedRegExpAlternation(); + + for(const auto& child : alternation.getElements()) + { + static_cast<const regexp::UnboundedRegExpElement&>(*child).Accept(userData, *this); + ret->appendElement(std::move(*out.second)); + delete out.second; + } + + out.second = ret; +} + +void RegExpIntegral::Visit(void* userData, const regexp::UnboundedRegExpConcatenation& concatenation) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + + regexp::UnboundedRegExpSymbol* symb = new regexp::UnboundedRegExpSymbol(out.first); + regexp::UnboundedRegExpElement* concat = concatenation.clone(); + regexp::UnboundedRegExpConcatenation* ret = new regexp::UnboundedRegExpConcatenation(); + ret->appendElement(std::move(*symb)); + ret->appendElement(std::move(*concat)); + + delete concat; + delete symb; + + out.second = ret; +} + +void RegExpIntegral::Visit(void* userData, const regexp::UnboundedRegExpIteration& iteration) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + + regexp::UnboundedRegExpSymbol* symb = new regexp::UnboundedRegExpSymbol(out.first); + regexp::UnboundedRegExpElement* iter = iteration.clone(); + regexp::UnboundedRegExpConcatenation* ret = new regexp::UnboundedRegExpConcatenation(); + ret->appendElement(std::move(*symb)); + ret->appendElement(std::move(*iter)); + + delete iter; + delete symb; + + out.second = ret; +} + +void RegExpIntegral::Visit(void* userData, const regexp::UnboundedRegExpSymbol& symbol) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + + regexp::UnboundedRegExpSymbol* symb = new regexp::UnboundedRegExpSymbol(out.first); + regexp::UnboundedRegExpElement* symb2 = symbol.clone(); + regexp::UnboundedRegExpConcatenation* ret = new regexp::UnboundedRegExpConcatenation(); + ret->appendElement(std::move(*symb)); + ret->appendElement(std::move(*symb2)); + + delete symb2; + delete symb; + + out.second = ret; +} + +void RegExpIntegral::Visit(void* userData, const regexp::UnboundedRegExpEpsilon& epsilon) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + + regexp::UnboundedRegExpSymbol* symb = new regexp::UnboundedRegExpSymbol(out.first); + out.second = symb; +} + +void RegExpIntegral::Visit(void* userData, const regexp::UnboundedRegExpEmpty& empty) +{ + std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*> &out = *((std::pair<alphabet::Symbol, regexp::UnboundedRegExpElement*>*) userData); + out.second = new regexp::UnboundedRegExpEmpty(); +} diff --git a/alib2algo/src/regexp/RegExpIntegral.h b/alib2algo/src/regexp/RegExpIntegral.h new file mode 100644 index 0000000000000000000000000000000000000000..87c5f79964c8c138651e80bee3dc3e0764f86c89 --- /dev/null +++ b/alib2algo/src/regexp/RegExpIntegral.h @@ -0,0 +1,47 @@ +/* + * RegExpIntegral.h + * + * Created on: 24. 2. 2014 + * Author: Tomas Pecka + */ + +#ifndef REGEXPINTEGRAL_H_ +#define REGEXPINTEGRAL_H_ + +#include <regexp/RegExp.h> +#include <regexp/formal/FormalRegExpElements.h> +#include <regexp/unbounded/UnboundedRegExpElements.h> + +#include <string/LinearString.h> +#include <string/StringBase.h> + +/** + * Calculates integral of regular expression as defined in Melichar 2.93 (chapt. 2.4.4) + */ +class RegExpIntegral : public regexp::VisitableRegExpBase::visitor_type, regexp::FormalRegExpElement::visitor_type, regexp::UnboundedRegExpElement::visitor_type +{ +public: + RegExpIntegral(); + ~RegExpIntegral(); + regexp::RegExp integral(const regexp::RegExp& regexp, const string::LinearString& string); + +private: + void Visit(void*, const regexp::UnboundedRegExpAlternation& alternation); + void Visit(void*, const regexp::UnboundedRegExpConcatenation& concatenation); + void Visit(void*, const regexp::UnboundedRegExpIteration& iteration); + void Visit(void*, const regexp::UnboundedRegExpSymbol& symbol); + void Visit(void*, const regexp::UnboundedRegExpEpsilon& epsilon); + void Visit(void*, const regexp::UnboundedRegExpEmpty& empty); + + void Visit(void*, const regexp::FormalRegExpAlternation& alternation); + void Visit(void*, const regexp::FormalRegExpConcatenation& concatenation); + void Visit(void*, const regexp::FormalRegExpIteration& iteration); + void Visit(void*, const regexp::FormalRegExpSymbol& symbol); + void Visit(void*, const regexp::FormalRegExpEpsilon& epsilon); + void Visit(void*, const regexp::FormalRegExpEmpty& empty); + + void Visit(void*, const regexp::UnboundedRegExp& empty); + void Visit(void*, const regexp::FormalRegExp& empty); +}; + +#endif /* REGEXPINTEGRAL_H_ */ diff --git a/alib2algo/test-src/rg2rg/rg2rgTest.cpp b/alib2algo/test-src/conversions/rg2rg/rg2rgTest.cpp similarity index 98% rename from alib2algo/test-src/rg2rg/rg2rgTest.cpp rename to alib2algo/test-src/conversions/rg2rg/rg2rgTest.cpp index 17d733af1565fb8c76ac07563e77d0fb0ab9cd1d..aa812511ff4ea3be6e805baa0e5db0e96dedf7e8 100644 --- a/alib2algo/test-src/rg2rg/rg2rgTest.cpp +++ b/alib2algo/test-src/conversions/rg2rg/rg2rgTest.cpp @@ -6,8 +6,8 @@ #include "label/Label.h" #include "alphabet/LabeledSymbol.h" -#include "rg2rg/rrg2lrg/RightToLeftRegularGrammar.h" -#include "rg2rg/lrg2rrg/LeftToRightRegularGrammar.h" +#include "conversions/rg2rg/rrg2lrg/RightToLeftRegularGrammar.h" +#include "conversions/rg2rg/lrg2rrg/LeftToRightRegularGrammar.h" #define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y)) diff --git a/alib2algo/test-src/rg2rg/rg2rgTest.h b/alib2algo/test-src/conversions/rg2rg/rg2rgTest.h similarity index 100% rename from alib2algo/test-src/rg2rg/rg2rgTest.h rename to alib2algo/test-src/conversions/rg2rg/rg2rgTest.h diff --git a/alib2algo/test-src/play/playTest.cpp b/alib2algo/test-src/play/playTest.cpp index 57171f2cff564634d55a345ae6e3d4495ca9c714..32a9088766c30ef886802af9a2c7b2e336469ada 100644 --- a/alib2algo/test-src/play/playTest.cpp +++ b/alib2algo/test-src/play/playTest.cpp @@ -1,8 +1,8 @@ #include <list> #include "playTest.h" -#include "re2fa/Glushkov.h" -#include "fa2re/BrzozowskiAlgebraic.h" +#include "conversions/re2fa/Glushkov.h" +#include "conversions/fa2re/BrzozowskiAlgebraic.h" #include "determinize/nfa/NFADeterminizer.h" #include "minimize/dfa/MinimizeDFA.h" diff --git a/alib2algo/test-src/regexp/RegExpDerivationTest.cpp b/alib2algo/test-src/regexp/RegExpDerivationTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7554f11c64bd5676691b6291ccf033863d277c23 --- /dev/null +++ b/alib2algo/test-src/regexp/RegExpDerivationTest.cpp @@ -0,0 +1,50 @@ +#include <sstream> + +#include "RegExpDerivationTest.h" + +#include "regexp/RegExpDerivation.h" + +#include <regexp/RegExpFromStringParser.h> +#include <regexp/RegExpToStringComposer.h> +#include <string/StringFromStringParser.h> + +#define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y)) + +CPPUNIT_TEST_SUITE_REGISTRATION( RegExpDerivationTest ); + +void RegExpDerivationTest::setUp() { +} + +void RegExpDerivationTest::tearDown() { +} + +void RegExpDerivationTest::testRegExpDerivation() { + // https://edux.fit.cvut.cz/oppa/BI-AAG/cviceni/aag-cv04.pdf + + // Exc. 13 + this->ExecSingleTest("010 + 101 + 01*1 + 1*0", "0", "#E 1 0+#0 0 1+#E 0* 1+#0+#0 1* 0+#E"); + this->ExecSingleTest("010 + 101 + 01*1 + 1*0", "0 0", "#0 1 0+#0 0+#0 0 1+(#0 0*+#E 0*) 1+#0+#0+#0 1* 0+#0"); + + // Exc. 14 + this->ExecSingleTest("(01*0 + 10*)*", "1", "(#0 1* 0+#E 0*) (0 1* 0+1 0*)*"); + this->ExecSingleTest("(01*0 + 10*)*", "1 0", "(#0 1* 0+#0 0*+#E 0*) (0 1* 0+1 0*)*+(#E 1* 0+#0 0*) (0 1* 0+1 0*)*"); + + // Exc. 15 + this->ExecSingleTest("10*1*0", "100", "#0 0* 1* 0+(#0 0*+#E 0*) 1* 0+#0 1* 0+#E+#0 1* 0+#0"); +} + +void RegExpDerivationTest::ExecSingleTest(std::string regexp_str, std::string string_str, std::string result) { + std::stringstream regexp_ss(regexp_str); + regexp::RegExpFromStringParser regexp_parser(regexp_ss); + regexp::RegExp regexp = regexp_parser.parseValue(); + + std::stringstream string_ss("\"" + string_str + "\""); + string::StringFromStringParser string_parser(string_ss); + string::String string = string_parser.parseValue(); + + RegExpDerivation d; + regexp::RegExpToStringComposer regexp_composer; + + // TODO + // CPPUNIT_ASSERT(regexp_composer.compose(d.derivation(regexp, string)) == result); +} diff --git a/alib2algo/test-src/regexp/RegExpDerivationTest.h b/alib2algo/test-src/regexp/RegExpDerivationTest.h new file mode 100644 index 0000000000000000000000000000000000000000..4b3d9f4bde783c52518d64101c0b8a51f3e540f0 --- /dev/null +++ b/alib2algo/test-src/regexp/RegExpDerivationTest.h @@ -0,0 +1,23 @@ +#ifndef REGEXPDERIVATION_TEST_H_ +#define REGEXPDERIVATION_TEST_H_ + +#include <string> + +#include <cppunit/extensions/HelperMacros.h> + +class RegExpDerivationTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( RegExpDerivationTest ); + CPPUNIT_TEST( testRegExpDerivation ); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + void tearDown(); + + void testRegExpDerivation(); + + void ExecSingleTest(std::string, std::string, std::string); +}; + +#endif /* REGEXPDERIVATION_TEST_H_ */ diff --git a/alib2algo/test-src/regexp/RegExpIntegralTest.cpp b/alib2algo/test-src/regexp/RegExpIntegralTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8264659718f3a232d6e5551a15621f697e14265f --- /dev/null +++ b/alib2algo/test-src/regexp/RegExpIntegralTest.cpp @@ -0,0 +1,42 @@ +#include <sstream> + +#include "RegExpIntegralTest.h" + +#include "regexp/RegExpIntegral.h" + +#include <regexp/RegExpFromStringParser.h> +#include <regexp/RegExpToStringComposer.h> +#include <string/StringFromStringParser.h> + +#define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y)) + +CPPUNIT_TEST_SUITE_REGISTRATION( RegExpIntegralTest ); + +void RegExpIntegralTest::setUp() { +} + +void RegExpIntegralTest::tearDown() { +} + +void RegExpIntegralTest::testRegExpIntegral() { + // https://edux.fit.cvut.cz/oppa/BI-AAG/cviceni/aag-cv04.pdf + + // Exc. 16 + this->ExecSingleTest("010 + 101", "1", "1 0 1 0 + 1 1 0 1"); +} + +void RegExpIntegralTest::ExecSingleTest(std::string regexp_str, std::string string_str, std::string result) { + std::stringstream regexp_ss(regexp_str); + regexp::RegExpFromStringParser regexp_parser(regexp_ss); + regexp::RegExp regexp = regexp_parser.parseValue(); + + std::stringstream string_ss("\"" + string_str + "\""); + string::StringFromStringParser string_parser(string_ss); + string::String string = string_parser.parseValue(); + + RegExpIntegral i; + regexp::RegExpToStringComposer regexp_composer; + + // TODO + // CPPUNIT_ASSERT(regexp_composer.compose(i.integral(regexp, string)) == result); +} diff --git a/alib2algo/test-src/regexp/RegExpIntegralTest.h b/alib2algo/test-src/regexp/RegExpIntegralTest.h new file mode 100644 index 0000000000000000000000000000000000000000..3634c9f754f0059e250750a42f1e1b8ee6487f5a --- /dev/null +++ b/alib2algo/test-src/regexp/RegExpIntegralTest.h @@ -0,0 +1,23 @@ +#ifndef REGEXPINTEGRAL_TEST_H_ +#define REGEXPINTEGRAL_TEST_H_ + +#include <string> + +#include <cppunit/extensions/HelperMacros.h> + +class RegExpIntegralTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( RegExpIntegralTest ); + CPPUNIT_TEST( testRegExpIntegral ); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + void tearDown(); + + void testRegExpIntegral(); + + void ExecSingleTest(std::string, std::string, std::string); +}; + +#endif /* REGEXPINTEGRAL_TEST_H_ */ diff --git a/examples2/regexp/formal-aag.oppa.4.13.xml b/examples2/regexp/formal-aag.oppa.4.13.xml new file mode 100644 index 0000000000000000000000000000000000000000..a8c8c362559641b7760c688ceeb1d087774ea758 --- /dev/null +++ b/examples2/regexp/formal-aag.oppa.4.13.xml @@ -0,0 +1,38 @@ +<formalRegexp> + <alphabet> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </alphabet> + <alternation> + <concatenation> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <concatenation> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </concatenation> + </concatenation> + <alternation> + <concatenation> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + <concatenation> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </concatenation> + </concatenation> + <alternation> + <concatenation> + <iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </iteration> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </concatenation> + <concatenation> + <iteration> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </concatenation> + </alternation> + </alternation> + </alternation> +</formalRegexp> diff --git a/examples2/regexp/formal-aag.oppa.4.14.xml b/examples2/regexp/formal-aag.oppa.4.14.xml new file mode 100644 index 0000000000000000000000000000000000000000..8687b3508958f659ffdf200da6ec5436c32f195c --- /dev/null +++ b/examples2/regexp/formal-aag.oppa.4.14.xml @@ -0,0 +1,23 @@ +<unboundedRegexp> + <alphabet> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </alphabet> + <iteration> + <alternation> + <concatenation> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <iteration> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </concatenation> + <concatenation> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + <iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </iteration> + </concatenation> + </alternation> + </iteration> +</unboundedRegexp> diff --git a/examples2/regexp/unbounded-aag.oppa.4.13.xml b/examples2/regexp/unbounded-aag.oppa.4.13.xml new file mode 100644 index 0000000000000000000000000000000000000000..8aca563ef7e231357f1b27fa846eebabe06f71aa --- /dev/null +++ b/examples2/regexp/unbounded-aag.oppa.4.13.xml @@ -0,0 +1,30 @@ +<unboundedRegexp> + <alphabet> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </alphabet> + <alternation> + <concatenation> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </concatenation> + <concatenation> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </concatenation> + <concatenation> + <iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </iteration> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </concatenation> + <concatenation> + <iteration> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </concatenation> + </alternation> +</unboundedRegexp> diff --git a/examples2/regexp/unbounded-aag.oppa.4.14.xml b/examples2/regexp/unbounded-aag.oppa.4.14.xml new file mode 100644 index 0000000000000000000000000000000000000000..8687b3508958f659ffdf200da6ec5436c32f195c --- /dev/null +++ b/examples2/regexp/unbounded-aag.oppa.4.14.xml @@ -0,0 +1,23 @@ +<unboundedRegexp> + <alphabet> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </alphabet> + <iteration> + <alternation> + <concatenation> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <iteration> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </concatenation> + <concatenation> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + <iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </iteration> + </concatenation> + </alternation> + </iteration> +</unboundedRegexp> diff --git a/examples2/regexp/unbounded-aag.oppa.4.15.xml b/examples2/regexp/unbounded-aag.oppa.4.15.xml new file mode 100644 index 0000000000000000000000000000000000000000..eb3ca9612827adb2cae109432c39eb3337607656 --- /dev/null +++ b/examples2/regexp/unbounded-aag.oppa.4.15.xml @@ -0,0 +1,16 @@ +<unboundedRegexp> + <alphabet> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </alphabet> + <concatenation> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + <iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </iteration> + <iteration> + <LabeledSymbol><IntegerLabel>1</IntegerLabel></LabeledSymbol> + </iteration> + <LabeledSymbol><IntegerLabel>0</IntegerLabel></LabeledSymbol> + </concatenation> +</unboundedRegexp> diff --git a/makefile b/makefile index 1cb34d76493909e7bc58bf583678f23c53f64d97..2a4bde95c71d3ef2428f7dab0372055db54b2f59 100644 --- a/makefile +++ b/makefile @@ -7,9 +7,11 @@ SUBDIRS_LIBS = alib2algo SUBDIRS_BINS = acat2 \ aconversions2 \ aconvert2 \ + aderivation2 \ adeterminize2 \ adiff2 \ aepsilon2 \ + aintegral2 \ aminimize2 \ anormalize2 \ arand2 \