From c33e12f099aa561a53dbeda5793fdfa854274e0a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 5 Jan 2016 01:48:38 -0500 Subject: [PATCH] LR0: Added ::Item::operator== --- src/LR0.cpp | 15 +++++++++++++++ src/LR0.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/LR0.cpp b/src/LR0.cpp index d84995d3..f99c854d 100644 --- a/src/LR0.cpp +++ b/src/LR0.cpp @@ -225,6 +225,21 @@ LR0::Item::Item (const std::vector & rule) _rule.pop_back (); } +//////////////////////////////////////////////////////////////////////////////// +bool LR0::Item::operator== (const Item& other) +{ + if (_cursor != other._cursor || + _grammarRule != other._grammarRule || + _rule.size () != other._rule.size ()) + return false; + + for (unsigned int i = 0; i < _rule.size () - 1; ++i) + if (_rule[i] != other._rule[i]) + return false; + + return true; +} + //////////////////////////////////////////////////////////////////////////////// void LR0::Item::setGrammarRuleIndex (const int rule) { diff --git a/src/LR0.h b/src/LR0.h index 3b0437dd..50833fca 100644 --- a/src/LR0.h +++ b/src/LR0.h @@ -45,6 +45,7 @@ public: { public: Item (const std::vector &); + bool operator== (const LR0::Item&); void setGrammarRuleIndex (const int); bool advance (); bool done () const;