aboutsummaryrefslogtreecommitdiff
path: root/include/cru/parse
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/parse')
-rw-r--r--include/cru/parse/Grammar.hpp5
-rw-r--r--include/cru/parse/Production.hpp7
2 files changed, 12 insertions, 0 deletions
diff --git a/include/cru/parse/Grammar.hpp b/include/cru/parse/Grammar.hpp
index 5935e703..42649c30 100644
--- a/include/cru/parse/Grammar.hpp
+++ b/include/cru/parse/Grammar.hpp
@@ -35,6 +35,11 @@ class Grammar : public Object {
return productions_;
}
+ Grammar* Clone() const;
+
+ public: // Algorithms
+ void EliminateLeftRecursions();
+
private:
Nonterminal* start_symbol_;
std::vector<Terminal*> terminals_;
diff --git a/include/cru/parse/Production.hpp b/include/cru/parse/Production.hpp
index bd05a8c4..8a1331b9 100644
--- a/include/cru/parse/Production.hpp
+++ b/include/cru/parse/Production.hpp
@@ -20,12 +20,19 @@ class Production : public Object {
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_;