diff --git a/alib2str/src/grammar/string/Regular/RightRG.h b/alib2str/src/grammar/string/Regular/RightRG.h index eb43316403c06216930dc0af096760d9da78b93b..befeaacbe46a280bcf4027f70d4b06314ce9c7e6 100644 --- a/alib2str/src/grammar/string/Regular/RightRG.h +++ b/alib2str/src/grammar/string/Regular/RightRG.h @@ -31,7 +31,22 @@ grammar::RightRG < SymbolType > stringApi < grammar::RightRG < SymbolType > >::p if(token.type != grammar::GrammarFromStringLexer::TokenType::RIGHT_RG) throw exception::CommonException("Unrecognised RightRG token."); - return grammar::GrammarFromStringParserCommon::parseCFLikeGrammar < grammar::RightRG < SymbolType > > ( input ); + grammar::RightRG < SymbolType > g = grammar::GrammarFromStringParserCommon::parseCFLikeGrammar < grammar::RightRG < SymbolType > > ( input ); + + if ( g.getGeneratesEpsilon( ) ) { + for ( const auto& rule : g.getRules ( ) ) { + const ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > >& rhsSet = rule.second; + for ( const auto& elem : rhsSet ) { + if ( elem.template is < ext::pair < SymbolType, SymbolType > > ( ) ) { + const ext::pair < SymbolType, SymbolType > & rhs = elem.template get < ext::pair < SymbolType, SymbolType > > ( ); + if ( g.getInitialSymbol ( ) == rhs.second ) + throw exception::CommonException("Init on RHS when generate eps"); + } + } + } + } + + return g; } template<class SymbolType > diff --git a/alib2str/test-src/grammar/GrammarTest.cpp b/alib2str/test-src/grammar/GrammarTest.cpp index a40fa023d1711b9f91c07f387883788a2df3cadd..32719889a585a6062ecc2f8afa3e4491cc6575ac 100644 --- a/alib2str/test-src/grammar/GrammarTest.cpp +++ b/alib2str/test-src/grammar/GrammarTest.cpp @@ -61,7 +61,7 @@ void GrammarTest::stringParserTest() { "{a, b},\n" "{ A -> a | a A,\n" " B -> b | b B,\n" - " S -> | a A | a S | b B},\n" + " S -> | a A | b A | b B},\n" "S)\n"; grammar::Grammar grammar = alib::StringDataFactory::fromString (input);