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

aconversion: changes (see details)

 - FA -> LRG: fix double addition of rules
 - Glushkov: use different state/nonterminal names. Names are generated via hexavigesimal with symbol id appended
 - Thompson: use different state names
 - Brzozowski: fix numbering - start at 0 so hexavigesimal starts properly at A
 - RRG -> FA: if createUnique is used, then use A' instead of A0

 - tests: correct exit values to determine if process reached timeout or segfault
parent ae3d7c7d
No related branches found
No related tags found
No related merge requests found
......@@ -103,7 +103,7 @@ void ConversionHandler::convertFSMtoRE( void )
 
void ConversionHandler::convertFSMtoRG( void )
{
if( m_target == RIGHT_REGULAR_GRAMMAR || REGULAR_GRAMMAR )
if( m_target == RIGHT_REGULAR_GRAMMAR )
convertFSMtoRRG( );
else if( m_target == LEFT_REGULAR_GRAMMAR )
convertFSMtoLRG( );
......@@ -172,7 +172,7 @@ void ConversionHandler::convertREtoFSM( void )
 
void ConversionHandler::convertREtoRG( void )
{
if( m_target == RIGHT_REGULAR_GRAMMAR || REGULAR_GRAMMAR )
if( m_target == RIGHT_REGULAR_GRAMMAR )
convertREtoRRG( );
else if( m_target == LEFT_REGULAR_GRAMMAR )
throw AlibException( "ConversionHandler:: RE to LRG is not implemented. Please convert to RRG and then to LRG." );
......@@ -361,10 +361,7 @@ ConversionHandler::TFormalism ConversionHandler::parseFormalismFromString( const
if( target == "re" || target == "regexp" || target == "regex" )
return REGULAR_EXPRESSION;
 
if( target == "rg" || target == "grammar" )
return REGULAR_GRAMMAR;
if( target == "rrg" )
if( target == "rrg" || target == "rg" || target == "grammar" )
return RIGHT_REGULAR_GRAMMAR;
 
if( target == "lrg" )
......
......@@ -51,9 +51,12 @@ LeftRegularGrammar FAtoLRGConverter::convert( void )
{
list<Symbol> leftSide, rightSide;
leftSide.push_back( grammar.getStartSymbol( ) );
grammar.addRule( Rule( leftSide, rightSide ) );
rightSide.push_back( nonterminalMap.find( transition.getFrom( ) )->second );
rightSide.push_back( transition.getInput( ) );
Rule r( leftSide, rightSide );
if( ! isInSet( r, grammar.getRules( ) ) )
grammar.addRule( Rule( leftSide, rightSide ) );
}
 
 
......@@ -69,7 +72,10 @@ LeftRegularGrammar FAtoLRGConverter::convert( void )
list<Symbol> leftSide, rightSide;
leftSide.push_back( grammar.getStartSymbol( ) );
rightSide.push_back( transition.getInput( ) );
grammar.addRule( Rule( leftSide, rightSide ) );
Rule r( leftSide, rightSide );
if( ! isInSet( r, grammar.getRules( ) ) )
grammar.addRule( Rule( leftSide, rightSide ) );
}
}
}
......
......@@ -76,7 +76,7 @@ FSM Brzozowski::convert( void )
 
for( const auto & r : Q )
{
State q( toBase26( ++ stateId ) );
State q( toBase26( stateId ++ ) );
stateMap.insert( std::pair<RegExp,State>( r, q ) );
automaton.addState( q );
}
......
......@@ -50,9 +50,10 @@ FSM Glushkov::convert( void )
State q0( "q0" );
automaton.addState( q0 );
automaton.addInitialState( q0 );
int stateId = 0;
for( auto const& symbol : GlushkovTraversal::getSymbols( m_re ) )
{
State q( to_string( symbol.getId( ) ) );
State q( toBase26( stateId ++ ) + to_string( symbol.getId( ) ) );
 
m_stateMap.insert( std::pair<GlushkovSymbol, State>( symbol, q ) );
automaton.addState( q );
......
......@@ -17,6 +17,7 @@
 
#include "../interface/IConversionFSM.h"
#include "../shared/glushkov/GlushkovTraversal.h"
#include "../shared/Hexavigesimal.h"
 
namespace conversions
{
......
......@@ -27,6 +27,7 @@ Thompson::~Thompson( void )
FSM Thompson::convert( void )
{
m_fsm = FSM( );
m_stateId = 0;
 
for( const auto & symbol : m_re.getAlphabet( ) )
m_fsm.addInputSymbol( symbol.getSymbol( ) );
......@@ -66,8 +67,8 @@ Thompson::SubexpressionTails Thompson::processRegExpNode( const RegExpElement *
 
Thompson::SubexpressionTails Thompson::processRegExpNode( const Iteration * node )
{
State head = m_fsm.createUniqueState( "iter__head", true );
State tail = m_fsm.createUniqueState( "iter__tail", true );
State head = m_fsm.createUniqueState( toBase26( m_stateId ) + "0", true );
State tail = m_fsm.createUniqueState( toBase26( m_stateId ++ ) + "1", true );
 
SubexpressionTails st = processRegExpNode( node->getElement( ) );
 
......@@ -81,8 +82,8 @@ Thompson::SubexpressionTails Thompson::processRegExpNode( const Iteration * node
 
Thompson::SubexpressionTails Thompson::processRegExpNode( const Alternation * node )
{
State head = m_fsm.createUniqueState( "alt__head", true );
State tail = m_fsm.createUniqueState( "alt__tail", true );
State head = m_fsm.createUniqueState( toBase26( m_stateId ) + "0", true );
State tail = m_fsm.createUniqueState( toBase26( m_stateId ++ ) + "1", true );
 
for( const auto & element : node->getElements( ) )
{
......@@ -110,8 +111,8 @@ Thompson::SubexpressionTails Thompson::processRegExpNode( const Concatenation *
Thompson::SubexpressionTails Thompson::processRegExpNode( const RegExpSymbol * node )
{
Symbol symb( node->getSymbol( ) );
State head = m_fsm.createUniqueState( "sym__start", true );
State tail = m_fsm.createUniqueState( "sym__end", true );
State head = m_fsm.createUniqueState( toBase26( m_stateId ) + "0", true );
State tail = m_fsm.createUniqueState( toBase26( m_stateId ++ ) + "1", true );
 
m_fsm.addTransition( head, symb, tail );
 
......@@ -121,8 +122,8 @@ Thompson::SubexpressionTails Thompson::processRegExpNode( const RegExpSymbol * n
Thompson::SubexpressionTails Thompson::processRegExpNode( const RegExpEpsilon * node )
{
Symbol symb( "" );
State head = m_fsm.createUniqueState( "epssym__start", true );
State tail = m_fsm.createUniqueState( "epssym__end", true );
State head = m_fsm.createUniqueState( toBase26( m_stateId ) + "0", true );
State tail = m_fsm.createUniqueState( toBase26( m_stateId ++ ) + "1", true );
 
m_fsm.addTransition( head, symb, tail );
 
......@@ -131,8 +132,8 @@ Thompson::SubexpressionTails Thompson::processRegExpNode( const RegExpEpsilon *
 
Thompson::SubexpressionTails Thompson::processRegExpNode( const RegExpEmpty * node )
{
State head = m_fsm.createUniqueState( "empty__start", true );
State tail = m_fsm.createUniqueState( "empty__end", true );
State head = m_fsm.createUniqueState( toBase26( m_stateId ) + "0", true );
State tail = m_fsm.createUniqueState( toBase26( m_stateId ++ ) + "1", true );
 
return SubexpressionTails( head, tail );
}
......
......@@ -18,6 +18,7 @@
 
#include "../interface/IConversionFSM.h"
#include "../include/macros.h"
#include "../shared/Hexavigesimal.h"
 
 
namespace conversions
......@@ -56,6 +57,7 @@ private:
* output FSM ($\varepsilon$--NFA)
*/
automaton::FSM m_fsm;
int m_stateId;
 
/**
* Stores head and tail state of "subautomaton" created in regexp subtree.
......
......@@ -75,7 +75,7 @@ RightRegularGrammar BrzozowskiDerivationRRG::convert( void )
 
for( const auto & r : N )
{
Symbol nt = grammar.createUniqueNonTerminalSymbol( toBase26( ++ nonterminalId ) );
Symbol nt = grammar.createUniqueNonTerminalSymbol( toBase26( nonterminalId ++ ) );
nonterminalMap.insert( pair<RegExp, Symbol>( r, nt ) );
}
 
......
......@@ -46,9 +46,11 @@ RightRegularGrammar GlushkovRRG::convert( void )
Symbol S = grammar.createUniqueNonTerminalSymbol( "S" );
grammar.setStartSymbol( S );
 
int nonterminalId = 0;
for( auto const& symbol : GlushkovTraversal::getSymbols( m_re ) )
{
Symbol a = grammar.createUniqueNonTerminalSymbol( symbol.getInputSymbol( ).getSymbol( ) + to_string( symbol.getId( ) ) );
Symbol a = grammar.createUniqueNonTerminalSymbol( toBase26( nonterminalId ++ ) + to_string( symbol.getId( ) ) );
 
m_symbolMap.insert( std::pair<GlushkovSymbol, Symbol>( symbol, a ) );
}
......
......@@ -16,6 +16,8 @@
#include "../../interface/IConversionRRG.h"
#include "../../shared/glushkov/GlushkovTraversal.h"
 
#include "../../shared/Hexavigesimal.h"
namespace conversions
{
 
......
......@@ -28,7 +28,7 @@ FSM RRGtoFAConverter::convert( void )
for( const auto & symbol : m_grammar.getNonTerminalSymbols( ) )
automaton.addState( State( symbol.getSymbol( ) ) );
 
const State & AState = automaton.createUniqueState( "A", true );
const State & AState = automaton.createUniqueState( "A", false );
 
for( const auto & rule : m_grammar.getRules( ) )
{
......
......@@ -2,7 +2,7 @@
 
set -o pipefail
 
TESTCASE_ITERATIONS=200
TESTCASE_ITERATIONS=100
TESTCASE_TIMEOUT=5
LOGFILE="log_tests.txt"
 
......@@ -58,7 +58,7 @@ function runTest2 {
RETTMP=$?
 
# segfault
if [ $RETTMP -eq 139 ]; then
if [ $RETTMP -eq 134 ]; then
return 3
fi
 
......
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