Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ToRegExpAlgebraic.h
Go to the documentation of this file.
1
6#pragma once
7
10
13
16
17namespace grammar {
18
19namespace convert {
20
22public:
29 template < class TerminalSymbolType, class NonterminalSymbolType >
31
35 template < class TerminalSymbolType, class NonterminalSymbolType >
37};
38
39template < class TerminalSymbolType, class NonterminalSymbolType >
42
43 solver.setVariableSymbols(grammar.getNonterminalAlphabet());
44
45 for(const auto & rule : grammar.getRules()) {
46 const NonterminalSymbolType& lhs = rule.first;
47
48 for(const auto& ruleRHS : rule.second) {
49 if(ruleRHS.template is<TerminalSymbolType>()) {
50 const TerminalSymbolType& rhs = ruleRHS.template get<TerminalSymbolType>();
52 } else {
53 const ext::pair<NonterminalSymbolType, TerminalSymbolType>& rhs = ruleRHS.template get<ext::pair<NonterminalSymbolType, TerminalSymbolType>>();
54 solver.addEquation(lhs, rhs.first, regexp::UnboundedRegExpSymbol < TerminalSymbolType > (rhs.second));
55 }
56 }
57 }
58 if(grammar.getGeneratesEpsilon())
60
61 return solver.solve(grammar.getInitialSymbol());
62}
63
64template < class TerminalSymbolType, class NonterminalSymbolType >
67
68 solver.setVariableSymbols(grammar.getNonterminalAlphabet());
69
70 for(const auto & rule : grammar.getRules()) {
71 const NonterminalSymbolType & lhs = rule.first;
72
73 for(const auto& ruleRHS : rule.second) {
74 if ( ruleRHS.template is < TerminalSymbolType > ( ) ) {
75 const TerminalSymbolType & rhs = ruleRHS.template get < TerminalSymbolType > ( );
77 } else {
78 const ext::pair < TerminalSymbolType, NonterminalSymbolType > & rhs = ruleRHS.template get < ext::pair < TerminalSymbolType, NonterminalSymbolType > > ( );
79 solver.addEquation ( lhs, rhs.second, regexp::UnboundedRegExpSymbol < TerminalSymbolType > ( rhs.first ) );
80 }
81 }
82 }
83 if(grammar.getGeneratesEpsilon())
84 solver.addEquation ( grammar.getInitialSymbol ( ), regexp::UnboundedRegExpEpsilon < TerminalSymbolType > ( ) );
85
86 return solver.solve ( grammar.getInitialSymbol ( ) );
87}
88
89} /* namespace covert */
90
91} /* namespace grammar */
92
Definition: LeftRegularEquationSolver.h:16
Definition: RightRegularEquationSolver.h:16
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Left regular grammar in Chomsky hierarchy or type 3 in Chomsky hierarchy. Generates regular languages...
Definition: LeftRG.h:70
Right regular grammar in Chomsky hierarchy or type 3 in Chomsky hierarchy. Generates regular language...
Definition: RightRG.h:70
Definition: ToRegExpAlgebraic.h:21
static regexp::UnboundedRegExp< TerminalSymbolType > convert(const grammar::RightRG< TerminalSymbolType, NonterminalSymbolType > &grammar)
Definition: ToRegExpAlgebraic.h:65
Represents the epsilon expression in the regular expression. The node can't have any children.
Definition: UnboundedRegExpEpsilon.h:41
Represents the symbol in the regular expression. The can't have any children.
Definition: UnboundedRegExpSymbol.h:42
Unbounded regular expression represents regular expression. It describes regular languages....
Definition: UnboundedRegExp.h:80
equations::RightRegularEquationSolver< SymbolType, StateType > solver
Definition: ToRegExpAlgebraic.h:117
Definition: converterCommon.hpp:8
Definition: ToAutomaton.h:24