LR0: Added ::Item::setReductionRule

This commit is contained in:
Paul Beckingham 2016-01-05 12:00:40 -05:00
parent 88e932ea2e
commit 9d239f7a80
2 changed files with 13 additions and 0 deletions

View file

@ -216,6 +216,7 @@ LR0::Item::Item (const std::vector <std::string>& rule)
: _rule (rule)
, _cursor (2)
, _grammarRule (-1)
, _reducesTo (-1)
{
if (_rule.size () == 3 && _rule[2] == "є")
_rule.pop_back ();
@ -226,6 +227,7 @@ bool LR0::Item::operator== (const Item& other)
{
if (_cursor != other._cursor ||
_grammarRule != other._grammarRule ||
_reducesTo != other._reducesTo ||
_rule.size () != other._rule.size ())
return false;
@ -242,6 +244,12 @@ void LR0::Item::setGrammarRuleIndex (const int rule)
_grammarRule = rule;
}
////////////////////////////////////////////////////////////////////////////////
void LR0::Item::setReductionRule (const int rule)
{
_reducesTo = rule;
}
////////////////////////////////////////////////////////////////////////////////
bool LR0::Item::advance ()
{
@ -286,6 +294,9 @@ std::string LR0::Item::dump () const
if (_grammarRule != -1)
out << " [g" << _grammarRule << "]";
if (_reducesTo != -1)
out << " [r" << _reducesTo << "]";
return out.str ();
}