-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrammar.hpp
71 lines (56 loc) · 1.79 KB
/
Grammar.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _GRAMMAR_HPP_
#define _GRAMMAR_HPP_
#include "Symbol.hpp"
#include "Production.hpp"
#include <vector>
/********************----- CLASS: Grammar -----********************/
class Grammar
{
public:
Grammar();
virtual ~Grammar(){}
void add(Production &&i_production);
SymbolSet::const_iterator alphabetBegin() const;
SymbolSet::const_iterator alphabetEnd() const;
bool isContextFree() const;
ProductionConstPtrVector productionPointers(SymbolList const &i_left) const;
size_t productionCount() const;
Symbol const &startSymbol() const;
SymbolSet first(Symbol const &i_symbol) const;
SymbolSet firstList(SymbolList const &i_symbolList) const;
std::string toString() const;
Grammar &operator |= (Symbol &&i_symbol);
Grammar &operator |= (Production &&i_production);
Production const &operator[](size_t const i_ruleIndex) const;
enum class AnalysisFlags
{
CONTEXTFREE=(1<<0),
DEFAULT=CONTEXTFREE,
};
enum class CacheFlags
{
BUILTFIRST=(1<<0),
BUILTFOLLOW=(1<<1),
DEFAULT=0,
};
protected:
SymbolMap buildFirst() const;
SymbolMap buildFollow() const;
static SymbolSet first(Symbol const &i_symbol, SymbolMap const &i_firstMap);
static SymbolSet firstList(SymbolList const &i_symbolList, SymbolMap const &i_firstMap);
private:
Grammar(Grammar const &)=delete;
Grammar(Grammar &&)=delete;
Grammar &operator =(Grammar const &)=delete;
Grammar &operator =(Grammar &&)=delete;
SymbolSet m_alphabet;
AnalysisFlags m_analysisFlags;
mutable CacheFlags m_cacheFlags;
mutable SymbolMap m_cacheFirst;
mutable SymbolMap m_cacheFollow;
ProductionVector m_productions;
};
/**************************************************/
ENUM_GENERATE_HELPERS(Grammar::AnalysisFlags)
ENUM_GENERATE_HELPERS(Grammar::CacheFlags)
#endif /* _GRAMMAR_HPP_ */