Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
GrammarTransformCommon.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
25
26#pragma once
27
28template < class TerminalSymbolType, class NonterminalSymbolType >
30 for ( const NonterminalSymbolType & symb : src.getNonterminalAlphabet ( ) )
31 dst.addNonterminalSymbol ( ext::make_pair ( symb, suffix ) );
32}
33
34template < class TerminalSymbolType, class NonterminalSymbolType >
36 for ( const std::pair < const NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & kv : src.getRules ( ) ) {
37 const NonterminalSymbolType & lhs = kv.first;
38
41
43 if ( symb.template is < TerminalSymbolType > ( ) && src.getTerminalAlphabet ( ).count ( symb.template get < TerminalSymbolType > ( ) ) )
44 newRhs.push_back ( symb.template get < TerminalSymbolType > ( ) );
45 else
46 newRhs.push_back ( ext::make_pair ( symb.template get < NonterminalSymbolType > ( ), suffix ) );
47 }
48
49 dst.addRule ( ext::make_pair ( lhs, suffix ), newRhs );
50 }
51 }
52}
53
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: set.hpp:44
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
Context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy. Generates context free lang...
Definition: CFG.h:67
const ext::set< TerminalSymbolType > & getTerminalAlphabet() const &
Definition: CFG.h:215
const ext::set< NonterminalSymbolType > & getNonterminalAlphabet() const &
Definition: CFG.h:177
const ext::map< NonterminalSymbolType, ext::set< ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > > > & getRules() const &
Definition: CFG.h:332
void copyNonterminalsRename(grammar::CFG< TerminalSymbolType, ext::pair< NonterminalSymbolType, unsigned > > &dst, const grammar::CFG< TerminalSymbolType, NonterminalSymbolType > &src, const unsigned suffix)
Definition: GrammarTransformCommon.h:29
void copyRulesRenameNonterminals(grammar::CFG< TerminalSymbolType, ext::pair< NonterminalSymbolType, unsigned > > &dst, const grammar::CFG< TerminalSymbolType, NonterminalSymbolType > &src, const unsigned suffix)
Definition: GrammarTransformCommon.h:35
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79