Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
GrammarConcatenation.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
24#pragma once
25
27
30
32
33namespace grammar::transform {
34
42public:
51 template < class TerminalSymbolType, class NonterminalSymbolType >
53};
54
55template < class TerminalSymbolType, class NonterminalSymbolType >
57 ext::pair < NonterminalSymbolType, unsigned > S = ext::make_pair ( common::createUnique ( label::InitialStateLabel::instance < NonterminalSymbolType > ( ), first.getNonterminalAlphabet ( ), second.getNonterminalAlphabet ( ) ), 0 );
59
60 res.setTerminalAlphabet ( first.getTerminalAlphabet ( ) + second.getTerminalAlphabet ( ) );
61
62 copyNonterminalsRename ( res, first, 1 );
63 copyNonterminalsRename ( res, first, 2 );
64
65 copyRulesRenameNonterminals ( res, first, 1 );
67
68 res.addRule ( S, { ext::make_pair ( first.getInitialSymbol ( ), 1 ), ext::make_pair ( second.getInitialSymbol ( ), 2 ) } );
69
70 return res;
71}
72
73} /* namespace grammar::transform */
74
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Context free grammar in Chomsky hierarchy or type 2 in Chomsky hierarchy. Generates context free lang...
Definition: CFG.h:67
const NonterminalSymbolType & getInitialSymbol() const &
Definition: CFG.h:148
const ext::set< TerminalSymbolType > & getTerminalAlphabet() const &
Definition: CFG.h:215
const ext::set< NonterminalSymbolType > & getNonterminalAlphabet() const &
Definition: CFG.h:177
Definition: GrammarConcatenation.h:41
static grammar::CFG< TerminalSymbolType, ext::pair< NonterminalSymbolType, unsigned > > concatenation(const grammar::CFG< TerminalSymbolType, NonterminalSymbolType > &first, const grammar::CFG< TerminalSymbolType, NonterminalSymbolType > &second)
Definition: GrammarConcatenation.h:56
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
p second
Definition: ToRegExpAlgebraic.h:126
return res
Definition: MinimizeByPartitioning.h:145
T createUnique(T object, const Alphabets &... alphabets)
Definition: createUnique.hpp:46
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: GrammarAlternation.h:33