LR0: Added ::dump method to display intermediate parsing table

This commit is contained in:
Paul Beckingham 2015-12-27 11:18:47 -05:00
parent 26e0a472ac
commit ad5f1e4fd7
2 changed files with 37 additions and 0 deletions

View file

@ -132,3 +132,39 @@ std::string LR0::dump () const
}
////////////////////////////////////////////////////////////////////////////////
std::string LR0::dump (std::vector <std::vector <std::string>>& 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 ();
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -60,6 +60,7 @@ protected:
private:
bool expandNonTerminals (std::vector <std::vector <std::string>>&, std::vector <std::pair <int, int>>&);
std::string dump (std::vector <std::vector <std::string>>&, States&) const;
private:
// state column result