30 lines
729 B
C++
30 lines
729 B
C++
#include "Parsodus/lrtables/SLR1Itemset.h"
|
|
|
|
#include <algorithm>
|
|
|
|
namespace pds {
|
|
namespace lr {
|
|
|
|
SLR1Itemset::SLR1Itemset() : LR0ItemsetBase<SLR1Itemset>()
|
|
{}
|
|
|
|
SLR1Itemset::SLR1Itemset(std::shared_ptr<Rule> start) : LR0ItemsetBase<SLR1Itemset>(start)
|
|
{}
|
|
|
|
bool SLR1Itemset::needsFollow() {
|
|
return true;
|
|
}
|
|
|
|
std::set<std::size_t> SLR1Itemset::getReduces(const Grammar& g, std::string lookahead) const {
|
|
std::set<std::size_t> res;
|
|
for (auto& item : m_items) {
|
|
if (item.dotIdx >= item.rule->tail.size() && (*g.follow)(item.rule->head).count(lookahead)) {
|
|
res.insert(std::find(g.rules.begin(), g.rules.end(), item.rule) - g.rules.begin());
|
|
}
|
|
}
|
|
return res;
|
|
}
|
|
|
|
} /* lr */
|
|
} /* pds */
|