From ef087a7b3515658d581a18c94d5fe134afdd976c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 27 Dec 2015 12:18:02 -0500 Subject: [PATCH] LR0: Implemented Item::dump --- src/LR0.cpp | 22 ++++++++++++++++++++++ src/LR0.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/LR0.cpp b/src/LR0.cpp index a1a77174..00411aeb 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -175,3 +175,25 @@ bool LR0::Item::advance () } //////////////////////////////////////////////////////////////////////////////// +std::string LR0::Item::dump () const +{ + std::stringstream out; + + for (unsigned int i = 0; i < _rule.size (); ++i) + { + if (i) + out << " "; + + if (i == _cursor) + out << "● "; + + out << _rule[i]; + } + + if (_cursor >= _rule.size ()) + out << " ●"; + + return out.str (); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/LR0.h b/src/LR0.h index 1172bdcd..268b37ad 100644 --- a/src/LR0.h +++ b/src/LR0.h @@ -45,6 +45,7 @@ public: public: Item (const std::vector &); bool advance (); + std::string dump () const; private: std::vector _rule;