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

aIntegral: Integrate regexp

parent dfa36ba2
No related branches found
No related tags found
No related merge requests found
<?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.707297701">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.707297701" 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.707297701" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.707297701." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1599711834" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.411034457" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
<builder buildPath="${workspace_loc:/aintegral}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.644341997" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.2009244310" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1369390546" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.993968371" 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.1537920879" 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.2114166236" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/alib/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/libaderivation/src}&quot;"/>
<listOptionValue builtIn="false" value="/usr/include/libxml2"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1939414215" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1602187054" 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.1052600029" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.exe.debug.option.debugging.level.587040755" 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.1922653179" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.1271249302" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.193878269" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1647041643" 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.436674534" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1543209329" 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.1264340708">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1264340708" 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.1264340708" name="Release" parent="cdt.managedbuild.config.gnu.exe.release">
<folderInfo id="cdt.managedbuild.config.gnu.exe.release.1264340708." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.313537907" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.1838088733" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
<builder buildPath="${workspace_loc:/aintegral}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.490681150" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.963952675" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.161185738" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
<option id="gnu.cpp.compiler.exe.release.option.optimization.level.1288899991" 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.1854852592" 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.232047172" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.309612803" 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.920707787" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.exe.release.option.debugging.level.1787401156" 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.1298630353" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.220400844" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.194372850" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1330297478" 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.1842525723" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.191812789" 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="aintegral.cdt.managedbuild.target.gnu.exe.668827556" 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.707297701;cdt.managedbuild.config.gnu.exe.debug.707297701.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1369390546;cdt.managedbuild.tool.gnu.cpp.compiler.input.1939414215">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1264340708;cdt.managedbuild.config.gnu.exe.release.1264340708.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.161185738;cdt.managedbuild.tool.gnu.cpp.compiler.input.232047172">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.1264340708;cdt.managedbuild.config.gnu.exe.release.1264340708.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.309612803;cdt.managedbuild.tool.gnu.c.compiler.input.1298630353">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.707297701;cdt.managedbuild.config.gnu.exe.debug.707297701.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1602187054;cdt.managedbuild.tool.gnu.c.compiler.input.1922653179">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>aintegral</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>
CC=g++
EXECUTABLE=aintegral
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
#include <iostream>
#include <AlibException.h>
#include <regexp/RegExp.h>
#include <regexp/RegExpParser.h>
#include <regexp/RegExpSymbol.h>
#include <sax/SaxInterface.h>
#include "RegExpIntegral.h"
using namespace alib;
using namespace regexp;
using namespace std;
/*
* Usage:
* aintegral "a" "b" "cc" < regexp.xml
*/
int main(int argc, char** argv)
{
try
{
list<Token> tokens;
string input(istreambuf_iterator<char>(cin), (istreambuf_iterator<char>()));
SaxInterface::parseMemory(input, tokens);
RegExp re = RegExpParser::parse(tokens);
list<RegExpElement*> dString;
for( int i = 1; i < argc ; i++ )
{
string symbol( argv[ i ] );
// cout << "'" << symbol << "'" << endl;
if( symbol == "" )
dString.push_back( new RegExpEpsilon( ) );
else
dString.push_back( new RegExpSymbol( symbol ) );
}
RegExpIntegral i( re );
i.integral( dString ).toXML( cout );
}
catch( AlibException & e )
{
cout << e.what() << endl;
return 1;
}
return 0;
}
/*
* RegExpIntegral.cpp
*
* Created on: 24. 2. 2014
* Author: tomas
*/
#include "RegExpIntegral.h"
using namespace alib;
using namespace regexp;
RegExpIntegral::RegExpIntegral( const RegExp & re ) : m_re( re )
{
}
RegExp RegExpIntegral::integral( const list<RegExpElement*> & dString ) const
{
RegExpElement * expression = const_cast<RegExpElement*>( m_re.getRegExp( ) );
for( auto it = dString.rbegin( ); it != dString.rend( ); it ++ )
{
const auto & dSymbol = * it;
// FIXME: memory leak
if( dynamic_cast<RegExpEpsilon*>( dSymbol ) )
expression = expression->clone( );
else if( dynamic_cast<RegExpSymbol*>( dSymbol ) )
expression = integral( expression, * dynamic_cast<RegExpSymbol*>( dSymbol ) );
else
throw AlibException( "RegExpIntegral::integral - invalid/unknown RegExpElement passed in dString." );
}
return RegExp( expression );
}
RegExpElement * RegExpIntegral::integral( const RegExpElement * node, const RegExpSymbol & dSymbol ) const
{
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 RegExpEpsilon * eps = dynamic_cast<const RegExpEpsilon*>( node );
const RegExpEmpty * empty = dynamic_cast<const RegExpEmpty*>( node );
if( alternation )
return integral( alternation, dSymbol );
if( concatenation )
return integral( concatenation, dSymbol);
if( iteration )
return integral( iteration, dSymbol );
if( symbol )
return integral( symbol, dSymbol );
if( eps )
return integral( eps, dSymbol );
if( empty )
return integral( empty, dSymbol );
throw AlibException( "RegExpDerivation::derivation() - unknown RegExpElement node" );
}
RegExpElement * RegExpIntegral::integral( const Alternation * node, const RegExpSymbol & dSymbol ) const
{
Alternation * alt = new Alternation( );
for( const auto & child : node->getElements( ) )
alt->getElements( ).push_back( integral( child, dSymbol ) );
return alt;
}
RegExpElement * RegExpIntegral::integral( const Concatenation * node, const RegExpSymbol & dSymbol ) const
{
Concatenation * concat = new Concatenation( );
concat->getElements( ).push_back( dSymbol.clone( ) );
for( const auto & child : node->getElements( ) )
concat->getElements( ).push_back( child->clone( ) );
return concat;
}
RegExpElement * RegExpIntegral::integral( const Iteration * node, const RegExpSymbol & dSymbol ) const
{
Concatenation * concat = new Concatenation( );
concat->getElements( ).push_back( dSymbol.clone( ) );
concat->getElements( ).push_back( node->getElement( )->clone( ) );
return concat;
}
RegExpElement * RegExpIntegral::integral( const RegExpSymbol * node, const RegExpSymbol & dSymbol ) const
{
Concatenation * concat = new Concatenation( );
concat->getElements( ).push_back( dSymbol.clone( ) );
concat->getElements( ).push_back( node->clone( ) );
return concat;
}
RegExpElement * RegExpIntegral::integral( const RegExpEpsilon * node, const RegExpSymbol & dSymbol ) const
{
return dSymbol.clone( );
}
RegExpElement * RegExpIntegral::integral( const RegExpEmpty * node, const RegExpSymbol & dSymbol ) const
{
return new RegExpEmpty( );
}
/*
* RegExpIntegral.h
*
* Created on: 24. 2. 2014
* Author: tomas
*/
#ifndef REGEXPINTEGRAL_H_
#define REGEXPINTEGRAL_H_
#include <AlibException.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>
class RegExpIntegral
{
public:
RegExpIntegral( const regexp::RegExp & re );
regexp::RegExp integral( const std::list<regexp::RegExpElement*> & dString ) const;
private:
regexp::RegExpElement * integral( const regexp::RegExpElement * node, const regexp::RegExpSymbol & dSymbol ) const;
regexp::RegExpElement * integral( const regexp::Alternation * node, const regexp::RegExpSymbol & dSymbol ) const;
regexp::RegExpElement * integral( const regexp::Concatenation * node, const regexp::RegExpSymbol & dSymbol ) const;
regexp::RegExpElement * integral( const regexp::Iteration * node, const regexp::RegExpSymbol & dSymbol ) const;
regexp::RegExpElement * integral( const regexp::RegExpSymbol * node, const regexp::RegExpSymbol & dSymbol ) const;
regexp::RegExpElement * integral( const regexp::RegExpEpsilon * node, const regexp::RegExpSymbol & dSymbol ) const;
regexp::RegExpElement * integral( const regexp::RegExpEmpty * node, const regexp::RegExpSymbol & dSymbol ) const;
const regexp::RegExp & m_re;
};
#endif /* REGEXPINTEGRAL_H_ */
......@@ -13,7 +13,7 @@ SUBDIRS_BINS = acat \
atrim \
anormalize \
aconversions \
aderivation
aderivation aintegral
SUBDIRS_WITH_MAKE = $(dir $(wildcard */makefile))
 
.PHONY: $(CORE_LIB) $(SUBDIRS_LIBS) $(SUBDIRS_BINS)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment