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/Production.h | |
parent | b90c398de829d1ba5329651d75bae82f5e4085fe (diff) | |
download | cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.gz cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.bz2 cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.zip |
...
Diffstat (limited to 'include/cru/parse/Production.h')
-rw-r--r-- | include/cru/parse/Production.h | 43 |
1 files changed, 43 insertions, 0 deletions
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 <vector> + +namespace cru::parse { +class CRU_PARSE_API Production : public Object { + public: + Production(Grammar* grammar, String name, Nonterminal* left, + std::vector<Symbol*> 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<Symbol*>& GetRight() const { return right_; } + void SetRight(std::vector<Symbol*> right); + + bool IsLeftRecursion() const { + return !right_.empty() && left_ == right_.front(); + } + + private: + Grammar* grammar_; + String name_; + + Nonterminal* left_; + std::vector<Symbol*> right_; +}; +} // namespace cru::parse |