mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
LR0: ::expandNonTerminals now writes expansion state in debug mode
This commit is contained in:
parent
08457be4a0
commit
474ed85811
1 changed files with 29 additions and 1 deletions
30
src/LR0.cpp
30
src/LR0.cpp
|
@ -51,6 +51,8 @@ void LR0::createParseTables (const Grammar& grammar)
|
||||||
std::cout << " " << term;
|
std::cout << " " << term;
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all items from augmented grammar, in initial state:
|
// Add all items from augmented grammar, in initial state:
|
||||||
|
@ -59,7 +61,7 @@ void LR0::createParseTables (const Grammar& grammar)
|
||||||
for (unsigned int i = 0; i < augmented.size (); ++i)
|
for (unsigned int i = 0; i < augmented.size (); ++i)
|
||||||
items.push_back (std::pair <int, int> (i, 0));
|
items.push_back (std::pair <int, int> (i, 0));
|
||||||
|
|
||||||
// TODO Add new states.
|
// Iteratively expand non-terminals until there are no more.
|
||||||
while (expandNonTerminals (augmented, items))
|
while (expandNonTerminals (augmented, items))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +71,32 @@ bool LR0::expandNonTerminals (
|
||||||
std::vector <std::vector <std::string>>& augmented,
|
std::vector <std::vector <std::string>>& augmented,
|
||||||
std::vector <std::pair <int, int>>& items)
|
std::vector <std::pair <int, int>>& items)
|
||||||
{
|
{
|
||||||
|
if (_debug)
|
||||||
|
{
|
||||||
|
std::cout << "Expand:\n";
|
||||||
|
int count = 0;
|
||||||
|
for (auto& item : items)
|
||||||
|
{
|
||||||
|
std::cout << " [" << count++ << "] "
|
||||||
|
<< augmented[item.first][0]
|
||||||
|
<< " "
|
||||||
|
<< augmented[item.first][1];
|
||||||
|
|
||||||
|
for (int i = 2; i < (int)augmented[item.first].size (); ++i)
|
||||||
|
{
|
||||||
|
if (i - 2 == item.second)
|
||||||
|
std::cout << " .";
|
||||||
|
|
||||||
|
std::cout << " " << augmented[item.first][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue