From 74bb9cd27242b9320f99ff4d2b50c3051576cc14 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 8 Feb 2022 16:53:51 +0800 Subject: ... --- include/cru/parse/Production.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 include/cru/parse/Production.h (limited to 'include/cru/parse/Production.h') 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 -- cgit v1.2.3