From 61ef17813a246d36763c8634426720dca0da32bc Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 2 Jan 2016 10:43:14 -0500 Subject: [PATCH] LR0: Now retains a copy of the augmented grammar --- src/LR0.cpp | 12 +++++------- src/LR0.h | 7 ++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/LR0.cpp b/src/LR0.cpp index 9ca28a36..bd841ea1 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -50,13 +50,13 @@ LR0::LR0 () void LR0::initialize (const Grammar& grammar) { // Obtain the augmented grammar. - auto augmented = grammar.augmented (); + auto _augmented = grammar.augmented (); if (_debug) { std::cout << "Augmented Grammar\n"; auto count = 0; - for (auto& item : augmented) + for (auto& item : _augmented) { std::cout << " [" << count++ << "]"; for (auto& term : item) @@ -69,8 +69,8 @@ void LR0::initialize (const Grammar& grammar) // TODO Expand this single interation into a loop that ends when there is no // more expanѕion. - Item item0 {augmented[0]}; - auto closure = getClosure (item0, augmented); + Item item0 {_augmented[0]}; + auto closure = getClosure (item0); States states; states.push_back (closure); @@ -90,9 +90,7 @@ void LR0::initialize (const Grammar& grammar) // until no more items can be added to J; // return J // end -LR0::Closure LR0::getClosure ( - const Item& item, - const std::vector >& augmented) +LR0::Closure LR0::getClosure (const Item& item) { LR0::Closure closure; closure.push_back (item); diff --git a/src/LR0.h b/src/LR0.h index 86c6ed20..70231c3a 100644 --- a/src/LR0.h +++ b/src/LR0.h @@ -63,9 +63,14 @@ public: }; private: - Closure getClosure (const Item&, const std::vector >&); + Closure getClosure (const Item&); + + private: + // Copy of the augmented grammar. + std::vector > _augmented; + // state column result // | | | std::map > _actions;