From 90ccdc872fe8eee59f8f10862053aea3dcaa26bd Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 5 Jan 2016 12:04:26 -0500 Subject: [PATCH] LR0: Implemented unformatted ::dump --- src/LR0.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/LR0.cpp b/src/LR0.cpp index 2f47abfd..951ac8a0 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -207,21 +207,32 @@ void LR0::debug (bool value) } //////////////////////////////////////////////////////////////////////////////// +// +-------+---------------+---------------+ +// | state | actions... | goto... | +// | | terminals $ | non-terminals | +// +-------+--+--+--+--+---+----+-----+----+ +// | | | | | | | | | | +// +-------+--+--+--+--+---+----+-----+----+ +// | | | | | | | | | | +// +-------+--+--+--+--+---+----+-----+----+ std::string LR0::dump () const { std::stringstream out; out << "Parser Tables\n"; - // TODO Render _actions and _goto as a table. - // - // +-------+---------------+---------------+ - // | state | actions... | goto... | - // | | terminals $ | non-terminals | - // +-------+--+--+--+--+---+----+-----+----+ - // | | | | | | | | | | - // +-------+--+--+--+--+---+----+-----+----+ - // | | | | | | | | | | - // +-------+--+--+--+--+---+----+-----+----+ + for (unsigned int state = 0; state < _actions.size (); ++state) + { + out << " " << state; + for (auto& terminal : _actions[state]) + out << " " << terminal.first << ":" << terminal.second; + + out << " "; + + for (auto& rule : _goto[state]) + out << " " << rule.first << ":" << rule.second; + + out << "\n"; + } return out.str (); }