diff --git a/aconversions/.cproject b/aconversions/.cproject index bb01ba9941de10840aee0b77a4bdc61846d20ee3..db78cf652aa3bbc680dd8cbbdf7ae42d4274c076 100644 --- a/aconversions/.cproject +++ b/aconversions/.cproject @@ -25,6 +25,8 @@ <option id="gnu.cpp.compiler.exe.debug.option.debugging.level.590531226" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/> <option id="gnu.cpp.compiler.option.include.paths.2109499447" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath"> <listOptionValue builtIn="false" value=""${workspace_loc:/alib/src}""/> + <listOptionValue builtIn="false" value=""${workspace_loc:/libaregexptree/src}""/> + <listOptionValue builtIn="false" value=""${workspace_loc:/libaderivation/src}""/> <listOptionValue builtIn="false" value="/usr/include/libxml2"/> </option> <option id="gnu.cpp.compiler.option.other.other.1786233414" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0 -std=c++11" valueType="string"/> diff --git a/aconversions/Makefile b/aconversions/Makefile index b156636b3f5d18521a31d52010e0fd4614e31535..4d5c0a5b0fb078353029bcc565cf50417b609fc7 100644 --- a/aconversions/Makefile +++ b/aconversions/Makefile @@ -1,23 +1,25 @@ OUT_DIR = bin export ALIB_SRC = $(realpath ../alib/src) export ALIB_LIB = $(realpath ../alib/lib) +export DERLIB_SRC = $(realpath ../libaderivation/src) +export DERLIB_LIB = $(realpath ../libaderivation/lib) +export RELIB_SRC = $(realpath ../libaregexptree/src) +export RELIB_LIB = $(realpath ../libaregexptree/lib) export BIN_DIR = $(addsuffix /$(OUT_DIR), $(realpath .)) export CXX=g++ -export CXXFLAGS=-O2 -g -std=c++11 -c -Wall -pedantic -I/usr/include/libxml2 -I$(ALIB_SRC) +export CXXFLAGS=-O2 -g -std=c++11 -c -Wall -pedantic -I/usr/include/libxml2 -I$(ALIB_SRC) -I$(DERLIB_SRC) -I$(RELIB_SRC) export LD=g++ -export LDFLAGS=-L$(ALIB_LIB) -lalib +export LDFLAGS=-L$(ALIB_LIB) -L$(DERLIB_LIB) -L$(RELIB_LIB) -lalib -laderivation -laregexptree .PHONY: clean all: @mkdir -p $(OUT_DIR) @$(MAKE) -C src/conversions - @$(MAKE) -C src/derivatives clean: @echo "[Clean] Cleaning up" @$(MAKE) -C src/conversions clean - @$(MAKE) -C src/derivatives clean @rm -f $(OUT_DIR)/* @rm -rf $(OUT_DIR) \ No newline at end of file diff --git a/aconversions/src/conversions/fa2re/BrzozowskiAlgebraic.cpp b/aconversions/src/conversions/fa2re/BrzozowskiAlgebraic.cpp index a4b568042f3aa6ee2f67a8c9e95b87d9ba69f63c..58b6660910a991a48acc68b32e2df67d86684142 100644 --- a/aconversions/src/conversions/fa2re/BrzozowskiAlgebraic.cpp +++ b/aconversions/src/conversions/fa2re/BrzozowskiAlgebraic.cpp @@ -6,7 +6,7 @@ */ #include "BrzozowskiAlgebraic.h" -#include <iostream> + using namespace automaton; using namespace regexp; @@ -50,8 +50,8 @@ void BrzozowskiAlgebraic::initEquations( void ) if ( isInSet( TransitionFSM( p, symbol, q ), m_automaton.getTransitions( ) ) ) alt->getElements( ).push_back( new RegExpSymbol( symbol.getSymbol( ) ) ); - RegExpNormalize norm; - m_eqTransition[ p ][ q ] = norm.normalize( alt ); + RegExpOptimize opt; + m_eqTransition[ p ][ q ] = opt.optimize( alt ); } } } @@ -101,8 +101,8 @@ RegExp BrzozowskiAlgebraic::convert( void ) for( const auto & q : m_automaton.getStates( ) ) eliminate( q ); - RegExpNormalize norm; - m_eqFinal[ initState ] = norm.normalize( m_eqFinal[ initState ] ); + RegExpOptimize opt; + m_eqFinal[ initState ] = opt.optimize( m_eqFinal[ initState ] ); m_re.setRegExp( m_eqFinal[ initState ]->clone( ) ); @@ -111,31 +111,31 @@ RegExp BrzozowskiAlgebraic::convert( void ) RegExpElement* BrzozowskiAlgebraic::alternate( RegExpElement* a, RegExpElement* b ) { - RegExpNormalize norm; + RegExpOptimize opt; Alternation* alt = new Alternation( ); alt->getElements( ).push_back( a->clone( ) ); alt->getElements( ).push_back( b->clone( ) ); - return norm.normalize( alt ); + return opt.optimize( alt ); } RegExpElement* BrzozowskiAlgebraic::concatenate( RegExpElement* a, RegExpElement* b ) { - RegExpNormalize norm; + RegExpOptimize opt; Concatenation* concat = new Concatenation( ); concat->getElements( ).push_back( a->clone( ) ); concat->getElements( ).push_back( b->clone( ) ); - return norm.normalize( concat ); + return opt.optimize( concat ); } RegExpElement* BrzozowskiAlgebraic::star( RegExpElement* a ) { - RegExpNormalize norm; + RegExpOptimize opt; Iteration* iter = new Iteration( ); iter->setElement( a->clone( ) ); - return norm.normalize( iter ); + return opt.optimize( iter ); } } /* namespace conversions */ diff --git a/aconversions/src/conversions/fa2re/BrzozowskiAlgebraic.h b/aconversions/src/conversions/fa2re/BrzozowskiAlgebraic.h index fb0cd326e3fdff8feb9d7d519f19215497a9184d..2444fc6fb46855f61579c855b697d68948183853 100644 --- a/aconversions/src/conversions/fa2re/BrzozowskiAlgebraic.h +++ b/aconversions/src/conversions/fa2re/BrzozowskiAlgebraic.h @@ -19,9 +19,10 @@ #include <regexp/RegExpEpsilon.h> #include "AbstractFAtoREConverter.h" -#include "../../derivatives/RegExpNormalize.h" #include "../../utils/utils.h" +#include "RegExpOptimize.h" + namespace conversions { diff --git a/aconversions/src/conversions/fa2re/Makefile b/aconversions/src/conversions/fa2re/Makefile index 69f4ea8864baff8a6b30c322b79e709b1c55b850..fc811a37536b2589e1f1bd023ad2db74e9246861 100644 --- a/aconversions/src/conversions/fa2re/Makefile +++ b/aconversions/src/conversions/fa2re/Makefile @@ -2,10 +2,10 @@ all: afa2re.elimination afa2re.brzozowski mv afa2re.elimination $(BIN_DIR) mv afa2re.brzozowski $(BIN_DIR) -afa2re.elimination: afa2re.elimination.o AbstractFAtoREConverter.o StateElimination.o ConversionException.o RegExpNormalize.o RegExpComprator.o +afa2re.elimination: afa2re.elimination.o AbstractFAtoREConverter.o StateElimination.o ConversionException.o RegExpComparator.o $(LD) $(LDFLAGS) $^ -o afa2re.elimination -afa2re.brzozowski: afa2re.brzozowski.o AbstractFAtoREConverter.o BrzozowskiAlgebraic.o RegExpNormalize.o ConversionException.o +afa2re.brzozowski: afa2re.brzozowski.o AbstractFAtoREConverter.o BrzozowskiAlgebraic.o ConversionException.o $(LD) $(LDFLAGS) $^ -o afa2re.brzozowski @@ -28,10 +28,7 @@ BrzozowskiAlgebraic.o: BrzozowskiAlgebraic.cpp BrzozowskiAlgebraic.h AbstractFAt ConversionException.o: ../../utils/ConversionException.cpp ../../utils/ConversionException.h $(CXX) $(CXXFLAGS) $< -o $@ -RegExpNormalize.o: ../../derivatives/RegExpNormalize.cpp ../../derivatives/RegExpNormalize.h ../../utils/ConversionException.h - $(CXX) $(CXXFLAGS) $< -o $@ - -RegExpComprator.o: ../re2fa/RegExpComparator.cpp ../re2fa/RegExpComparator.h ../../utils/ConversionException.h +RegExpComparator.o: ../../conversions/re2fa/RegExpComparator.cpp ../../conversions/re2fa/RegExpComparator.o $(CXX) $(CXXFLAGS) $< -o $@ .PHONY: clean diff --git a/aconversions/src/conversions/fa2re/StateElimination.cpp b/aconversions/src/conversions/fa2re/StateElimination.cpp index d2e8142f94c74fa3214f31eabef0d7c5a862ad42..65ee15485b633ac9f1f016bd512bc416bea3c446 100644 --- a/aconversions/src/conversions/fa2re/StateElimination.cpp +++ b/aconversions/src/conversions/fa2re/StateElimination.cpp @@ -46,8 +46,8 @@ RegExp StateElimination::convert( void ) concat->getElements( ).push_back( transition( q0, f ) ); concat->getElements( ).push_back( iter ); - RegExpNormalize norm; - m_re.setRegExp( norm.normalize( concat ) ); + RegExpOptimize opt; + m_re.setRegExp( opt.optimize( concat ) ); return m_re; } @@ -102,7 +102,7 @@ void StateElimination::extendExtendedNFA( void ) void StateElimination::eliminate( const State & q ) { set<TransitionExtendedNFA> newTransitions; - RegExpNormalize norm; + RegExpOptimize opt; for( const auto & p : m_MR.m_states ) { @@ -123,7 +123,7 @@ void StateElimination::eliminate( const State & q ) alt->getElements( ).push_back( transition( p, r ) ); alt->getElements( ).push_back( concat ); - newTransitions.insert( TransitionExtendedNFA( p, norm.normalize( alt ), r ) ); + newTransitions.insert( TransitionExtendedNFA( p, opt.optimize( alt ), r ) ); } } diff --git a/aconversions/src/conversions/fa2re/StateElimination.h b/aconversions/src/conversions/fa2re/StateElimination.h index 740791dbe767cda66765b77ebafb67d91cbd0fe8..2a717183c635fc436cfd3b5c538bfdf3367de1ce 100644 --- a/aconversions/src/conversions/fa2re/StateElimination.h +++ b/aconversions/src/conversions/fa2re/StateElimination.h @@ -22,9 +22,9 @@ #include "AbstractFAtoREConverter.h" #include "../../utils/utils.h" - #include "../../conversions/re2fa/RegExpComparator.h" -#include "../../derivatives/RegExpNormalize.h" + +#include "RegExpOptimize.h" namespace conversions { diff --git a/aconversions/src/conversions/re2fa/Brzozowski.cpp b/aconversions/src/conversions/re2fa/Brzozowski.cpp index 77b72b590472f9f09bfcdf5c0865e16570effc27..2321104d689d185275bcb5a672ff25b79e95150b 100644 --- a/aconversions/src/conversions/re2fa/Brzozowski.cpp +++ b/aconversions/src/conversions/re2fa/Brzozowski.cpp @@ -6,7 +6,6 @@ */ #include "Brzozowski.h" -#include <iostream> using namespace automaton; using namespace regexp; @@ -21,26 +20,22 @@ Brzozowski::Brzozowski( const RegExp & re ) : AbstractREtoFAConverter( re ) FSM Brzozowski::convert( void ) { - set<RegExpSymbol> alphabet = RegExpUtils::getRegExpAlphabet( m_re ); + set<RegExpSymbol> alphabet = RegExpAlphabet::getSymbols( m_re ); set<RegExp, RegExpComparator> Q = { m_re }, Qprev = { m_re }, Qcurr; int i = 1; while( true ) { - // std::cout << "Round " << i << std::endl; for( const auto & regexp : Qprev ) { - BrzozowskiDerivative bd( regexp ); + RegExpDerivation deriv( regexp ); 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 ) { - const RegExp re = bd.derivative( list<RegExpElement*>( 1, new RegExpSymbol( symbol.getSymbol( ) ) ) ); - // std::cout << "Podle: " << symbol.getSymbol() << std::endl; - // const_cast<RegExp&>(re).toXML( cout ); + const RegExp re = deriv.derivation( list<RegExpElement*>( 1, new RegExpSymbol( symbol.getSymbol( ) ) ) ); - if( ! RegExpUtils::isRegExpEmpty( re ) ) + if( ! re.isEmpty( ) ) { if( ! isInSet( re, Q ) ) { @@ -59,7 +54,6 @@ FSM Brzozowski::convert( void ) Qprev = Qcurr; Qcurr.clear( ); - // std::cout << "-------------------------------------------------------" << std::endl; i += 1; } @@ -80,7 +74,7 @@ FSM Brzozowski::convert( void ) m_fsm.addInitialState( builder.getState( m_re ) ); for( const auto & r : Q ) - if( RegExpUtils::containsEpsilon( r ) ) + if( r.containsEmptyString( ) ) m_fsm.addFinalState( builder.getState( r ) ); return m_fsm; diff --git a/aconversions/src/conversions/re2fa/Brzozowski.h b/aconversions/src/conversions/re2fa/Brzozowski.h index 9c3306a78460233044e1dd17300786bfd22588db..1cf791f36dd0d52eecccb0f4d1d07649d31b3bda 100644 --- a/aconversions/src/conversions/re2fa/Brzozowski.h +++ b/aconversions/src/conversions/re2fa/Brzozowski.h @@ -16,8 +16,10 @@ #include "AbstractREtoFAConverter.h" #include "RegExpComparator.h" -#include "../../derivatives/BrzozowskiDerivative.h" -#include "../../utils/RegExpUtils.h" +#include "../../utils/utils.h" + +#include "RegExpDerivation.h" +#include "RegExpAlphabet.h" namespace conversions { diff --git a/aconversions/src/conversions/re2fa/Glushkov.cpp b/aconversions/src/conversions/re2fa/Glushkov.cpp index 19a8386285eb8b1a067b9e3e17c9925c76e6d378..0e2543214794549f919ac84ff98ac4748454423c 100644 --- a/aconversions/src/conversions/re2fa/Glushkov.cpp +++ b/aconversions/src/conversions/re2fa/Glushkov.cpp @@ -27,7 +27,7 @@ FSM Glushkov::convert( void ) // step 1 initNumberSymbols( ); - for( const auto & symbol : RegExpUtils::getRegExpAlphabet( m_re ) ) + for( const auto & symbol : RegExpAlphabet::getSymbols( m_re ) ) m_fsm.addInputSymbol( symbol.getSymbol( ) ); // steps 2, 3, 4 @@ -52,7 +52,8 @@ FSM Glushkov::convert( void ) // step 7 for( const auto & ns : m_endSymbolSet ) m_fsm.addFinalState( State ( ns->m_state ) ); - if( RegExpUtils::containsEpsilon( m_regexpRoot ) ) + + if( m_regexpRoot->containsEmptyString( ) ) m_fsm.addFinalState( q0 ); return m_fsm; @@ -113,7 +114,7 @@ const set<RegExpSymbol*> Glushkov::getLeftmostSymbolsInTree( Concatenation * nod const set<RegExpSymbol*> tmp = getLeftmostSymbolsInTree( e ); ret.insert( tmp.begin( ), tmp.end( ) ); - if( ! RegExpUtils::containsEpsilon( e ) ) // If this subtree can be epsilon, then we need to add next subtree also + if( ! e->containsEmptyString( ) ) // If this subtree can be epsilon, then we need to add next subtree also break; } @@ -194,7 +195,7 @@ const set<RegExpSymbol*> Glushkov::getRightmostSymbolsInTree( Concatenation * no const set<RegExpSymbol*> tmp = getRightmostSymbolsInTree( *it ); ret.insert( tmp.begin( ), tmp.end( ) ); - if( ! RegExpUtils::containsEpsilon( *it ) ) + if( ! ( * it )->containsEmptyString( ) ) break; } @@ -293,7 +294,7 @@ const set<pair<const RegExpSymbol*, const RegExpSymbol*>> Glushkov::getNeighbour for( const auto & y : leftmost ) pairs.insert( pair<const RegExpSymbol*, const RegExpSymbol*>( x, y ) ); - if( ! RegExpUtils::containsEpsilon( *f ) ) + if( ! ( * f )->containsEmptyString( ) ) break; } } @@ -336,7 +337,7 @@ void Glushkov::initNumberSymbols( void ) { int iter = 1; - for( const auto & symb : RegExpUtils::getRegExpSymbols( m_re ) ) + for( const auto & symb : RegExpAlphabet::getSymbolsListInOrder( m_re ) ) m_numberedSymbols.insert( NumberedSymbol( symb, iter ++ ) ); } const Glushkov::NumberedSymbol * Glushkov::getNumberedSymbol( const RegExpSymbol * symbol ) const diff --git a/aconversions/src/conversions/re2fa/Glushkov.h b/aconversions/src/conversions/re2fa/Glushkov.h index 61b33a55ea454d3579313f5d22cff0ced4057f1d..096e1f0ae61bc62bf5167b3773b03b6154835308 100644 --- a/aconversions/src/conversions/re2fa/Glushkov.h +++ b/aconversions/src/conversions/re2fa/Glushkov.h @@ -9,17 +9,16 @@ #define GLUSHKOV_H_ #include <map> -#include <string> -#include <sstream> -#include <utility> #include <alphabet/Symbol.h> #include <automaton/State.h> #include <regexp/RegExp.h> #include <AlibException.h> -#include "../../utils/RegExpUtils.h" #include "AbstractREtoFAConverter.h" +#include "../../utils/ConversionException.h" + +#include "RegExpAlphabet.h" namespace conversions { diff --git a/aconversions/src/conversions/re2fa/Makefile b/aconversions/src/conversions/re2fa/Makefile index 501ac0ef7230b818b53fd89d16e771633c575453..a5332abd63f5409678582991a398e726d2bb2c51 100644 --- a/aconversions/src/conversions/re2fa/Makefile +++ b/aconversions/src/conversions/re2fa/Makefile @@ -3,17 +3,17 @@ all: are2fa.glushkov are2fa.brzozowski are2fa.thompson mv are2fa.brzozowski $(BIN_DIR) mv are2fa.thompson $(BIN_DIR) -are2fa.glushkov: are2fa.glushkov.o Glushkov.o AbstractREtoFAConverter.o RegExpUtils.o ConversionException.o +are2fa.glushkov: are2fa.glushkov.o Glushkov.o AbstractREtoFAConverter.o ConversionException.o $(LD) $(LDFLAGS) $^ -o $@ -are2fa.brzozowski: are2fa.brzozowski.o Brzozowski.o AbstractREtoFAConverter.o BrzozowskiDerivative.o ConversionException.o RegExpComparator.o RegExpNormalize.o RegExpUtils.o +are2fa.brzozowski: are2fa.brzozowski.o Brzozowski.o AbstractREtoFAConverter.o ConversionException.o RegExpComparator.o $(LD) $(LDFLAGS) $^ -o $@ -are2fa.thompson: are2fa.thompson.o Thompson.o AbstractREtoFAConverter.o ConversionException.o RegExpUtils.o +are2fa.thompson: are2fa.thompson.o Thompson.o AbstractREtoFAConverter.o ConversionException.o $(LD) $(LDFLAGS) $^ -o $@ -are2fa.brzozowski.o: are2fa.brzozowski.cpp Brzozowski.h ../../derivatives/BrzozowskiDerivative.h ../../derivatives/RegExpNormalize.h AbstractREtoFAConverter.h +are2fa.brzozowski.o: are2fa.brzozowski.cpp Brzozowski.h AbstractREtoFAConverter.h $(CXX) $(CXXFLAGS) $< -o $@ are2fa.glushkov.o: are2fa.glushkov.cpp Glushkov.h AbstractREtoFAConverter.h @@ -39,15 +39,6 @@ Thompson.o: Thompson.cpp Thompson.h AbstractREtoFAConverter.h ../../utils/Conver $(CXX) $(CXXFLAGS) $< -o $@ -BrzozowskiDerivative.o: ../../derivatives/BrzozowskiDerivative.cpp ../../derivatives/BrzozowskiDerivative.h ../../derivatives/RegExpNormalize.h ../../utils/ConversionException.h ../../utils/RegExpUtils.h - $(CXX) $(CXXFLAGS) $< -o $@ - -RegExpNormalize.o: ../../derivatives/RegExpNormalize.cpp ../../derivatives/RegExpNormalize.o ../../utils/RegExpUtils.h - $(CXX) $(CXXFLAGS) $< -o $@ - -RegExpUtils.o: ../../utils/RegExpUtils.cpp ../../utils/RegExpUtils.h ../../utils/utils.h ../../utils/ConversionException.h - $(CXX) $(CXXFLAGS) $< -o $@ - ConversionException.o: ../../utils/ConversionException.cpp ../../utils/ConversionException.h $(CXX) $(CXXFLAGS) $< -o $@ diff --git a/aconversions/src/conversions/re2fa/Thompson.cpp b/aconversions/src/conversions/re2fa/Thompson.cpp index 403ea2c2b5f907b0c04da8f1975490d706f77cf2..5ef1719f2d738c24d8d5c1812494a94d39736b33 100644 --- a/aconversions/src/conversions/re2fa/Thompson.cpp +++ b/aconversions/src/conversions/re2fa/Thompson.cpp @@ -23,7 +23,7 @@ FSM Thompson::convert( void ) RegExp& re = const_cast<RegExp&>(m_re); RegExpElement* treeRoot = re.getRegExp(); - for( const auto & symbol : RegExpUtils::getRegExpAlphabet( m_re ) ) + for( const auto & symbol : RegExpAlphabet::getSymbols( m_re ) ) m_fsm.addInputSymbol( symbol.getSymbol( ) ); SubexpressionTails st = processRegExpNode( treeRoot ); diff --git a/aconversions/src/conversions/re2fa/Thompson.h b/aconversions/src/conversions/re2fa/Thompson.h index 4f1b66d71ccc398259f57f41816fa8fd219969e6..e8d15d0be84ed00d1b5399f7916c8394f78d899e 100644 --- a/aconversions/src/conversions/re2fa/Thompson.h +++ b/aconversions/src/conversions/re2fa/Thompson.h @@ -8,8 +8,10 @@ #ifndef THOMPSON_H_ #define THOMPSON_H_ -#include <automaton/FSM/FSM.h> +#include <set> +#include <vector> +#include <automaton/FSM/FSM.h> #include <regexp/RegExp.h> #include <regexp/RegExpElement.h> #include <regexp/Alternation.h> @@ -17,13 +19,10 @@ #include <regexp/Iteration.h> #include <regexp/RegExpSymbol.h> -#include "../../utils/RegExpUtils.h" +#include "AbstractREtoFAConverter.h" #include "../../utils/ConversionException.h" -#include <set> -#include <vector> - -#include "AbstractREtoFAConverter.h" +#include "RegExpAlphabet.h" namespace conversions { diff --git a/aconversions/src/derivatives/BrzozowskiDerivative.cpp b/aconversions/src/derivatives/BrzozowskiDerivative.cpp deleted file mode 100644 index b96be33ba812d1327d28e0e0102b0b5e280caf88..0000000000000000000000000000000000000000 --- a/aconversions/src/derivatives/BrzozowskiDerivative.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * BrzozowskiDerivative.cpp - * - * Created on: 19. 1. 2014 - * Author: tomas - */ - -#include "BrzozowskiDerivative.h" -#include <iostream> - -using namespace regexp; -using namespace std; - -namespace conversions -{ - -BrzozowskiDerivative::BrzozowskiDerivative( const RegExp & re ) : m_re( re ) -{ - //FIXME in alib! - RegExpNormalize norm; - m_regexpRoot = const_cast<RegExp&>( m_re ).getRegExp( ); - - m_reNorm.setRegExp( norm.normalize( m_regexpRoot ) ); - m_regexpRoot = m_reNorm.getRegExp( ); - - // const_cast<RegExp&>(m_reNorm).toXML( cout ); -} - -RegExp BrzozowskiDerivative::derivative ( const list<RegExpElement*> & dString ) const -{ - RegExpElement * expression = m_regexpRoot; - - for( const auto & dSymbol : dString ) // dV/d(ab) = d( dV/da )/db - { - // FIXME: memory leak - if( dynamic_cast<RegExpEpsilon*>( dSymbol ) ) - expression = expression->clone( ); - - else if( dynamic_cast<RegExpSymbol*>( dSymbol ) ) - expression = derivative( expression, * dynamic_cast<RegExpSymbol*>( dSymbol ) ); - - else - throw ConversionException( "BrzozowskiDerivative::derivative - invalid/unknown RegExpElement node passed in dString." ); - } - - RegExpNormalize norm; - return RegExp( norm.normalize( expression ) ); -} - -RegExpElement * BrzozowskiDerivative::derivative( RegExpElement * node, const RegExpSymbol & dSymbol ) const -{ - Alternation * alternation = dynamic_cast<Alternation*>( node ); - Concatenation * concatenation = dynamic_cast<Concatenation*>( node ); - Iteration * iteration = dynamic_cast<Iteration*>( node ); - RegExpSymbol * symbol = dynamic_cast<RegExpSymbol*>( node ); - RegExpEpsilon * eps = dynamic_cast<RegExpEpsilon*>( node ); - RegExpEmpty * empty = dynamic_cast<RegExpEmpty*>( node ); - - if( alternation ) - return derivative( alternation, dSymbol ); - if( concatenation ) - return derivative( concatenation, dSymbol); - if( iteration ) - return derivative( iteration, dSymbol ); - if( symbol ) - return derivative( symbol, dSymbol ); - if( eps ) - return derivative( eps, dSymbol ); - if( empty ) - return derivative( empty, dSymbol ); - - throw ConversionException( "BrzozowskiDerivative::derivative() - unknown RegExpElement node" ); -} - -RegExpElement * BrzozowskiDerivative::derivative( Alternation * element, const RegExpSymbol & dSymbol ) const -{ - Alternation* ret = new Alternation( ); - list<RegExpElement*> & retElements = ret->getElements( ); - - for( const auto & e : element->getElements( ) ) - retElements.push_back( derivative( e, dSymbol ) ); - - return ret; -} - -RegExpElement * BrzozowskiDerivative::derivative( Concatenation * element, const RegExpSymbol & dSymbol ) const -{ - Alternation* alt = new Alternation( ); - list<RegExpElement*> & altElements = alt->getElements( ); - - for( auto elem = element->getElements( ).begin( ); elem != element->getElements( ).end( ); elem ++ ) - { - Concatenation* concat = new Concatenation( ); - list<RegExpElement*> & concatElements = concat->getElements( ); - - concatElements.push_back( derivative( * elem, dSymbol ) ); - - auto succeedingElem = elem; - while( ++ succeedingElem != element->getElements( ).end( ) ) - concatElements.push_back( ( * succeedingElem )->clone( ) ); - - altElements.push_back( concat ); - - if( ! RegExpUtils::containsEpsilon( * elem ) ) - break; - } - - return alt; -} - -RegExpElement * BrzozowskiDerivative::derivative( Iteration * element, const RegExpSymbol & dSymbol ) const -{ - Concatenation* ret = new Concatenation( ); - list<RegExpElement*> & retElements = ret->getElements(); - - retElements.push_back( derivative( element->getElement( ), dSymbol ) ); - retElements.push_back( element->clone( ) ); - - return ret; -} - -RegExpElement * BrzozowskiDerivative::derivative( RegExpSymbol * element, const RegExpSymbol & dSymbol ) const -{ - if( dSymbol == element->getSymbol( ) ) - return new RegExpEpsilon( ); - else - return new RegExpEmpty( ); -} - -RegExpElement * BrzozowskiDerivative::derivative( RegExpEpsilon * element, const RegExpSymbol & dSymbol ) const -{ - return new RegExpEmpty( ); -} - -RegExpElement * BrzozowskiDerivative::derivative( RegExpEmpty * element, const RegExpSymbol & dSymbol ) const -{ - return new RegExpEmpty( ); -} - -} /* namespace conversions */ diff --git a/aconversions/src/derivatives/BrzozowskiDerivative.h b/aconversions/src/derivatives/BrzozowskiDerivative.h deleted file mode 100644 index 135bdf4aff01fac4d7c3064eb3245b680f803b69..0000000000000000000000000000000000000000 --- a/aconversions/src/derivatives/BrzozowskiDerivative.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * BrzozowskiDerivative.h - * - * Created on: 19. 1. 2014 - * Author: tomas - */ - -#ifndef BRZOZOWSKIDERIVATIVE_H_ -#define BRZOZOWSKIDERIVATIVE_H_ - -#include <regexp/RegExp.h> -#include <regexp/RegExpElement.h> -#include <regexp/Alternation.h> -#include <regexp/Concatenation.h> -#include <regexp/Iteration.h> -#include <regexp/RegExpSymbol.h> -#include <regexp/RegExpEmpty.h> -#include <regexp/RegExpEpsilon.h> - -#include <list> - -#include "RegExpNormalize.h" -#include "../utils/ConversionException.h" -#include "../utils/RegExpUtils.h" - -namespace conversions -{ - -/** - * Calculates derivative of regular expression re by string passed in derivative( ). - * Sources: - * - Melichar, definition 2.91 in chapter 2.4.3 - * - Brzozowski, J. A. - Derivatives of regular expressions (1964) - */ -class BrzozowskiDerivative -{ -public: - BrzozowskiDerivative( const regexp::RegExp & re ); - regexp::RegExp derivative ( const std::list<regexp::RegExpElement*> & dString ) const; - -private: - regexp::RegExpElement * derivative( regexp::RegExpElement * element, const regexp::RegExpSymbol & dSymbol ) const; - regexp::RegExpElement * derivative( regexp::Alternation * element, const regexp::RegExpSymbol & dSymbol ) const; - regexp::RegExpElement * derivative( regexp::Concatenation * element, const regexp::RegExpSymbol & dSymbol ) const; - regexp::RegExpElement * derivative( regexp::Iteration * element, const regexp::RegExpSymbol & dSymbol ) const; - regexp::RegExpElement * derivative( regexp::RegExpSymbol * element, const regexp::RegExpSymbol & dSymbol ) const; - regexp::RegExpElement * derivative( regexp::RegExpEpsilon * element, const regexp::RegExpSymbol & dSymbol ) const; - regexp::RegExpElement * derivative( regexp::RegExpEmpty * element, const regexp::RegExpSymbol & dSymbol ) const; - - const regexp::RegExp & m_re; - regexp::RegExp m_reNorm; - regexp::RegExpElement* m_regexpRoot; -}; - -} /* namespace conversions */ - -#endif /* BRZOZOWSKIDERIVATIVE_H_ */ diff --git a/aconversions/src/derivatives/Makefile b/aconversions/src/derivatives/Makefile deleted file mode 100644 index 9483ace132c9de2a69d64458b18d6928a7fbc450..0000000000000000000000000000000000000000 --- a/aconversions/src/derivatives/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -all: aderivative - mv aderivative $(BIN_DIR) - -aderivative: aderivative.o BrzozowskiDerivative.o RegExpNormalize.o ConversionException.o RegExpUtils.o - $(LD) $(LDFLAGS) $^ -o aderivative - - -aderivative.o: aderivative.cpp BrzozowskiDerivative.h - $(CXX) $(CXXFLAGS) $< -o $@ - -BrzozowskiDerivative.o: BrzozowskiDerivative.cpp BrzozowskiDerivative.h RegExpNormalize.h ../utils/RegExpUtils.h - $(CXX) $(CXXFLAGS) $< -o $@ - -RegExpNormalize.o: RegExpNormalize.cpp RegExpNormalize.h ../utils/ConversionException.h ../utils/RegExpUtils.h - $(CXX) $(CXXFLAGS) $< -o $@ - -ConversionException.o: ../utils/ConversionException.cpp ../utils/ConversionException.h - $(CXX) $(CXXFLAGS) $< -o $@ - -RegExpUtils.o: ../utils/RegExpUtils.cpp ../utils/RegExpUtils.h - $(CXX) $(CXXFLAGS) $< -o $@ - - -.PHONY: clean -clean: - rm -f *.o diff --git a/aconversions/src/utils/RegExpUtils.cpp b/aconversions/src/utils/RegExpUtils.cpp deleted file mode 100644 index 431ba67ba83d8def4937871cec2ce8731ab288f0..0000000000000000000000000000000000000000 --- a/aconversions/src/utils/RegExpUtils.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include "RegExpUtils.h" - -#include<iostream> - -using namespace alphabet; -using namespace regexp; -using namespace std; - -namespace conversions -{ - -bool RegExpUtils::isRegExpEmpty( const RegExp & re ) -{ - return dynamic_cast<RegExpEmpty*>( const_cast<RegExp&>( re ).getRegExp( ) ) != NULL; -} - -set<RegExpSymbol> RegExpUtils::getRegExpAlphabet( const RegExp & re ) -{ - set<RegExpSymbol> alphabet; - - for( const auto & symbol : getRegExpSymbols( re ) ) - alphabet.insert( RegExpSymbol( symbol->getSymbol( ) ) ); - - return alphabet; -} - -list<RegExpSymbol*> RegExpUtils::getRegExpSymbols( const RegExp & re ) -{ - // returning list to preserver ordering of symbols in the regexp tree ( used in re2fa.Glushkov symbol numbering ) - list<RegExpSymbol*> alphabet; - traverseSymbols( const_cast<RegExp&>( re ).getRegExp( ), alphabet ); - return alphabet; -} - - -void RegExpUtils::traverseSymbols( RegExpElement * node, list<RegExpSymbol*> & alphabet ) -{ - Alternation* alternation = dynamic_cast<Alternation*>( node ); - Concatenation* concatenation = dynamic_cast<Concatenation*>( node ); - Iteration* iteration = dynamic_cast<Iteration*>( node ); - RegExpSymbol* symbol = dynamic_cast<RegExpSymbol*>( node ); - RegExpEmpty * empty = dynamic_cast<RegExpEmpty*>( node ); - RegExpEpsilon* eps = dynamic_cast<RegExpEpsilon*>( node ); - - if( symbol ) - { - alphabet.push_back( symbol ); - return; - } - - else if( alternation ) - { - for( const auto & element : alternation->getElements() ) - traverseSymbols( element, alphabet ); - return; - } - - else if( concatenation ) - { - for( const auto & element : concatenation->getElements() ) - traverseSymbols( element, alphabet ); - return; - } - - else if( iteration ) - { - traverseSymbols( iteration->getElement(), alphabet ); - return; - } - - else if( empty ) - return; - - else if( eps ) - return; - - - throw ConversionException( "RegExpUtils::traverseSymbols() - unknown RegExpElement node" ); -} - -// ---------------------------------------------------------------------------- - -bool RegExpUtils::containsEpsilon( const RegExp & re ) -{ - return containsEpsilon( const_cast<RegExp&>( re ).getRegExp( ) ); -} - -bool RegExpUtils::containsEpsilon( RegExpElement * node ) -{ - Alternation* alternation = dynamic_cast<Alternation*>( node ); - Concatenation* concatenation = dynamic_cast<Concatenation*>( node ); - Iteration* iteration = dynamic_cast<Iteration*>( node ); - RegExpSymbol* symbol = dynamic_cast<RegExpSymbol*>( node ); - RegExpEmpty * empty = dynamic_cast<RegExpEmpty*>( node ); - RegExpEpsilon* eps = dynamic_cast<RegExpEpsilon*>( node ); - - if( alternation ) - return containsEpsilon( alternation ); - if( concatenation ) - return containsEpsilon( concatenation ); - if( iteration ) - return containsEpsilon( iteration ); - if( symbol ) - return containsEpsilon( symbol ); - if( empty ) - return containsEpsilon( empty ); - if( eps ) - return containsEpsilon( eps ); - - throw ConversionException( "RegExpUtils::containsEpsilon() - unknown RegExpElement node" ); -} - -bool RegExpUtils::containsEpsilon( Alternation * node ) -{ - for( const auto & e : node->getElements( ) ) - if( containsEpsilon( e ) ) - return true; - - return false; -} - -bool RegExpUtils::containsEpsilon( Concatenation * node ) -{ - for( const auto & e : node->getElements( ) ) - if( ! containsEpsilon( e ) ) - return false; - - return true; -} - -bool RegExpUtils::containsEpsilon( Iteration * node ) -{ - return true; -} - -bool RegExpUtils::containsEpsilon( RegExpSymbol * node ) -{ - // backwards compatibility for alib versions without RegExpEpsilon - if( node->getSymbol( ) == "" ) - return true; - - return false; -} - -bool RegExpUtils::containsEpsilon( RegExpEmpty * element ) -{ - return false; -} - -bool RegExpUtils::containsEpsilon( RegExpEpsilon * element ) -{ - return true; -} - -} /* namespace conversions */ diff --git a/aconversions/src/utils/RegExpUtils.h b/aconversions/src/utils/RegExpUtils.h deleted file mode 100644 index a2b459da8338bf77f644be2130aee026d596c73a..0000000000000000000000000000000000000000 --- a/aconversions/src/utils/RegExpUtils.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef REGEXPUTILS_H_ -#define REGEXPUTILS_H_ - -#include <regexp/RegExp.h> -#include <regexp/RegExpElement.h> -#include <regexp/Alternation.h> -#include <regexp/Concatenation.h> -#include <regexp/Iteration.h> -#include <regexp/RegExpSymbol.h> -#include <regexp/RegExpEmpty.h> -#include <regexp/RegExpEpsilon.h> - -#include <list> -#include <set> - -#include "utils.h" -#include "ConversionException.h" - -namespace conversions -{ - -class RegExpUtils -{ -public: - static std::list<regexp::RegExpSymbol*> getRegExpSymbols( const regexp::RegExp & re ); - static std::set<regexp::RegExpSymbol> getRegExpAlphabet( const regexp::RegExp & re ); - - static bool containsEpsilon( regexp::RegExpElement * node ); - static bool containsEpsilon( const regexp::RegExp & re ); - - static bool isRegExpEmpty( const regexp::RegExp & re ); - -private: - static void traverseSymbols( regexp::RegExpElement * element, std::list<regexp::RegExpSymbol*> & alphabet ); - - static bool containsEpsilon( regexp::Alternation * node ); - static bool containsEpsilon( regexp::Concatenation * node ); - static bool containsEpsilon( regexp::Iteration * node ); - static bool containsEpsilon( regexp::RegExpSymbol * node ); - static bool containsEpsilon( regexp::RegExpEmpty * node ); - static bool containsEpsilon( regexp::RegExpEpsilon * node ); -}; - -} /* namespace conversions */ - -#endif /* GRAMMARUTILS_H_ */ diff --git a/aderivation/.cproject b/aderivation/.cproject new file mode 100644 index 0000000000000000000000000000000000000000..e389bb986f94b215a5afb7f896a9ff99174f18eb --- /dev/null +++ b/aderivation/.cproject @@ -0,0 +1,128 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> + <storageModule moduleId="org.eclipse.cdt.core.settings"> + <cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.2000389846"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.2000389846" moduleId="org.eclipse.cdt.core.settings" name="Debug"> + <externalSettings/> + <extensions> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.2000389846" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug"> + <folderInfo id="cdt.managedbuild.config.gnu.exe.debug.2000389846." name="/" resourcePath=""> + <toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1224933308" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug"> + <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.448613666" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/> + <builder buildPath="${workspace_loc:/aderivation}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.283963047" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/> + <tool id="cdt.managedbuild.tool.gnu.archiver.base.1221143539" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.559647916" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug"> + <option id="gnu.cpp.compiler.exe.debug.option.optimization.level.835066855" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/> + <option id="gnu.cpp.compiler.exe.debug.option.debugging.level.1525375087" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/> + <option id="gnu.cpp.compiler.option.include.paths.5360094" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath"> + <listOptionValue builtIn="false" value="/usr/include/libxml2"/> + <listOptionValue builtIn="false" value=""${workspace_loc:/libaderivation/src}""/> + <listOptionValue builtIn="false" value=""${workspace_loc:/alib/src}""/> + </option> + <option id="gnu.cpp.compiler.option.other.other.1115974193" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0 -std=c++11" valueType="string"/> + <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.912106636" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1888370304" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug"> + <option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.456423980" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" valueType="enumerated"/> + <option id="gnu.c.compiler.exe.debug.option.debugging.level.37814299" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1446459783" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.1861153242" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.620062018" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug"> + <option id="gnu.cpp.link.option.libs.136272860" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs"> + <listOptionValue builtIn="false" value="alib"/> + <listOptionValue builtIn="false" value="aderivations"/> + </option> + <option id="gnu.cpp.link.option.paths.1079549577" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths"> + <listOptionValue builtIn="false" value=""${workspace_loc:/alib/lib}""/> + <listOptionValue builtIn="false" value=""${workspace_loc:/libaderivation/lib}""/> + </option> + <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.509215795" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.832858679" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug"> + <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1118953191" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + <cconfiguration id="cdt.managedbuild.config.gnu.exe.release.1131291881"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1131291881" moduleId="org.eclipse.cdt.core.settings" name="Release"> + <externalSettings/> + <extensions> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.1131291881" name="Release" parent="cdt.managedbuild.config.gnu.exe.release"> + <folderInfo id="cdt.managedbuild.config.gnu.exe.release.1131291881." name="/" resourcePath=""> + <toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.1816455577" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release"> + <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.398359620" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/> + <builder buildPath="${workspace_loc:/aderivation}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.1339041658" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/> + <tool id="cdt.managedbuild.tool.gnu.archiver.base.330305112" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.387222562" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release"> + <option id="gnu.cpp.compiler.exe.release.option.optimization.level.624866051" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/> + <option id="gnu.cpp.compiler.exe.release.option.debugging.level.1534206649" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.101044315" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.1256207513" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release"> + <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.730984370" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/> + <option id="gnu.c.compiler.exe.release.option.debugging.level.743767829" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.486815690" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.969510604" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.963125953" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release"> + <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.87031727" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.1486323163" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release"> + <inputType id="cdt.managedbuild.tool.gnu.assembler.input.764663233" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <project id="aderivation.cdt.managedbuild.target.gnu.exe.1934873412" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/> + </storageModule> + <storageModule moduleId="scannerConfiguration"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.2000389846;cdt.managedbuild.config.gnu.exe.debug.2000389846.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.559647916;cdt.managedbuild.tool.gnu.cpp.compiler.input.912106636"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1131291881;cdt.managedbuild.config.gnu.exe.release.1131291881.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.1256207513;cdt.managedbuild.tool.gnu.c.compiler.input.486815690"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1131291881;cdt.managedbuild.config.gnu.exe.release.1131291881.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.387222562;cdt.managedbuild.tool.gnu.cpp.compiler.input.101044315"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.2000389846;cdt.managedbuild.config.gnu.exe.debug.2000389846.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1888370304;cdt.managedbuild.tool.gnu.c.compiler.input.1446459783"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> +</cproject> diff --git a/aderivation/.project b/aderivation/.project new file mode 100644 index 0000000000000000000000000000000000000000..c71429a43aa7c096f3cb1e35a3ac502714bf2abb --- /dev/null +++ b/aderivation/.project @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>aderivation</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> + <triggers>clean,full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.cdt.core.cnature</nature> + <nature>org.eclipse.cdt.core.ccnature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> + </natures> +</projectDescription> diff --git a/aderivation/makefile b/aderivation/makefile new file mode 100644 index 0000000000000000000000000000000000000000..e5dc1b8239f33786fac60968d2918c5250a3be38 --- /dev/null +++ b/aderivation/makefile @@ -0,0 +1,20 @@ +CC=g++ +EXECUTABLE=aderivation +CCFLAGS= -std=c++11 -O2 -c -Wall -I/usr/include/libxml2 -I../alib/src -I../libaderivation/src -I../libaregexptree/src +LDFLAGS= -L../alib/lib -L../libaderivation/lib -lxml2 -lalib -laderivation -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/aconversions/src/derivatives/aderivative.cpp b/aderivation/src/aderivation.cpp similarity index 83% rename from aconversions/src/derivatives/aderivative.cpp rename to aderivation/src/aderivation.cpp index fb4d9d707a66fdf8f9084c9a91990ef7998bf2bc..42f17adbc377aed89841e02e76e8d3324c8910a2 100644 --- a/aconversions/src/derivatives/aderivative.cpp +++ b/aderivation/src/aderivation.cpp @@ -1,5 +1,4 @@ #include <iostream> -#include <string> #include <AlibException.h> #include <regexp/RegExp.h> @@ -7,18 +6,16 @@ #include <regexp/RegExpSymbol.h> #include <sax/SaxInterface.h> -#include "BrzozowskiDerivative.h" +#include "RegExpDerivation.h" using namespace alib; -using namespace conversions; using namespace regexp; using namespace std; /* * Usage: * aderivative "a" "b" "cc" < regexp.xml - * ; aderivative regexp.xml "a" "b" "cc" */ int main(int argc, char** argv) @@ -40,8 +37,8 @@ int main(int argc, char** argv) else dString.push_back( new RegExpSymbol( symbol ) ); } - BrzozowskiDerivative d( re ); - d.derivative( dString ).toXML( cout ); + RegExpDerivation d( re ); + d.derivation( dString ).toXML( cout ); } catch( AlibException & e ) { diff --git a/libaderivation/.cproject b/libaderivation/.cproject new file mode 100644 index 0000000000000000000000000000000000000000..4f781ae58695a96fc60a2fe25d6d07628b6f7a27 --- /dev/null +++ b/libaderivation/.cproject @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> + <storageModule moduleId="org.eclipse.cdt.core.settings"> + <cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.1344749464"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.1344749464" moduleId="org.eclipse.cdt.core.settings" name="Debug"> + <externalSettings/> + <extensions> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.1344749464" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug"> + <folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1344749464." name="/" resourcePath=""> + <toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1688408127" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug"> + <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.2130198537" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/> + <builder buildPath="${workspace_loc:/aderivation}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.2119116171" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/> + <tool id="cdt.managedbuild.tool.gnu.archiver.base.1352200263" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1545173980" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug"> + <option id="gnu.cpp.compiler.exe.debug.option.optimization.level.651271958" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/> + <option id="gnu.cpp.compiler.exe.debug.option.debugging.level.341039959" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/> + <option id="gnu.cpp.compiler.option.include.paths.130703207" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath"> + <listOptionValue builtIn="false" value=""${workspace_loc:/alib/src}""/> + <listOptionValue builtIn="false" value=""${workspace_loc:/libaregexptree/src}""/> + <listOptionValue builtIn="false" value="/usr/include/libxml2"/> + </option> + <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1175408198" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1264646230" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug"> + <option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.323658724" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" valueType="enumerated"/> + <option id="gnu.c.compiler.exe.debug.option.debugging.level.1418485353" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1589237851" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.1738778745" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.1860251774" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug"> + <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.583727594" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.1837879655" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug"> + <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1146407047" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + <cconfiguration id="cdt.managedbuild.config.gnu.exe.release.359931095"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.359931095" moduleId="org.eclipse.cdt.core.settings" name="Release"> + <externalSettings/> + <extensions> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.359931095" name="Release" parent="cdt.managedbuild.config.gnu.exe.release"> + <folderInfo id="cdt.managedbuild.config.gnu.exe.release.359931095." name="/" resourcePath=""> + <toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.1652261549" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release"> + <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.623690363" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/> + <builder buildPath="${workspace_loc:/aderivation}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.91164453" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/> + <tool id="cdt.managedbuild.tool.gnu.archiver.base.1046466550" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.966608876" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release"> + <option id="gnu.cpp.compiler.exe.release.option.optimization.level.1531126373" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/> + <option id="gnu.cpp.compiler.exe.release.option.debugging.level.299546950" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1656318683" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.745334853" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release"> + <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.1463290351" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/> + <option id="gnu.c.compiler.exe.release.option.debugging.level.61088191" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1546874327" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.440230600" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.1864756601" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release"> + <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.2061831193" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.95319577" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release"> + <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1301876212" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <project id="aderivation.cdt.managedbuild.target.gnu.exe.1473902764" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/> + </storageModule> + <storageModule moduleId="scannerConfiguration"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1344749464;cdt.managedbuild.config.gnu.exe.debug.1344749464.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1545173980;cdt.managedbuild.tool.gnu.cpp.compiler.input.1175408198"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.359931095;cdt.managedbuild.config.gnu.exe.release.359931095.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.745334853;cdt.managedbuild.tool.gnu.c.compiler.input.1546874327"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.1344749464;cdt.managedbuild.config.gnu.exe.debug.1344749464.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1264646230;cdt.managedbuild.tool.gnu.c.compiler.input.1589237851"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.359931095;cdt.managedbuild.config.gnu.exe.release.359931095.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.966608876;cdt.managedbuild.tool.gnu.cpp.compiler.input.1656318683"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> +</cproject> diff --git a/libaderivation/.project b/libaderivation/.project new file mode 100644 index 0000000000000000000000000000000000000000..f8c12f067eff72294b6b18cfebb13d423357680c --- /dev/null +++ b/libaderivation/.project @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>libaderivation</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> + <triggers>clean,full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.cdt.core.cnature</nature> + <nature>org.eclipse.cdt.core.ccnature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> + </natures> +</projectDescription> diff --git a/libaderivation/makefile b/libaderivation/makefile new file mode 100644 index 0000000000000000000000000000000000000000..89cb637976f03019547b4483b0b6dbf3c43c9640 --- /dev/null +++ b/libaderivation/makefile @@ -0,0 +1,20 @@ +CC=g++ +LIBRARY=libaderivation.so +CCFLAGS= -std=c++11 -O2 -c -Wall -fPIC -I../alib/src -I../libaregexptree/src +LDFLAGS= -L../alib/lib -shared + +SOURCES=$(shell find src/ -name *cpp) +OBJECTS=$(patsubst src/%.cpp, obj/%.o, $(SOURCES)) + +all: $(SOURCES) lib/$(LIBRARY) + +lib/$(LIBRARY): $(OBJECTS) + mkdir -p lib + $(CC) $(OBJECTS) -o $@ $(LDFLAGS) + +obj/%.o: src/%.cpp + mkdir -p $(dir $@) + $(CC) $(CCFLAGS) $< -o $@ + +clean: + $(RM) -r *.o *.d lib obj diff --git a/libaderivation/src/RegExpDerivation.cpp b/libaderivation/src/RegExpDerivation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d78f6f7101a5efe898a4d464c2828596915d6fcd --- /dev/null +++ b/libaderivation/src/RegExpDerivation.cpp @@ -0,0 +1,123 @@ +/* + * RegExpDerivation.cpp + * + * Created on: 19. 1. 2014 + * Author: tomas + */ + +#include "RegExpDerivation.h" + +using namespace alib; +using namespace regexp; +using namespace std; + +RegExpDerivation::RegExpDerivation( const RegExp & re ) : m_re( re ) +{ + +} + +RegExp RegExpDerivation::derivation ( const list<RegExpElement*> & dString ) const +{ + RegExpElement * expression = const_cast<RegExp&>( m_re ).getRegExp( ); + + // dV/d(ab) = d( dV/da )/db + for( const auto & dSymbol : dString ) + { + // FIXME: memory leak + if( dynamic_cast<RegExpEpsilon*>( dSymbol ) ) + expression = expression->clone( ); + + else if( dynamic_cast<RegExpSymbol*>( dSymbol ) ) + expression = derivation( expression, * dynamic_cast<RegExpSymbol*>( dSymbol ) ); + + else + throw AlibException( "RegExpDerivation::derivation - invalid/unknown RegExpElement passed in dString." ); + } + + return RegExp( expression ); +} + +RegExpElement * RegExpDerivation::derivation( RegExpElement * node, const RegExpSymbol & dSymbol ) const +{ + Alternation * alternation = dynamic_cast<Alternation*>( node ); + Concatenation * concatenation = dynamic_cast<Concatenation*>( node ); + Iteration * iteration = dynamic_cast<Iteration*>( node ); + RegExpSymbol * symbol = dynamic_cast<RegExpSymbol*>( node ); + RegExpEpsilon * eps = dynamic_cast<RegExpEpsilon*>( node ); + RegExpEmpty * empty = dynamic_cast<RegExpEmpty*>( node ); + + if( alternation ) + return derivation( alternation, dSymbol ); + if( concatenation ) + return derivation( concatenation, dSymbol); + if( iteration ) + return derivation( iteration, dSymbol ); + if( symbol ) + return derivation( symbol, dSymbol ); + if( eps ) + return derivation( eps, dSymbol ); + if( empty ) + return derivation( empty, dSymbol ); + + throw AlibException( "RegExpDerivation::derivation() - unknown RegExpElement node" ); +} + +RegExpElement * RegExpDerivation::derivation( Alternation * element, const RegExpSymbol & dSymbol ) const +{ + Alternation* ret = new Alternation( ); + + for( const auto & e : element->getElements( ) ) + ret->getElements( ).push_back( derivation( e, dSymbol ) ); + + return ret; +} + +RegExpElement * RegExpDerivation::derivation( Concatenation * element, const RegExpSymbol & dSymbol ) const +{ + Alternation* alt = new Alternation( ); + + for( auto elem = element->getElements( ).begin( ); elem != element->getElements( ).end( ); elem ++ ) + { + Concatenation* concat = new Concatenation( ); + concat->getElements( ).push_back( derivation( * elem, dSymbol ) ); + + auto succeedingElem = elem; + while( ++ succeedingElem != element->getElements( ).end( ) ) + concat->getElements( ).push_back( ( * succeedingElem )->clone( ) ); + + alt->getElements( ).push_back( concat ); + + if( ! ( * elem )->containsEmptyString( ) ) + break; + } + + return alt; +} + +RegExpElement * RegExpDerivation::derivation( Iteration * element, const RegExpSymbol & dSymbol ) const +{ + Concatenation* ret = new Concatenation( ); + + ret->getElements( ).push_back( derivation( element->getElement( ), dSymbol ) ); + ret->getElements( ).push_back( element->clone( ) ); + + return ret; +} + +RegExpElement * RegExpDerivation::derivation( RegExpSymbol * element, const RegExpSymbol & dSymbol ) const +{ + if( dSymbol == element->getSymbol( ) ) + return new RegExpEpsilon( ); + else + return new RegExpEmpty( ); +} + +RegExpElement * RegExpDerivation::derivation( RegExpEpsilon * element, const RegExpSymbol & dSymbol ) const +{ + return new RegExpEmpty( ); +} + +RegExpElement * RegExpDerivation::derivation( RegExpEmpty * element, const RegExpSymbol & dSymbol ) const +{ + return new RegExpEmpty( ); +} diff --git a/libaderivation/src/RegExpDerivation.h b/libaderivation/src/RegExpDerivation.h new file mode 100644 index 0000000000000000000000000000000000000000..2881e23725ed57d2070c14fc3da46ff0996af916 --- /dev/null +++ b/libaderivation/src/RegExpDerivation.h @@ -0,0 +1,50 @@ +/* + * RegExpDerivation.h + * + * Created on: 19. 1. 2014 + * Author: tomas + */ + +#ifndef REGEXPDERIVATION_H_ +#define REGEXPDERIVATION_H_ + +#include <regexp/RegExp.h> +#include <regexp/RegExpElement.h> +#include <regexp/Alternation.h> +#include <regexp/Concatenation.h> +#include <regexp/Iteration.h> +#include <regexp/RegExpSymbol.h> +#include <regexp/RegExpEmpty.h> +#include <regexp/RegExpEpsilon.h> + +#include <AlibException.h> + +#include <list> + + +/** + * 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: + RegExpDerivation( const regexp::RegExp & re ); + regexp::RegExp derivation( const std::list<regexp::RegExpElement*> & dString ) const; + +private: + regexp::RegExpElement * derivation( regexp::RegExpElement * element, const regexp::RegExpSymbol & dSymbol ) const; + regexp::RegExpElement * derivation( regexp::Alternation * element, const regexp::RegExpSymbol & dSymbol ) const; + regexp::RegExpElement * derivation( regexp::Concatenation * element, const regexp::RegExpSymbol & dSymbol ) const; + regexp::RegExpElement * derivation( regexp::Iteration * element, const regexp::RegExpSymbol & dSymbol ) const; + regexp::RegExpElement * derivation( regexp::RegExpSymbol * element, const regexp::RegExpSymbol & dSymbol ) const; + regexp::RegExpElement * derivation( regexp::RegExpEpsilon * element, const regexp::RegExpSymbol & dSymbol ) const; + regexp::RegExpElement * derivation( regexp::RegExpEmpty * element, const regexp::RegExpSymbol & dSymbol ) const; + + const regexp::RegExp & m_re; +}; + +#endif /* REGEXPDERIVATION_H_ */ diff --git a/libaregexptree/.cproject b/libaregexptree/.cproject new file mode 100644 index 0000000000000000000000000000000000000000..ba16bd787df8a08c6d4ec38f035850e29f6c52df --- /dev/null +++ b/libaregexptree/.cproject @@ -0,0 +1,153 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> + <storageModule moduleId="org.eclipse.cdt.core.settings"> + <cconfiguration id="cdt.managedbuild.config.gnu.so.debug.1383098863"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.so.debug.1383098863" moduleId="org.eclipse.cdt.core.settings" name="Debug"> + <externalSettings> + <externalSetting> + <entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/libaregexptree"/> + <entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/libaregexptree/Debug"/> + <entry flags="RESOLVED" kind="libraryFile" name="libaregexptree" srcPrefixMapping="" srcRootPath=""/> + </externalSetting> + </externalSettings> + <extensions> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactExtension="so" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.so.debug.1383098863" name="Debug" parent="cdt.managedbuild.config.gnu.so.debug"> + <folderInfo id="cdt.managedbuild.config.gnu.so.debug.1383098863." name="/" resourcePath=""> + <toolChain id="cdt.managedbuild.toolchain.gnu.so.debug.1778678337" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.so.debug"> + <targetPlatform id="cdt.managedbuild.target.gnu.platform.so.debug.2130070537" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.so.debug"/> + <builder buildPath="${workspace_loc:/libaregexptree}/Debug" id="cdt.managedbuild.target.gnu.builder.so.debug.560781392" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.so.debug"/> + <tool id="cdt.managedbuild.tool.gnu.archiver.base.1660251016" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.so.debug.2082487370" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.so.debug"> + <option id="gnu.cpp.compiler.so.debug.option.optimization.level.1584304578" name="Optimization Level" superClass="gnu.cpp.compiler.so.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/> + <option id="gnu.cpp.compiler.so.debug.option.debugging.level.1455781484" name="Debug Level" superClass="gnu.cpp.compiler.so.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/> + <option id="gnu.cpp.compiler.option.include.paths.963055854" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath"> + <listOptionValue builtIn="false" value=""${workspace_loc:/alib/src}""/> + </option> + <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1152650017" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.compiler.so.debug.407077523" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.so.debug"> + <option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.so.debug.option.optimization.level.1759140872" name="Optimization Level" superClass="gnu.c.compiler.so.debug.option.optimization.level" valueType="enumerated"/> + <option id="gnu.c.compiler.so.debug.option.debugging.level.161895308" name="Debug Level" superClass="gnu.c.compiler.so.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1141545811" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.linker.so.debug.692555773" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.so.debug"> + <option defaultValue="true" id="gnu.c.link.so.debug.option.shared.775399741" name="Shared (-shared)" superClass="gnu.c.link.so.debug.option.shared" valueType="boolean"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.cpp.linker.so.debug.1539492262" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.so.debug"> + <option defaultValue="true" id="gnu.cpp.link.so.debug.option.shared.467224581" name="Shared (-shared)" superClass="gnu.cpp.link.so.debug.option.shared" valueType="boolean"/> + <option id="gnu.cpp.link.option.libs.2108554519" superClass="gnu.cpp.link.option.libs" valueType="libs"> + <listOptionValue builtIn="false" value="alib"/> + </option> + <option id="gnu.cpp.link.option.paths.1041404365" superClass="gnu.cpp.link.option.paths" valueType="libPaths"> + <listOptionValue builtIn="false" value=""${workspace_loc:/alib/lib}""/> + </option> + <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.2007525188" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="cdt.managedbuild.tool.gnu.assembler.so.debug.687188981" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.so.debug"> + <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1752274239" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + <cconfiguration id="cdt.managedbuild.config.gnu.so.release.1520604130"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.so.release.1520604130" moduleId="org.eclipse.cdt.core.settings" name="Release"> + <externalSettings> + <externalSetting> + <entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/libaregexptree"/> + <entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/libaregexptree/Release"/> + <entry flags="RESOLVED" kind="libraryFile" name="libaregexptree" srcPrefixMapping="" srcRootPath=""/> + </externalSetting> + </externalSettings> + <extensions> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactExtension="so" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.so.release.1520604130" name="Release" parent="cdt.managedbuild.config.gnu.so.release"> + <folderInfo id="cdt.managedbuild.config.gnu.so.release.1520604130." name="/" resourcePath=""> + <toolChain id="cdt.managedbuild.toolchain.gnu.so.release.1162609074" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.so.release"> + <targetPlatform id="cdt.managedbuild.target.gnu.platform.so.release.1759853920" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.so.release"/> + <builder buildPath="${workspace_loc:/libaregexptree}/Release" id="cdt.managedbuild.target.gnu.builder.so.release.1258822533" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.so.release"/> + <tool id="cdt.managedbuild.tool.gnu.archiver.base.1142241535" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> + <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.so.release.1786790485" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.so.release"> + <option id="gnu.cpp.compiler.so.release.option.optimization.level.953252658" name="Optimization Level" superClass="gnu.cpp.compiler.so.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/> + <option id="gnu.cpp.compiler.so.release.option.debugging.level.1252930773" name="Debug Level" superClass="gnu.cpp.compiler.so.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.700494430" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.compiler.so.release.1093926937" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.so.release"> + <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.so.release.option.optimization.level.1826966038" name="Optimization Level" superClass="gnu.c.compiler.so.release.option.optimization.level" valueType="enumerated"/> + <option id="gnu.c.compiler.so.release.option.debugging.level.1400300583" name="Debug Level" superClass="gnu.c.compiler.so.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/> + <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1965616930" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.c.linker.so.release.1524879430" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.so.release"> + <option defaultValue="true" id="gnu.c.link.so.release.option.shared.212020666" name="Shared (-shared)" superClass="gnu.c.link.so.release.option.shared" valueType="boolean"/> + </tool> + <tool id="cdt.managedbuild.tool.gnu.cpp.linker.so.release.1070138855" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.so.release"> + <option defaultValue="true" id="gnu.cpp.link.so.release.option.shared.1375446138" name="Shared (-shared)" superClass="gnu.cpp.link.so.release.option.shared" valueType="boolean"/> + <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1629746563" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="cdt.managedbuild.tool.gnu.assembler.so.release.1310441599" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.so.release"> + <inputType id="cdt.managedbuild.tool.gnu.assembler.input.847181109" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> + </tool> + </toolChain> + </folderInfo> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <project id="libaregexptree.cdt.managedbuild.target.gnu.so.669406254" name="Shared Library" projectType="cdt.managedbuild.target.gnu.so"/> + </storageModule> + <storageModule moduleId="scannerConfiguration"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.so.release.1520604130;cdt.managedbuild.config.gnu.so.release.1520604130.;cdt.managedbuild.tool.gnu.c.compiler.so.release.1093926937;cdt.managedbuild.tool.gnu.c.compiler.input.1965616930"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1471630722;cdt.managedbuild.config.gnu.exe.release.1471630722.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.559466187;cdt.managedbuild.tool.gnu.cpp.compiler.input.1646184593"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.so.debug.1383098863;cdt.managedbuild.config.gnu.so.debug.1383098863.;cdt.managedbuild.tool.gnu.cpp.compiler.so.debug.2082487370;cdt.managedbuild.tool.gnu.cpp.compiler.input.1152650017"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.so.debug.1383098863;cdt.managedbuild.config.gnu.so.debug.1383098863.;cdt.managedbuild.tool.gnu.c.compiler.so.debug.407077523;cdt.managedbuild.tool.gnu.c.compiler.input.1141545811"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.so.release.1520604130;cdt.managedbuild.config.gnu.so.release.1520604130.;cdt.managedbuild.tool.gnu.cpp.compiler.so.release.1786790485;cdt.managedbuild.tool.gnu.cpp.compiler.input.700494430"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.244448146;cdt.managedbuild.config.gnu.exe.debug.244448146.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1057366622;cdt.managedbuild.tool.gnu.cpp.compiler.input.730783971"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1471630722;cdt.managedbuild.config.gnu.exe.release.1471630722.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.173316879;cdt.managedbuild.tool.gnu.c.compiler.input.1355666001"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.244448146;cdt.managedbuild.config.gnu.exe.debug.244448146.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1175584482;cdt.managedbuild.tool.gnu.c.compiler.input.280382358"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> +</cproject> diff --git a/libaregexptree/.project b/libaregexptree/.project new file mode 100644 index 0000000000000000000000000000000000000000..7e13c6ecd7b916da5f2f84a41b32e97448f3d827 --- /dev/null +++ b/libaregexptree/.project @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>libaregexptree</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> + <triggers>clean,full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.cdt.core.cnature</nature> + <nature>org.eclipse.cdt.core.ccnature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> + </natures> +</projectDescription> diff --git a/libaregexptree/makefile b/libaregexptree/makefile new file mode 100644 index 0000000000000000000000000000000000000000..59349150b1c9a403ee66d23222ae8a3c726f10ed --- /dev/null +++ b/libaregexptree/makefile @@ -0,0 +1,20 @@ +CC=g++ +LIBRARY=libaregexptree.so +CCFLAGS= -std=c++11 -O2 -c -Wall -fPIC -I../alib/src +LDFLAGS= -L../alib/lib -lalib -shared + +SOURCES=$(shell find src/ -name *cpp) +OBJECTS=$(patsubst src/%.cpp, obj/%.o, $(SOURCES)) + +all: $(SOURCES) lib/$(LIBRARY) + +lib/$(LIBRARY): $(OBJECTS) + mkdir -p lib + $(CC) $(OBJECTS) -o $@ $(LDFLAGS) + +obj/%.o: src/%.cpp + mkdir -p $(dir $@) + $(CC) $(CCFLAGS) $< -o $@ + +clean: + $(RM) -r *.o *.d lib obj diff --git a/libaregexptree/src/RegExpAlphabet.cpp b/libaregexptree/src/RegExpAlphabet.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d39a7183fa6682d5c21a19f82b1acff33c21b5ce --- /dev/null +++ b/libaregexptree/src/RegExpAlphabet.cpp @@ -0,0 +1,69 @@ +#include "RegExpAlphabet.h" + +using namespace alib; +using namespace alphabet; +using namespace regexp; +using namespace std; + +set<RegExpSymbol> RegExpAlphabet::getSymbols( const RegExp & re ) +{ + set<RegExpSymbol> alphabet; + + for( const auto & symbol : getSymbolsListInOrder( re ) ) + alphabet.insert( RegExpSymbol( symbol->getSymbol( ) ) ); + + return alphabet; +} + +list<const RegExpSymbol*> RegExpAlphabet::getSymbolsListInOrder( const RegExp & re ) +{ + list<const RegExpSymbol*> alphabet; + searchSymbols( re.getRegExp( ), alphabet ); + return alphabet; +} + + +void RegExpAlphabet::searchSymbols( const RegExpElement * node, list<const RegExpSymbol*> & alphabet ) +{ + const Alternation* alternation = dynamic_cast<const Alternation*>( node ); + const Concatenation* concatenation = dynamic_cast<const Concatenation*>( node ); + const Iteration* iteration = dynamic_cast<const Iteration*>( node ); + const RegExpSymbol* symbol = dynamic_cast<const RegExpSymbol*>( node ); + const RegExpEmpty * empty = dynamic_cast<const RegExpEmpty*>( node ); + const RegExpEpsilon* eps = dynamic_cast<const RegExpEpsilon*>( node ); + + if( symbol ) + { + alphabet.push_back( symbol ); + return; + } + + else if( alternation ) + { + for( const auto & element : alternation->getElements( ) ) + searchSymbols( element, alphabet ); + return; + } + + else if( concatenation ) + { + for( const auto & element : concatenation->getElements( ) ) + searchSymbols( element, alphabet ); + return; + } + + else if( iteration ) + { + searchSymbols( iteration->getElement( ), alphabet ); + return; + } + + else if( empty ) + return; + + else if( eps ) + return; + + + throw AlibException( "RegExpAlphabet::traverseSymbols() - unknown RegExpElement node" ); +} diff --git a/libaregexptree/src/RegExpAlphabet.h b/libaregexptree/src/RegExpAlphabet.h new file mode 100644 index 0000000000000000000000000000000000000000..c8f08590543f2a9e26f656cf38bec596cc1584de --- /dev/null +++ b/libaregexptree/src/RegExpAlphabet.h @@ -0,0 +1,28 @@ +#ifndef REGEXPALPHABET_H_ +#define REGEXPALPHABET_H_ + +#include <regexp/RegExp.h> +#include <regexp/RegExpElement.h> +#include <regexp/Alternation.h> +#include <regexp/Concatenation.h> +#include <regexp/Iteration.h> +#include <regexp/RegExpSymbol.h> +#include <regexp/RegExpEmpty.h> +#include <regexp/RegExpEpsilon.h> + +#include <AlibException.h> + +#include <list> +#include <set> + +class RegExpAlphabet +{ +public: + static std::list<const regexp::RegExpSymbol*> getSymbolsListInOrder( const regexp::RegExp & re ); + static std::set<regexp::RegExpSymbol> getSymbols( const regexp::RegExp & re ); + +private: + static void searchSymbols( const regexp::RegExpElement * element, std::list<const regexp::RegExpSymbol*> & alphabet ); +}; + +#endif /* REGEXPALPHABET_H_ */ diff --git a/aconversions/src/derivatives/RegExpNormalize.cpp b/libaregexptree/src/RegExpOptimize.cpp similarity index 85% rename from aconversions/src/derivatives/RegExpNormalize.cpp rename to libaregexptree/src/RegExpOptimize.cpp index 889bef86b74d4f9b8fc890fded168d57887a578c..49e6bb34ecb0d2a2fded9017e9b856b07aa51a0e 100644 --- a/aconversions/src/derivatives/RegExpNormalize.cpp +++ b/libaregexptree/src/RegExpOptimize.cpp @@ -1,27 +1,17 @@ /* - * RegExpNormalize.cpp + * RegExpOptimize.cpp * * Created on: 20. 1. 2014 * Author: tomas */ -#include <cassert> -#include "RegExpNormalize.h" +#include "RegExpOptimize.h" +using namespace alib; using namespace regexp; -namespace conversions +RegExpElement* RegExpOptimize::optimize( RegExpElement * node ) { - -RegExpElement* RegExpNormalize::normalize( RegExpElement * element ) -{ - return optimize( element ); -} - - -RegExpElement* RegExpNormalize::optimize( RegExpElement * node ) -{ - assert( node ); Alternation * alternation = dynamic_cast<Alternation*>( node ); Concatenation * concatenation = dynamic_cast<Concatenation*>( node ); Iteration * iteration = dynamic_cast<Iteration*>( node ); @@ -42,10 +32,10 @@ RegExpElement* RegExpNormalize::optimize( RegExpElement * node ) if( eps ) return optimize( eps ); - throw ConversionException( "RegExpNormalize::optimize - unknown RegExpElement node" ); + throw AlibException( "RegExpOptimize::optimize - unknown RegExpElement node" ); } -RegExpElement * RegExpNormalize::optimize( Alternation * node ) +RegExpElement * RegExpOptimize::optimize( Alternation * node ) { auto & nodeElements = node->getElements( ); @@ -109,7 +99,7 @@ RegExpElement * RegExpNormalize::optimize( Alternation * node ) return node; } -RegExpElement * RegExpNormalize::optimize( Concatenation * node ) +RegExpElement * RegExpOptimize::optimize( Concatenation * node ) { auto & nodeElements = node->getElements( ); @@ -169,7 +159,7 @@ RegExpElement * RegExpNormalize::optimize( Concatenation * node ) return node; } -RegExpElement * RegExpNormalize::optimize( Iteration * node ) +RegExpElement * RegExpOptimize::optimize( Iteration * node ) { node->setElement( optimize( node->getElement( ) ) ); @@ -197,20 +187,17 @@ RegExpElement * RegExpNormalize::optimize( Iteration * node ) return node; } -RegExpElement * RegExpNormalize::optimize( RegExpSymbol * node ) +RegExpElement * RegExpOptimize::optimize( RegExpSymbol * node ) { return node; } -RegExpElement * RegExpNormalize::optimize( RegExpEmpty * node ) +RegExpElement * RegExpOptimize::optimize( RegExpEmpty * node ) { return node; } -RegExpElement * RegExpNormalize::optimize( RegExpEpsilon * node ) +RegExpElement * RegExpOptimize::optimize( RegExpEpsilon * node ) { return node; } - - -} /* namespace conversions */ diff --git a/aconversions/src/derivatives/RegExpNormalize.h b/libaregexptree/src/RegExpOptimize.h similarity index 69% rename from aconversions/src/derivatives/RegExpNormalize.h rename to libaregexptree/src/RegExpOptimize.h index 6b58f4333550e217a201f2b1ab11a408f2878e18..5f81b119be9e1ee01c4d0f3308332181496f455e 100644 --- a/aconversions/src/derivatives/RegExpNormalize.h +++ b/libaregexptree/src/RegExpOptimize.h @@ -1,12 +1,12 @@ /* - * RegExpNormalize.h + * RegExpOptimize.h * * Created on: 20. 1. 2014 * Author: tomas */ -#ifndef REGEXPNORMALIZE_H_ -#define REGEXPNORMALIZE_H_ +#ifndef REGEXPOPTIMIZE_H_ +#define REGEXPOPTIMIZE_H_ #include <regexp/RegExp.h> #include <regexp/RegExpElement.h> @@ -17,18 +17,12 @@ #include <regexp/RegExpEmpty.h> #include <regexp/RegExpEpsilon.h> -#include "../utils/ConversionException.h" +#include <AlibException.h> -namespace conversions -{ - -class RegExpNormalize +class RegExpOptimize { public: - regexp::RegExpElement* normalize( regexp::RegExpElement* element ); - -private: - regexp::RegExpElement * optimize( regexp::RegExpElement* node ); + regexp::RegExpElement * optimize( regexp::RegExpElement* element ); regexp::RegExpElement * optimize( regexp::Alternation * node ); regexp::RegExpElement * optimize( regexp::Concatenation * node ); regexp::RegExpElement * optimize( regexp::Iteration * node ); @@ -37,6 +31,4 @@ private: regexp::RegExpElement * optimize( regexp::RegExpEmpty * node ); }; -} /* namespace conversions */ - #endif /* REGEXPNORMALIZE_H_ */ diff --git a/makefile b/makefile index 861018a33a0f460876c205a58c117c1ec87db0e8..c31bddb3b586a444ca65e7d2c8650b790d21cbf7 100644 --- a/makefile +++ b/makefile @@ -1,17 +1,21 @@ APPPATH = /usr/bin -LIBPATH = /usr/lib/ +LIBPATH = /usr/lib BINFOLDER = bin -SUBDIRS_LIBS = alib adeterminize -SUBDIRS_BINS = acat aconvert aconvert.dot aconvert.gastex aconvert.regexp aconvert.automaton aconvert.grammar aminimize adeterminize.fsm adeterminize.idpda adeterminize.vpa adeterminize.vpa2 adeterminize.vpa3 adiff adiff.automaton adiff.grammar aepsilon atrim +CORE_LIB = alib +SUBDIRS_LIBS = adeterminize libaderivation libaregexptree +SUBDIRS_BINS = acat aconvert aconvert.dot aconvert.gastex aconvert.regexp aconvert.automaton aconvert.grammar aminimize adeterminize.fsm adeterminize.idpda adeterminize.vpa adeterminize.vpa2 adeterminize.vpa3 adiff adiff.automaton adiff.grammar aepsilon atrim aderivation SUBDIRS_WITH_MAKE = $(dir $(wildcard */makefile)) -.PHONY: $(SUBDIRS_LIBS) $(SUBDIRS_BINS) +.PHONY: $(CORE_LIB) $(SUBDIRS_LIBS) $(SUBDIRS_BINS) -all: $(SUBDIRS_LIBS) $(SUBDIRS_BINS) copy +all: $(CORE_LIB) $(SUBDIRS_LIBS) $(SUBDIRS_BINS) copy -$(SUBDIRS_LIBS): +$(CORE_LIB): + $(MAKE) -C $@ + +$(SUBDIRS_LIBS): $(CORE_LIB) $(MAKE) -C $@ $(SUBDIRS_BINS): $(SUBDIRS_LIBS) @@ -22,10 +26,10 @@ clean: $(MAKE) -C $$dir clean; \ done -copy: $(SUBDIRS_LIBS) $(SUBDIRS_BINS) +copy: $(CORE_LIB) $(SUBDIRS_LIBS) $(SUBDIRS_BINS) mkdir -p $(BINFOLDER) rm -rf $(BINFOLDER)/* - for dir in $(SUBDIRS_LIBS); do \ + for dir in $(CORE_LIB) $(SUBDIRS_LIBS); do \ cp $$dir/lib/* $(BINFOLDER); \ done for dir in $(SUBDIRS_BINS); do \