From 586cce2114e0b99e1a386fe1659155acb94a25f4 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 2 Jan 2016 15:21:50 -0500 Subject: [PATCH] LR0: Changed ::expand to take a single symbol, not a closure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated ::initialize to handle the expanѕion of the first rule. --- src/LR0.cpp | 12 ++++++++---- src/LR0.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/LR0.cpp b/src/LR0.cpp index 423ce100..8990b381 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -74,11 +74,15 @@ void LR0::initialize (const Grammar& grammar) Closure items; items.push_back (item0); - auto closure = getClosure (items); + for (auto& expected : getExpected (items)) + for (auto& item : expand (expected)) + items.push_back (item); States states; - states.push_back (closure); + states.push_back (items); std::cout << states.dump () << "\n"; + + // TODO Now recursively fill in the rest. } //////////////////////////////////////////////////////////////////////////////// @@ -127,11 +131,11 @@ std::set LR0::getExpected (const Closure& closure) const } //////////////////////////////////////////////////////////////////////////////// -LR0::Closure LR0::expand (const Closure& closure) const +LR0::Closure LR0::expand (const std::string& symbol) const { LR0::Closure result; - return closure; + return result; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/LR0.h b/src/LR0.h index befb2c27..5dfcba2a 100644 --- a/src/LR0.h +++ b/src/LR0.h @@ -70,7 +70,7 @@ public: private: Closure getClosure (const Closure&) const; std::set getExpected (const Closure&) const; - Closure expand (const Closure&) const; + Closure expand (const std::string&) const; private: // Copy of the augmented grammar.