From 9d239f7a801e76828e8dba893552e603e5692bf4 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 5 Jan 2016 12:00:40 -0500 Subject: [PATCH] LR0: Added ::Item::setReductionRule --- src/LR0.cpp | 11 +++++++++++ src/LR0.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/LR0.cpp b/src/LR0.cpp index bc8db326..5ab10439 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -216,6 +216,7 @@ LR0::Item::Item (const std::vector & 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 (); } diff --git a/src/LR0.h b/src/LR0.h index 74523637..e362c683 100644 --- a/src/LR0.h +++ b/src/LR0.h @@ -47,6 +47,7 @@ public: Item (const std::vector &); bool operator== (const LR0::Item&); void setGrammarRuleIndex (const int); + void setReductionRule (const int); bool advance (); bool done () const; std::string next () const; @@ -56,6 +57,7 @@ public: std::vector _rule; unsigned int _cursor; int _grammarRule; + int _reducesTo; }; class Closure : public std::vector