45 template <
class TerminalSymbolType,
class NonterminalSymbolType >
58 template <
class TerminalSymbolType,
class NonterminalSymbolType >
71 template <
class TerminalSymbolType,
class NonterminalSymbolType >
84 template <
class TerminalSymbolType,
class NonterminalSymbolType >
97 template <
class TerminalSymbolType,
class NonterminalSymbolType >
110 template <
class TerminalSymbolType,
class NonterminalSymbolType >
123 template <
class TerminalSymbolType,
class NonterminalSymbolType >
136 template <
class TerminalSymbolType,
class NonterminalSymbolType >
149 template <
class TerminalSymbolType,
class NonterminalSymbolType >
153template <
class TerminalSymbolType,
class NonterminalSymbolType >
158template <
class TerminalSymbolType,
class NonterminalSymbolType >
162 for (
const NonterminalSymbolType & nonterminal :
grammar.getNonterminalAlphabet ( ) )
163 result.addNonterminalSymbol ( nonterminal );
164 result.setTerminalAlphabet (
grammar.getTerminalAlphabet ( ) );
167 for (
const TerminalSymbolType & symbol :
grammar.getTerminalAlphabet ( ) ) {
170 result.addNonterminalSymbol ( shadowSymbol );
171 result.addRule ( std::move ( shadowSymbol ), symbol );
176 if ( rhs.template is < TerminalSymbolType > ( ) ) {
177 result.addRule ( rules.first, rhs.template get < TerminalSymbolType > ( ) );
180 result.addRule ( rules.first,
ext::make_pair ( rhsPair.first, terminalToShadowNonterminal.
at ( rhsPair.second ) ) );
185 result.setGeneratesEpsilon (
grammar.getGeneratesEpsilon ( ) );
190template <
class TerminalSymbolType,
class NonterminalSymbolType >
194 for (
const NonterminalSymbolType & nonterminal :
grammar.getNonterminalAlphabet ( ) )
195 result.addNonterminalSymbol ( nonterminal );
196 result.setTerminalAlphabet (
grammar.getTerminalAlphabet ( ) );
199 for (
const TerminalSymbolType & symbol :
grammar.getTerminalAlphabet ( ) ) {
202 result.addNonterminalSymbol ( shadowSymbol );
203 result.addRule ( std::move ( shadowSymbol ), symbol );
208 if ( rhs.template is < TerminalSymbolType > ( ) ) {
209 result.addRule ( rules.first, rhs.template get < TerminalSymbolType > ( ) );
212 result.addRule ( rules.first,
ext::make_pair ( terminalToShadowNonterminal.
at ( rhsPair.first ), rhsPair.second ) );
217 result.setGeneratesEpsilon (
grammar.getGeneratesEpsilon ( ) );
222template <
class TerminalSymbolType,
class NonterminalSymbolType >
227 for (
unsigned i = 0;
i < rhs.size ( ) / 2; ++
i )
228 left.push_back ( rhs [
i ] );
230 if (
result.addNonterminalSymbol ( left ) && left.size ( ) > 1 )
233 for (
unsigned i = rhs.size ( ) / 2;
i < rhs.size ( ); ++
i )
234 right.push_back ( rhs [
i ] );
236 if (
result.addNonterminalSymbol ( right ), right.size ( ) > 1 )
239 result.addRule ( std::move ( lhs ),
ext::make_pair ( std::move ( left ), std::move ( right ) ) );
242template <
class T,
class TerminalSymbolType =
typename grammar::TerminalSymbolTypeOfGrammar < T >,
class NonterminalSymbolType =
typename grammar::NonterminalSymbolTypeOfGrammar < T > >
246 for (
const NonterminalSymbolType & nonterminal :
grammar.getNonterminalAlphabet ( ) )
249 result.setTerminalAlphabet (
grammar.getTerminalAlphabet ( ) );
251 for (
const TerminalSymbolType & symbol :
grammar.getTerminalAlphabet ( ) ) {
256 for (
const auto & rules :
grammar.getRules ( ) ) {
258 if ( rhs.size ( ) == 1 ) {
263 if (
grammar.getTerminalAlphabet ( ).count ( symbol ) )
264 rawRule.push_back ( symbol.template get < TerminalSymbolType > ( ) );
266 rawRule.push_back ( symbol );
274 result.setGeneratesEpsilon (
grammar.getGeneratesEpsilon ( ) );
279template <
class TerminalSymbolType,
class NonterminalSymbolType >
284template <
class TerminalSymbolType,
class NonterminalSymbolType >
289template <
class TerminalSymbolType,
class NonterminalSymbolType >
293 for (
const NonterminalSymbolType & nonterminal :
grammar.getNonterminalAlphabet ( ) )
296 result.setTerminalAlphabet (
grammar.getTerminalAlphabet ( ) );
298 for (
const TerminalSymbolType & symbol :
grammar.getTerminalAlphabet ( ) ) {
303 for (
const auto & rules :
grammar.getRules ( ) ) {
305 if ( rhs.second.empty ( ) )
309 rawRule.
insert ( rawRule.end ( ), rhs.second.begin ( ), rhs.second.end ( ) );
315 result.setGeneratesEpsilon (
grammar.getGeneratesEpsilon ( ) );
320template <
class TerminalSymbolType,
class NonterminalSymbolType >
325template <
class TerminalSymbolType,
class NonterminalSymbolType >
330template <
class TerminalSymbolType,
class NonterminalSymbolType >
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
R & at(const T &key, R &defaultValue)
Definition: map.hpp:163
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Implementation of the variant class allowing to store any type of those listed in the template parame...
Definition: variant.hpp:98
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
reverse_iterator insert(const_reverse_iterator pos, const T &value)
Inserts the value on position given by iterator pos.
Definition: vector.hpp:229
Context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy. Generates context free lang...
Definition: CFG.h:67
Chomsky normal form of a context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy....
Definition: CNF.h:66
Context free grammar without epsilon rules in Chomsky hierarchy or type 2 in Chomsky hierarchy....
Definition: EpsilonFreeCFG.h:65
Greibach normal form of a context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy....
Definition: GNF.h:65
Context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy. Generates context free lang...
Definition: LG.h:67
Left linear grammar in Chomsky hierarchy or type 3 in Chomsky hierarchy. Generates regular languages.
Definition: LeftLG.h:66
Left regular grammar in Chomsky hierarchy or type 3 in Chomsky hierarchy. Generates regular languages...
Definition: LeftRG.h:70
Right linear grammar in Chomsky hierarchy or type 3 in Chomsky hierarchy. Generates regular languages...
Definition: RightLG.h:65
Right regular grammar in Chomsky hierarchy or type 3 in Chomsky hierarchy. Generates regular language...
Definition: RightRG.h:70
static grammar::EpsilonFreeCFG< TerminalSymbolType, NonterminalSymbolType > remove(const grammar::CFG< TerminalSymbolType, NonterminalSymbolType > &grammar)
Definition: EpsilonRemover.h:202
static grammar::CFG< TerminalSymbolType, NonterminalSymbolType > remove(const grammar::CFG< TerminalSymbolType, NonterminalSymbolType > &grammar)
Definition: SimpleRulesRemover.h:181
static grammar::CNF< TerminalSymbolType, ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > > convert(const grammar::CFG< TerminalSymbolType, NonterminalSymbolType > &grammar)
Definition: ToCNF.h:280
return grammar
Definition: ToGrammarLeftRG.h:99
int i
Definition: AllEpsilonClosure.h:118
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
T createUnique(T object, const Alphabets &... alphabets)
Definition: createUnique.hpp:46
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
void splitRule(ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > lhs, const ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > &rhs, grammar::CNF< TerminalSymbolType, ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > > &result)
Definition: ToCNF.h:223
grammar::CNF< TerminalSymbolType, ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > > convertInternal(const T &grammar)
Definition: ToCNF.h:243
Definition: ToAutomaton.h:24