mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
LR0: ::dump now includes the action and goto tables
This commit is contained in:
parent
1211dda9b0
commit
ab2eb68d7c
1 changed files with 24 additions and 8 deletions
32
src/LR0.cpp
32
src/LR0.cpp
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <LR0.h>
|
||||
#include <Table.h>
|
||||
#include <Color.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -220,20 +222,34 @@ std::string LR0::dump () const
|
|||
std::stringstream out;
|
||||
out << "Parser Tables\n";
|
||||
|
||||
Table t;
|
||||
t.leftMargin (2);
|
||||
t.colorHeader (Color ("underline"));
|
||||
|
||||
// Add columns.
|
||||
t.add ("State", false);
|
||||
for (auto& terminal : _terminals)
|
||||
t.add (terminal, false);
|
||||
|
||||
for (auto& rule : _rules)
|
||||
t.add (rule, false);
|
||||
|
||||
// Add cells.
|
||||
for (unsigned int state = 0; state < _actions.size (); ++state)
|
||||
{
|
||||
out << " " << state;
|
||||
for (auto& terminal : _actions[state])
|
||||
out << " " << terminal.first << ":" << terminal.second;
|
||||
int row = t.addRow ();
|
||||
int col = 0;
|
||||
t.set (row, col++, state);
|
||||
|
||||
out << " ";
|
||||
for (auto& terminal : _terminals)
|
||||
t.set (row, col++, _actions[state].at (terminal));
|
||||
|
||||
for (auto& rule : _goto[state])
|
||||
out << " " << rule.first << ":" << rule.second;
|
||||
|
||||
out << "\n";
|
||||
for (auto& rule : _rules)
|
||||
t.set (row, col++, _goto[state].at (rule));
|
||||
}
|
||||
|
||||
out << t.render ();
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue