mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
LR0: Implemented full ::expand method
This commit is contained in:
parent
f4bff57b09
commit
819beb5909
1 changed files with 22 additions and 1 deletions
23
src/LR0.cpp
23
src/LR0.cpp
|
@ -133,10 +133,31 @@ std::set <std::string> LR0::getExpected (const Closure& closure) const
|
|||
// Add all items to the result set matching the production rule for symbol.
|
||||
LR0::Closure LR0::expand (const std::string& symbol) const
|
||||
{
|
||||
std::set <std::string> seen;
|
||||
|
||||
LR0::Closure result;
|
||||
for (auto& rule : _augmented)
|
||||
{
|
||||
if (rule[0] == symbol)
|
||||
result.push_back (Item (rule));
|
||||
{
|
||||
Item item (rule);
|
||||
result.push_back (item);
|
||||
seen.insert (rule[0]);
|
||||
|
||||
auto nextSymbol = item.next ();
|
||||
if (seen.find (nextSymbol) == seen.end ())
|
||||
{
|
||||
for (auto& rule : _augmented)
|
||||
{
|
||||
if (rule[0] == nextSymbol)
|
||||
{
|
||||
result.push_back (Item (rule));
|
||||
seen.insert (nextSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue