mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
LR0: Cleaner parse table dump
This commit is contained in:
parent
2890d73f24
commit
62f11f6603
1 changed files with 7 additions and 7 deletions
14
src/LR0.cpp
14
src/LR0.cpp
|
@ -28,6 +28,7 @@
|
||||||
#include <LR0.h>
|
#include <LR0.h>
|
||||||
#include <Table.h>
|
#include <Table.h>
|
||||||
#include <Color.h>
|
#include <Color.h>
|
||||||
|
#include <Lexer.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -203,11 +204,13 @@ void LR0::createParseTable (States& states)
|
||||||
for (unsigned int state = 0; state < states.size (); ++state)
|
for (unsigned int state = 0; state < states.size (); ++state)
|
||||||
for (unsigned int item = 0; item < states[state].size (); ++item)
|
for (unsigned int item = 0; item < states[state].size (); ++item)
|
||||||
if (states[state][item].done ())
|
if (states[state][item].done ())
|
||||||
|
{
|
||||||
if (states[state][item]._grammarRule == 0)
|
if (states[state][item]._grammarRule == 0)
|
||||||
_actions[state]["$"] = "acc";
|
_actions[state]["$"] = "acc";
|
||||||
else
|
else
|
||||||
for (auto& terminal : _terminals)
|
for (auto& terminal : _terminals)
|
||||||
_actions[state][terminal] = format ("r{1}", states[state][item]._grammarRule);
|
_actions[state][terminal] = format ("r{1}", states[state][item]._grammarRule);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,8 +228,7 @@ void LR0::debug (bool value)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// +-------+---------------+---------------+
|
// +-------+---------------+---------------+
|
||||||
// | state | actions... | goto... |
|
// | state | terminals $ | non-terminals |
|
||||||
// | | terminals $ | non-terminals |
|
|
||||||
// +-------+--+--+--+--+---+----+-----+----+
|
// +-------+--+--+--+--+---+----+-----+----+
|
||||||
// | | | | | | | | | |
|
// | | | | | | | | | |
|
||||||
// +-------+--+--+--+--+---+----+-----+----+
|
// +-------+--+--+--+--+---+----+-----+----+
|
||||||
|
@ -242,14 +244,12 @@ std::string LR0::dump () const
|
||||||
t.colorHeader (Color ("underline"));
|
t.colorHeader (Color ("underline"));
|
||||||
|
|
||||||
// Add columns.
|
// Add columns.
|
||||||
t.add ("State", false);
|
t.add ("State", true);
|
||||||
for (auto& terminal : _terminals)
|
for (auto& terminal : _terminals)
|
||||||
t.add (terminal, false);
|
t.add (Lexer::dequote (terminal), true);
|
||||||
|
|
||||||
t.add ("$", false);
|
|
||||||
|
|
||||||
for (auto& rule : _rules)
|
for (auto& rule : _rules)
|
||||||
t.add (rule, false);
|
t.add (rule, true);
|
||||||
|
|
||||||
// Add cells.
|
// Add cells.
|
||||||
for (unsigned int state = 0; state < _actions.size (); ++state)
|
for (unsigned int state = 0; state < _actions.size (); ++state)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue