From 62f11f66031b530803585e58677315dd0051184d Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 6 Jan 2016 10:46:38 -0500 Subject: [PATCH] LR0: Cleaner parse table dump --- src/LR0.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/LR0.cpp b/src/LR0.cpp index 3813e68b..80d38238 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -203,11 +204,13 @@ void LR0::createParseTable (States& states) for (unsigned int state = 0; state < states.size (); ++state) for (unsigned int item = 0; item < states[state].size (); ++item) if (states[state][item].done ()) + { if (states[state][item]._grammarRule == 0) _actions[state]["$"] = "acc"; else for (auto& terminal : _terminals) _actions[state][terminal] = format ("r{1}", states[state][item]._grammarRule); + } } @@ -225,8 +228,7 @@ void LR0::debug (bool value) //////////////////////////////////////////////////////////////////////////////// // +-------+---------------+---------------+ -// | state | actions... | goto... | -// | | terminals $ | non-terminals | +// | state | terminals $ | non-terminals | // +-------+--+--+--+--+---+----+-----+----+ // | | | | | | | | | | // +-------+--+--+--+--+---+----+-----+----+ @@ -242,14 +244,12 @@ std::string LR0::dump () const t.colorHeader (Color ("underline")); // Add columns. - t.add ("State", false); + t.add ("State", true); for (auto& terminal : _terminals) - t.add (terminal, false); - - t.add ("$", false); + t.add (Lexer::dequote (terminal), true); for (auto& rule : _rules) - t.add (rule, false); + t.add (rule, true); // Add cells. for (unsigned int state = 0; state < _actions.size (); ++state)