Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
NullableNonterminals.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/algorithm>
9
10#include <alib/set>
11#include <alib/deque>
12
13#include <grammar/Grammar.h>
14
15#include <grammar/RawRules.h>
16
17namespace grammar {
18
19namespace properties {
20
25public:
39 template<class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > >
41};
42
43template < class T, class TerminalSymbolType, class NonterminalSymbolType >
45 auto rawRules = grammar::RawRules::getRawRules ( grammar );
46
48
49 Ni.push_back ( ext::set < NonterminalSymbolType > { } );
50 int i = 0;
51
52 auto testCallback = [ & ] ( const ext::variant < TerminalSymbolType, NonterminalSymbolType > & symb ) {
53 return Ni.at ( i - 1 ).count ( symb );
54 };
55
56 do {
57 i += 1;
58
59 Ni.push_back ( ext::set < NonterminalSymbolType > { } );
60 for ( const auto & rule : rawRules ) {
61 for ( const auto & rhs : rule.second ) {
62 if ( rhs.empty ( ) || std::all_of ( rhs.begin ( ), rhs.end ( ), testCallback ) ) {
63 Ni.at ( i ).insert ( rule.first );
64 }
65 }
66 }
67
68 } while ( Ni.at ( i ) != Ni.at ( i - 1 ) );
69
70 return Ni.at(i);
71}
72
73} /* namespace properties */
74
75} /* namespace grammar */
76
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: NullableNonterminals.h:24
static ext::set< NonterminalSymbolType > getNullableNonterminals(const T &grammar)
Definition: NullableNonterminals.h:44
int i
Definition: AllEpsilonClosure.h:118
all_of(T &&...) -> all_of< T... >
Definition: ToAutomaton.h:24