From ad5f1e4fd796d9c6f93bfd1ab102b21eb1756930 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 27 Dec 2015 11:18:47 -0500 Subject: [PATCH] LR0: Added ::dump method to display intermediate parsing table --- src/LR0.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/LR0.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/LR0.cpp b/src/LR0.cpp index 53d8dc0c..2b4e25bd 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -132,3 +132,39 @@ std::string LR0::dump () const } //////////////////////////////////////////////////////////////////////////////// +std::string LR0::dump (std::vector >& augmented, States& states) const +{ + std::stringstream out; + + for (unsigned int c = 0; c < states.size (); ++c) + { + out << " [" << c << "] "; + + for (unsigned int i = 0; i < states[c].size (); ++i) + { + if (i) + out << " "; + + out << augmented[states[c][i]._rule][0] + << " " + << augmented[states[c][i]._rule][1]; + + for (unsigned int t = 2; t < augmented[states[c][i]._rule].size (); t++) + { + if ((int)t - 2 == states[c][i]._cursor) + out << " ."; + + out << " " << augmented[states[c][i]._rule][t]; + } + + out << "\n"; + } + + out << "\n"; + } + + out << "\n"; + return out.str (); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/LR0.h b/src/LR0.h index 4371e37d..1b11840e 100644 --- a/src/LR0.h +++ b/src/LR0.h @@ -60,6 +60,7 @@ protected: private: bool expandNonTerminals (std::vector >&, std::vector >&); + std::string dump (std::vector >&, States&) const; private: // state column result