From 74bb9cd27242b9320f99ff4d2b50c3051576cc14 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 16:53:51 +0800 Subject: ... --- include/cru/parse/Base.h | 11 ++++ include/cru/parse/Base.hpp | 11 ---- include/cru/parse/Grammar.h | 62 ++++++++++++++++++++++ include/cru/parse/Grammar.hpp | 62 ---------------------- include/cru/parse/Nonterminal.h | 14 +++++ include/cru/parse/Nonterminal.hpp | 14 ----- include/cru/parse/ParsingAlgorithm.h | 22 ++++++++ include/cru/parse/ParsingAlgorithm.hpp | 22 -------- include/cru/parse/ParsingAlgorithmContext.h | 28 ++++++++++ include/cru/parse/ParsingAlgorithmContext.hpp | 28 ---------- include/cru/parse/ParsingContext.h | 22 ++++++++ include/cru/parse/ParsingContext.hpp | 22 -------- include/cru/parse/ParsingTreeNode.h | 33 ++++++++++++ include/cru/parse/ParsingTreeNode.hpp | 33 ------------ include/cru/parse/Production.h | 43 +++++++++++++++ include/cru/parse/Production.hpp | 43 --------------- include/cru/parse/RecursiveDescentAlgorithm.h | 19 +++++++ include/cru/parse/RecursiveDescentAlgorithm.hpp | 19 ------- .../cru/parse/RecursiveDescentAlgorithmContext.h | 22 ++++++++ .../cru/parse/RecursiveDescentAlgorithmContext.hpp | 22 -------- include/cru/parse/Symbol.h | 30 +++++++++++ include/cru/parse/Symbol.hpp | 30 ----------- include/cru/parse/Terminal.h | 14 +++++ include/cru/parse/Terminal.hpp | 14 ----- include/cru/parse/Token.h | 0 include/cru/parse/Token.hpp | 0 include/cru/parse/TokenType.h | 24 +++++++++ include/cru/parse/TokenType.hpp | 24 --------- 28 files changed, 344 insertions(+), 344 deletions(-) create mode 100644 include/cru/parse/Base.h delete mode 100644 include/cru/parse/Base.hpp create mode 100644 include/cru/parse/Grammar.h delete mode 100644 include/cru/parse/Grammar.hpp create mode 100644 include/cru/parse/Nonterminal.h delete mode 100644 include/cru/parse/Nonterminal.hpp create mode 100644 include/cru/parse/ParsingAlgorithm.h delete mode 100644 include/cru/parse/ParsingAlgorithm.hpp create mode 100644 include/cru/parse/ParsingAlgorithmContext.h delete mode 100644 include/cru/parse/ParsingAlgorithmContext.hpp create mode 100644 include/cru/parse/ParsingContext.h delete mode 100644 include/cru/parse/ParsingContext.hpp create mode 100644 include/cru/parse/ParsingTreeNode.h delete mode 100644 include/cru/parse/ParsingTreeNode.hpp create mode 100644 include/cru/parse/Production.h delete mode 100644 include/cru/parse/Production.hpp create mode 100644 include/cru/parse/RecursiveDescentAlgorithm.h delete mode 100644 include/cru/parse/RecursiveDescentAlgorithm.hpp create mode 100644 include/cru/parse/RecursiveDescentAlgorithmContext.h delete mode 100644 include/cru/parse/RecursiveDescentAlgorithmContext.hpp create mode 100644 include/cru/parse/Symbol.h delete mode 100644 include/cru/parse/Symbol.hpp create mode 100644 include/cru/parse/Terminal.h delete mode 100644 include/cru/parse/Terminal.hpp create mode 100644 include/cru/parse/Token.h delete mode 100644 include/cru/parse/Token.hpp create mode 100644 include/cru/parse/TokenType.h delete mode 100644 include/cru/parse/TokenType.hpp (limited to 'include/cru/parse') diff --git a/include/cru/parse/Base.h b/include/cru/parse/Base.h new file mode 100644 index 00000000..8f3a05e9 --- /dev/null +++ b/include/cru/parse/Base.h @@ -0,0 +1,11 @@ +#pragma once + +#ifdef CRU_PLATFORM_WINDOWS +#ifdef CRU_PARSE_EXPORT_API +#define CRU_PARSE_API __declspec(dllexport) +#else +#define CRU_PARSE_API __declspec(dllimport) +#endif +#else +#define CRU_PARSE_API +#endif diff --git a/include/cru/parse/Base.hpp b/include/cru/parse/Base.hpp deleted file mode 100644 index 8f3a05e9..00000000 --- a/include/cru/parse/Base.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifdef CRU_PLATFORM_WINDOWS -#ifdef CRU_PARSE_EXPORT_API -#define CRU_PARSE_API __declspec(dllexport) -#else -#define CRU_PARSE_API __declspec(dllimport) -#endif -#else -#define CRU_PARSE_API -#endif diff --git a/include/cru/parse/Grammar.h b/include/cru/parse/Grammar.h new file mode 100644 index 00000000..7dd1eec0 --- /dev/null +++ b/include/cru/parse/Grammar.h @@ -0,0 +1,62 @@ +#pragma once +#include "Production.h" + +#include +#include + +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 right); + + bool RemoveSymbol(Symbol* symbol); + bool RemoveProduction(Production* production); + + public: // Getters + Nonterminal* GetStartSymbol() const { return start_symbol_; } + const std::vector& GetTerminals() const { return terminals_; } + const std::vector& GetNonterminals() const { + return nonterminals_; + } + const std::vector& GetSymbols() const { return symbols_; } + const std::vector& GetProductions() const { + return productions_; + } + + Grammar* Clone() const; + + public: // Algorithms + std::unordered_map> + 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 terminals_; + std::vector nonterminals_; + std::vector symbols_; + std::vector productions_; +}; +} // namespace cru::parse 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 -#include - -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 right); - - bool RemoveSymbol(Symbol* symbol); - bool RemoveProduction(Production* production); - - public: // Getters - Nonterminal* GetStartSymbol() const { return start_symbol_; } - const std::vector& GetTerminals() const { return terminals_; } - const std::vector& GetNonterminals() const { - return nonterminals_; - } - const std::vector& GetSymbols() const { return symbols_; } - const std::vector& GetProductions() const { - return productions_; - } - - Grammar* Clone() const; - - public: // Algorithms - std::unordered_map> - 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 terminals_; - std::vector nonterminals_; - std::vector symbols_; - std::vector productions_; -}; -} // namespace cru::parse diff --git a/include/cru/parse/Nonterminal.h b/include/cru/parse/Nonterminal.h new file mode 100644 index 00000000..0ea15149 --- /dev/null +++ b/include/cru/parse/Nonterminal.h @@ -0,0 +1,14 @@ +#pragma once +#include "Symbol.h" + +namespace cru::parse { +class CRU_PARSE_API Nonterminal : public Symbol { + public: + Nonterminal(Grammar* grammar, String name); + + CRU_DELETE_COPY(Nonterminal) + CRU_DELETE_MOVE(Nonterminal) + + ~Nonterminal() override; +}; +} // namespace cru::parse diff --git a/include/cru/parse/Nonterminal.hpp b/include/cru/parse/Nonterminal.hpp deleted file mode 100644 index b01c7c8a..00000000 --- a/include/cru/parse/Nonterminal.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "Symbol.hpp" - -namespace cru::parse { -class CRU_PARSE_API Nonterminal : public Symbol { - public: - Nonterminal(Grammar* grammar, String name); - - CRU_DELETE_COPY(Nonterminal) - CRU_DELETE_MOVE(Nonterminal) - - ~Nonterminal() override; -}; -} // namespace cru::parse diff --git a/include/cru/parse/ParsingAlgorithm.h b/include/cru/parse/ParsingAlgorithm.h new file mode 100644 index 00000000..ae2dd0b5 --- /dev/null +++ b/include/cru/parse/ParsingAlgorithm.h @@ -0,0 +1,22 @@ +#pragma once +#include "Grammar.h" + +namespace cru::parse { +class ParsingAlgorithmContext; + +// Represents a parsing algorithm. +// It does not relate to any specific grammar. +// It is used to validate a grammar and create a parsing algorithm context. +class CRU_PARSE_API ParsingAlgorithm { + public: + ParsingAlgorithm() = default; + + CRU_DELETE_COPY(ParsingAlgorithm) + CRU_DELETE_MOVE(ParsingAlgorithm) + + virtual ~ParsingAlgorithm() = default; + + virtual bool CanHandle(Grammar* grammar) const = 0; + virtual ParsingAlgorithmContext* CreateContext(Grammar* grammar) const = 0; +}; +} // namespace cru::parse diff --git a/include/cru/parse/ParsingAlgorithm.hpp b/include/cru/parse/ParsingAlgorithm.hpp deleted file mode 100644 index 8f38c0ab..00000000 --- a/include/cru/parse/ParsingAlgorithm.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "Grammar.hpp" - -namespace cru::parse { -class ParsingAlgorithmContext; - -// Represents a parsing algorithm. -// It does not relate to any specific grammar. -// It is used to validate a grammar and create a parsing algorithm context. -class CRU_PARSE_API ParsingAlgorithm { - public: - ParsingAlgorithm() = default; - - CRU_DELETE_COPY(ParsingAlgorithm) - CRU_DELETE_MOVE(ParsingAlgorithm) - - virtual ~ParsingAlgorithm() = default; - - virtual bool CanHandle(Grammar* grammar) const = 0; - virtual ParsingAlgorithmContext* CreateContext(Grammar* grammar) const = 0; -}; -} // namespace cru::parse diff --git a/include/cru/parse/ParsingAlgorithmContext.h b/include/cru/parse/ParsingAlgorithmContext.h new file mode 100644 index 00000000..fe46c4d2 --- /dev/null +++ b/include/cru/parse/ParsingAlgorithmContext.h @@ -0,0 +1,28 @@ +#pragma once +#include +#include "Grammar.h" +#include "cru/parse/ParsingTreeNode.h" +#include "cru/parse/Terminal.h" + +namespace cru::parse { +class ParsingAlgorithm; + +// A parsing algorithm context contains all data a parsing algorithm needs to +// parse for a grammar. It does not relate to any input. For example, it can +// contain any state machine. +class CRU_PARSE_API ParsingAlgorithmContext { + public: + ParsingAlgorithmContext(Grammar* grammar, const ParsingAlgorithm* algorithm); + + CRU_DELETE_COPY(ParsingAlgorithmContext) + CRU_DELETE_MOVE(ParsingAlgorithmContext) + + virtual ~ParsingAlgorithmContext(); + + virtual ParsingTreeNode* Parse(const std::vector& input) = 0; + + private: + Grammar* grammar_; + const ParsingAlgorithm* algorithm_; +}; +} // namespace cru::parse diff --git a/include/cru/parse/ParsingAlgorithmContext.hpp b/include/cru/parse/ParsingAlgorithmContext.hpp deleted file mode 100644 index b959462c..00000000 --- a/include/cru/parse/ParsingAlgorithmContext.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include -#include "Grammar.hpp" -#include "cru/parse/ParsingTreeNode.hpp" -#include "cru/parse/Terminal.hpp" - -namespace cru::parse { -class ParsingAlgorithm; - -// A parsing algorithm context contains all data a parsing algorithm needs to -// parse for a grammar. It does not relate to any input. For example, it can -// contain any state machine. -class CRU_PARSE_API ParsingAlgorithmContext { - public: - ParsingAlgorithmContext(Grammar* grammar, const ParsingAlgorithm* algorithm); - - CRU_DELETE_COPY(ParsingAlgorithmContext) - CRU_DELETE_MOVE(ParsingAlgorithmContext) - - virtual ~ParsingAlgorithmContext(); - - virtual ParsingTreeNode* Parse(const std::vector& input) = 0; - - private: - Grammar* grammar_; - const ParsingAlgorithm* algorithm_; -}; -} // namespace cru::parse diff --git a/include/cru/parse/ParsingContext.h b/include/cru/parse/ParsingContext.h new file mode 100644 index 00000000..02dc4c9c --- /dev/null +++ b/include/cru/parse/ParsingContext.h @@ -0,0 +1,22 @@ +#pragma once +#include "ParsingAlgorithmContext.h" +#include "cru/parse/ParsingTreeNode.h" + +namespace cru::parse { +// A parsing context contains all info that a program needs to know when parsing +// a input sequence of terminals. +class CRU_PARSE_API ParsingContext { + public: + ParsingContext(const ParsingAlgorithmContext* parsing_algorithm_context, + std::vector input); + + CRU_DELETE_COPY(ParsingContext) + CRU_DELETE_MOVE(ParsingContext) + + ~ParsingContext(); + + private: + const ParsingAlgorithmContext* parsing_algorithm_context_; + std::vector input_; +}; +} // namespace cru::parse diff --git a/include/cru/parse/ParsingContext.hpp b/include/cru/parse/ParsingContext.hpp deleted file mode 100644 index cfb850b9..00000000 --- a/include/cru/parse/ParsingContext.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "ParsingAlgorithmContext.hpp" -#include "cru/parse/ParsingTreeNode.hpp" - -namespace cru::parse { -// A parsing context contains all info that a program needs to know when parsing -// a input sequence of terminals. -class CRU_PARSE_API ParsingContext { - public: - ParsingContext(const ParsingAlgorithmContext* parsing_algorithm_context, - std::vector input); - - CRU_DELETE_COPY(ParsingContext) - CRU_DELETE_MOVE(ParsingContext) - - ~ParsingContext(); - - private: - const ParsingAlgorithmContext* parsing_algorithm_context_; - std::vector input_; -}; -} // namespace cru::parse diff --git a/include/cru/parse/ParsingTreeNode.h b/include/cru/parse/ParsingTreeNode.h new file mode 100644 index 00000000..05b1006c --- /dev/null +++ b/include/cru/parse/ParsingTreeNode.h @@ -0,0 +1,33 @@ +#pragma once +#include "Grammar.h" + +#include + +namespace cru::parse { +class CRU_PARSE_API ParsingTreeNode { + public: + ParsingTreeNode(Symbol* symbol, Production* production); + + CRU_DELETE_COPY(ParsingTreeNode) + CRU_DELETE_MOVE(ParsingTreeNode) + + // In destructor, it will delete all children. + ~ParsingTreeNode(); + + public: + Symbol* GetSymbol() const { return symbol_; } + Production* GetProduction() const { return production_; } + Grammar* GetGrammar() const; + + const std::vector& GetChildren() const { return children_; } + + void AddChild(ParsingTreeNode* child); + void AddChild(ParsingTreeNode* child, Index index); + void RemoveChild(Index index); + + private: + Symbol* symbol_; + Production* production_; + std::vector children_; +}; +} // namespace cru::parse diff --git a/include/cru/parse/ParsingTreeNode.hpp b/include/cru/parse/ParsingTreeNode.hpp deleted file mode 100644 index 7119ca0b..00000000 --- a/include/cru/parse/ParsingTreeNode.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include "Grammar.hpp" - -#include - -namespace cru::parse { -class CRU_PARSE_API ParsingTreeNode { - public: - ParsingTreeNode(Symbol* symbol, Production* production); - - CRU_DELETE_COPY(ParsingTreeNode) - CRU_DELETE_MOVE(ParsingTreeNode) - - // In destructor, it will delete all children. - ~ParsingTreeNode(); - - public: - Symbol* GetSymbol() const { return symbol_; } - Production* GetProduction() const { return production_; } - Grammar* GetGrammar() const; - - const std::vector& GetChildren() const { return children_; } - - void AddChild(ParsingTreeNode* child); - void AddChild(ParsingTreeNode* child, Index index); - void RemoveChild(Index index); - - private: - Symbol* symbol_; - Production* production_; - std::vector children_; -}; -} // namespace cru::parse diff --git a/include/cru/parse/Production.h b/include/cru/parse/Production.h new file mode 100644 index 00000000..d5ababe6 --- /dev/null +++ b/include/cru/parse/Production.h @@ -0,0 +1,43 @@ +#pragma once +#include "cru/common/String.h" + +#include "Nonterminal.h" +#include "Terminal.h" + +#include + +namespace cru::parse { +class CRU_PARSE_API Production : public Object { + public: + Production(Grammar* grammar, String name, Nonterminal* left, + std::vector right); + + CRU_DELETE_COPY(Production) + CRU_DELETE_MOVE(Production) + + ~Production() override; + + public: + Grammar* GetGrammar() const { return grammar_; } + + String GetName() const { return name_; } + void SetName(String name) { name_ = std::move(name); } + + Nonterminal* GetLeft() const { return left_; } + void SetLeft(Nonterminal* left); + + const std::vector& GetRight() const { return right_; } + void SetRight(std::vector right); + + bool IsLeftRecursion() const { + return !right_.empty() && left_ == right_.front(); + } + + private: + Grammar* grammar_; + String name_; + + Nonterminal* left_; + std::vector right_; +}; +} // namespace cru::parse diff --git a/include/cru/parse/Production.hpp b/include/cru/parse/Production.hpp deleted file mode 100644 index cb3c79c0..00000000 --- a/include/cru/parse/Production.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once -#include "cru/common/String.hpp" - -#include "Nonterminal.hpp" -#include "Terminal.hpp" - -#include - -namespace cru::parse { -class CRU_PARSE_API Production : public Object { - public: - Production(Grammar* grammar, String name, Nonterminal* left, - std::vector right); - - CRU_DELETE_COPY(Production) - CRU_DELETE_MOVE(Production) - - ~Production() override; - - public: - Grammar* GetGrammar() const { return grammar_; } - - String GetName() const { return name_; } - void SetName(String name) { name_ = std::move(name); } - - Nonterminal* GetLeft() const { return left_; } - void SetLeft(Nonterminal* left); - - const std::vector& GetRight() const { return right_; } - void SetRight(std::vector right); - - bool IsLeftRecursion() const { - return !right_.empty() && left_ == right_.front(); - } - - private: - Grammar* grammar_; - String name_; - - Nonterminal* left_; - std::vector right_; -}; -} // namespace cru::parse diff --git a/include/cru/parse/RecursiveDescentAlgorithm.h b/include/cru/parse/RecursiveDescentAlgorithm.h new file mode 100644 index 00000000..9da4b8fe --- /dev/null +++ b/include/cru/parse/RecursiveDescentAlgorithm.h @@ -0,0 +1,19 @@ +#pragma once + +#include "ParsingAlgorithm.h" + +namespace cru::parse { +class CRU_PARSE_API RecursiveDescentAlgorithm : public ParsingAlgorithm { + public: + RecursiveDescentAlgorithm() = default; + + CRU_DELETE_COPY(RecursiveDescentAlgorithm) + CRU_DELETE_MOVE(RecursiveDescentAlgorithm) + + ~RecursiveDescentAlgorithm() override = default; + + public: + bool CanHandle(Grammar* grammar) const override; + ParsingAlgorithmContext* CreateContext(Grammar* grammar) const override; +}; +} // namespace cru::parse diff --git a/include/cru/parse/RecursiveDescentAlgorithm.hpp b/include/cru/parse/RecursiveDescentAlgorithm.hpp deleted file mode 100644 index 373724ea..00000000 --- a/include/cru/parse/RecursiveDescentAlgorithm.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "ParsingAlgorithm.hpp" - -namespace cru::parse { -class CRU_PARSE_API RecursiveDescentAlgorithm : public ParsingAlgorithm { - public: - RecursiveDescentAlgorithm() = default; - - CRU_DELETE_COPY(RecursiveDescentAlgorithm) - CRU_DELETE_MOVE(RecursiveDescentAlgorithm) - - ~RecursiveDescentAlgorithm() override = default; - - public: - bool CanHandle(Grammar* grammar) const override; - ParsingAlgorithmContext* CreateContext(Grammar* grammar) const override; -}; -} // namespace cru::parse diff --git a/include/cru/parse/RecursiveDescentAlgorithmContext.h b/include/cru/parse/RecursiveDescentAlgorithmContext.h new file mode 100644 index 00000000..00acf479 --- /dev/null +++ b/include/cru/parse/RecursiveDescentAlgorithmContext.h @@ -0,0 +1,22 @@ +#pragma once + +#include "ParsingAlgorithmContext.h" +#include "cru/parse/ParsingTreeNode.h" +#include "cru/parse/RecursiveDescentAlgorithm.h" +#include "cru/parse/Terminal.h" + +namespace cru::parse { +class CRU_PARSE_API RecursiveDescentAlgorithmContext : public ParsingAlgorithmContext { + public: + RecursiveDescentAlgorithmContext(Grammar* grammar, + const RecursiveDescentAlgorithm* algorithm); + + CRU_DELETE_COPY(RecursiveDescentAlgorithmContext) + CRU_DELETE_MOVE(RecursiveDescentAlgorithmContext) + + ~RecursiveDescentAlgorithmContext() override; + + public: + ParsingTreeNode* Parse(const std::vector& input) override; +}; +} // namespace cru::parse diff --git a/include/cru/parse/RecursiveDescentAlgorithmContext.hpp b/include/cru/parse/RecursiveDescentAlgorithmContext.hpp deleted file mode 100644 index b29ee1a1..00000000 --- a/include/cru/parse/RecursiveDescentAlgorithmContext.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "ParsingAlgorithmContext.hpp" -#include "cru/parse/ParsingTreeNode.hpp" -#include "cru/parse/RecursiveDescentAlgorithm.hpp" -#include "cru/parse/Terminal.hpp" - -namespace cru::parse { -class CRU_PARSE_API RecursiveDescentAlgorithmContext : public ParsingAlgorithmContext { - public: - RecursiveDescentAlgorithmContext(Grammar* grammar, - const RecursiveDescentAlgorithm* algorithm); - - CRU_DELETE_COPY(RecursiveDescentAlgorithmContext) - CRU_DELETE_MOVE(RecursiveDescentAlgorithmContext) - - ~RecursiveDescentAlgorithmContext() override; - - public: - ParsingTreeNode* Parse(const std::vector& input) override; -}; -} // namespace cru::parse diff --git a/include/cru/parse/Symbol.h b/include/cru/parse/Symbol.h new file mode 100644 index 00000000..e7bd4808 --- /dev/null +++ b/include/cru/parse/Symbol.h @@ -0,0 +1,30 @@ +#pragma once +#include "Base.h" + +#include "cru/common/String.h" + +namespace cru::parse { +class Grammar; + +// Base class of Terminal and Nonterminal. +class CRU_PARSE_API Symbol : public Object { + public: + explicit Symbol(Grammar* grammar, String name); + + CRU_DELETE_COPY(Symbol) + CRU_DELETE_MOVE(Symbol) + + ~Symbol() override; + + public: + Grammar* GetGrammar() { return grammar_; } + + String GetName() const { return name_; } + void SetName(String name) { name_ = std::move(name); } + + private: + Grammar* grammar_; + + String name_; +}; +} // namespace cru::parse diff --git a/include/cru/parse/Symbol.hpp b/include/cru/parse/Symbol.hpp deleted file mode 100644 index 7404a5e7..00000000 --- a/include/cru/parse/Symbol.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include "Base.hpp" - -#include "cru/common/String.hpp" - -namespace cru::parse { -class Grammar; - -// Base class of Terminal and Nonterminal. -class CRU_PARSE_API Symbol : public Object { - public: - explicit Symbol(Grammar* grammar, String name); - - CRU_DELETE_COPY(Symbol) - CRU_DELETE_MOVE(Symbol) - - ~Symbol() override; - - public: - Grammar* GetGrammar() { return grammar_; } - - String GetName() const { return name_; } - void SetName(String name) { name_ = std::move(name); } - - private: - Grammar* grammar_; - - String name_; -}; -} // namespace cru::parse diff --git a/include/cru/parse/Terminal.h b/include/cru/parse/Terminal.h new file mode 100644 index 00000000..d197ab29 --- /dev/null +++ b/include/cru/parse/Terminal.h @@ -0,0 +1,14 @@ +#pragma once +#include "Symbol.h" + +namespace cru::parse { +class CRU_PARSE_API Terminal : public Symbol { + public: + Terminal(Grammar* grammar, String name); + + CRU_DELETE_COPY(Terminal) + CRU_DELETE_MOVE(Terminal) + + ~Terminal() override; +}; +} // namespace cru::parse diff --git a/include/cru/parse/Terminal.hpp b/include/cru/parse/Terminal.hpp deleted file mode 100644 index 4ff8f898..00000000 --- a/include/cru/parse/Terminal.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "Symbol.hpp" - -namespace cru::parse { -class CRU_PARSE_API Terminal : public Symbol { - public: - Terminal(Grammar* grammar, String name); - - CRU_DELETE_COPY(Terminal) - CRU_DELETE_MOVE(Terminal) - - ~Terminal() override; -}; -} // namespace cru::parse diff --git a/include/cru/parse/Token.h b/include/cru/parse/Token.h new file mode 100644 index 00000000..e69de29b diff --git a/include/cru/parse/Token.hpp b/include/cru/parse/Token.hpp deleted file mode 100644 index e69de29b..00000000 diff --git a/include/cru/parse/TokenType.h b/include/cru/parse/TokenType.h new file mode 100644 index 00000000..cb6f6159 --- /dev/null +++ b/include/cru/parse/TokenType.h @@ -0,0 +1,24 @@ +#pragma once +#include "Base.h" + +#include "cru/common/Base.h" +#include "cru/common/String.h" + +namespace cru::parse { +class CRU_PARSE_API TokenType : public Object { + public: + explicit TokenType(String name); + + CRU_DELETE_COPY(TokenType) + CRU_DELETE_MOVE(TokenType) + + ~TokenType() override; + + public: + String GetName() const { return name_; } + void SetName(String name) { name_ = std::move(name); } + + private: + String name_; +}; +} // namespace cru::parse diff --git a/include/cru/parse/TokenType.hpp b/include/cru/parse/TokenType.hpp deleted file mode 100644 index 49415d3b..00000000 --- a/include/cru/parse/TokenType.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "Base.hpp" - -#include "cru/common/Base.hpp" -#include "cru/common/String.hpp" - -namespace cru::parse { -class CRU_PARSE_API TokenType : public Object { - public: - explicit TokenType(String name); - - CRU_DELETE_COPY(TokenType) - CRU_DELETE_MOVE(TokenType) - - ~TokenType() override; - - public: - String GetName() const { return name_; } - void SetName(String name) { name_ = std::move(name); } - - private: - String name_; -}; -} // namespace cru::parse -- cgit v1.2.3