From 7126046049c88abef33593a3fc2cf0140c9c80d6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 5 Jan 2016 01:15:30 -0500 Subject: [PATCH] LR0: Added ::initializeFirstState --- src/LR0.cpp | 14 ++++++++++++++ src/LR0.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/LR0.cpp b/src/LR0.cpp index f7b365b8..d6afd678 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -128,6 +128,20 @@ LR0::Closure LR0::getClosure (const std::string& symbol) const return result; } +//////////////////////////////////////////////////////////////////////////////// +void LR0::initializeFirstState (States& states) const +{ + LR0::Closure result; + for (unsigned int r = 0; r < _augmented.size (); ++r) + { + Item item (_augmented[r]); + item.setGrammarRuleIndex (r); + result.push_back (item); + } + + states.push_back (result); +} + //////////////////////////////////////////////////////////////////////////////// void LR0::closeState (States& states, const int state) const { diff --git a/src/LR0.h b/src/LR0.h index a4ad5262..3b0437dd 100644 --- a/src/LR0.h +++ b/src/LR0.h @@ -70,6 +70,7 @@ public: private: std::set getExpectedSymbols (const Closure&) const; Closure getClosure (const std::string&) const; + void initializeFirstState (States&) const; void closeState (States&, const int) const; private: