diff options
| author | crupest <crupest@outlook.com> | 2022-02-08 16:53:51 +0800 |
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2022-02-08 16:53:51 +0800 |
| commit | 74bb9cd27242b9320f99ff4d2b50c3051576cc14 (patch) | |
| tree | 744bac5799c593d1d6f81e7b09581bea626f2cde /include/cru/parse/Grammar.hpp | |
| parent | b90c398de829d1ba5329651d75bae82f5e4085fe (diff) | |
| download | cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.gz cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.bz2 cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.zip | |
...
Diffstat (limited to 'include/cru/parse/Grammar.hpp')
| -rw-r--r-- | include/cru/parse/Grammar.hpp | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/include/cru/parse/Grammar.hpp b/include/cru/parse/Grammar.hpp deleted file mode 100644 index 8dc1833f..00000000 --- a/include/cru/parse/Grammar.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once -#include "Production.hpp" - -#include <unordered_map> -#include <vector> - -namespace cru::parse { -class CRU_PARSE_API Grammar : public Object { - public: - Grammar(); - - CRU_DELETE_COPY(Grammar) - CRU_DELETE_MOVE(Grammar) - - ~Grammar() override; - - public: - void SetStartSymbol(Nonterminal* start_symbol); - - Terminal* CreateTerminal(String name); - Nonterminal* CreateNonterminal(String name); - Production* CreateProduction(String name, Nonterminal* left, - std::vector<Symbol*> right); - - bool RemoveSymbol(Symbol* symbol); - bool RemoveProduction(Production* production); - - public: // Getters - Nonterminal* GetStartSymbol() const { return start_symbol_; } - const std::vector<Terminal*>& GetTerminals() const { return terminals_; } - const std::vector<Nonterminal*>& GetNonterminals() const { - return nonterminals_; - } - const std::vector<Symbol*>& GetSymbols() const { return symbols_; } - const std::vector<Production*>& GetProductions() const { - return productions_; - } - - Grammar* Clone() const; - - public: // Algorithms - std::unordered_map<Nonterminal*, std::vector<Production*>> - GenerateLeftProductionMap() const; - - // Algorithm 4.19. - // Require grammar has no cycles or empty-productions. - void EliminateLeftRecursions(); - - // Algorithm 4.21 - void LeftFactor(); - - public: - String ProductionsToString() const; - - private: - Nonterminal* start_symbol_ = nullptr; - std::vector<Terminal*> terminals_; - std::vector<Nonterminal*> nonterminals_; - std::vector<Symbol*> symbols_; - std::vector<Production*> productions_; -}; -} // namespace cru::parse |
