Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
LL1ParseTable.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/vector>
9#include <alib/variant>
10#include <alib/set>
11#include <alib/map>
12
13#include <grammar/Grammar.h>
14
15#include "First.h"
16#include "Follow.h"
17
18namespace grammar {
19
20namespace parsing {
21
23public:
24 template < class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > >
26
27};
28
29template < class T, class TerminalSymbolType, class NonterminalSymbolType >
32
35
36 auto rawRules = grammar::RawRules::getRawRules ( grammar );
37 for ( const std::pair < const NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & transition : rawRules ) {
38 const NonterminalSymbolType & lhs = transition.first;
39
40 for ( const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs : transition.second ) {
41 for ( const ext::vector < TerminalSymbolType > & firstElem : first[rhs] ) {
42 if ( firstElem.empty ( ) )
43 continue;
44
45 res [ ext::make_pair ( firstElem, lhs ) ].insert ( rhs );
46 }
47
48 if ( first[rhs].count ( ext::vector < TerminalSymbolType > ( ) ) )
49 for ( const ext::vector < TerminalSymbolType > & followElem : follow[lhs] )
50 res [ ext::make_pair ( followElem, lhs ) ].insert ( rhs );
51
52 }
53 }
54
55 return res;
56}
57
58} /* namespace parsing */
59
60} /* namespace grammar */
61
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
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
static ext::map< NonterminalSymbolType, ext::set< ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > > > getRawRules(const LG< TerminalSymbolType, NonterminalSymbolType > &grammar)
Definition: RawRules.h:92
Definition: LL1ParseTable.h:22
static ext::map< ext::pair< ext::vector< TerminalSymbolType >, NonterminalSymbolType >, ext::set< ext::vector< ext::variant< TerminalSymbolType, NonterminalSymbolType > > > > parseTable(const T &grammar)
Definition: LL1ParseTable.h:30
return res
Definition: MinimizeByPartitioning.h:145
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: ToAutomaton.h:24