Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ReachableSymbols.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/algorithm>
9
10#include <alib/deque>
11#include <alib/set>
12
13#include <grammar/Grammar.h>
14
15#include <grammar/RawRules.h>
16
17namespace grammar {
18
19namespace properties {
20
25public:
37 template<class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > >
39};
40
41template<class T, class TerminalSymbolType, class NonterminalSymbolType >
43 auto rawRules = grammar::RawRules::getRawRules ( grammar );
44
45 // 1
48 Vi.at ( 0 ).insert ( grammar.getInitialSymbol ( ) );
49
50 int i = 0;
51
52 // 2.
53 do {
54 i = i + 1;
55
56 Vi.push_back ( Vi.at ( i - 1 ) );
57
58 for ( const auto & rule : rawRules ) {
59 if ( Vi.at( i - 1 ).count ( rule.first ) ) {
60 for ( const auto & rhs : rule.second ) {
61 Vi.at ( i ).insert( rhs.begin( ), rhs.end( ) );
62 }
63 }
64 }
65
66 } while ( Vi.at( i ) != Vi.at( i - 1 ) );
67
68 // 3.
69 return Vi.at( i );
70}
71
72} /* namespace properties */
73
74} /* namespace grammar */
75
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
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
static ext::map< NonterminalSymbolType, ext::set< ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > > > getRawRules(const LG< TerminalSymbolType, NonterminalSymbolType > &grammar)
Definition: RawRules.h:92
Definition: ReachableSymbols.h:24
static ext::set< ext::variant< TerminalSymbolType, NonterminalSymbolType > > getReachableSymbols(const T &grammar)
Definition: ReachableSymbols.h:42
int i
Definition: AllEpsilonClosure.h:118
Definition: ToAutomaton.h:24