From dc2cd57a5a38b1f1d93c4062be340e421d74e004 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Thu, 19 Feb 2015 17:09:59 +0100 Subject: [PATCH] identities and nongenerative rules properly fix --- alib2algo/src/grammar/simplify/LeftRecursionRemover.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/alib2algo/src/grammar/simplify/LeftRecursionRemover.cpp b/alib2algo/src/grammar/simplify/LeftRecursionRemover.cpp index 3837b8ac91..d4c760831b 100644 --- a/alib2algo/src/grammar/simplify/LeftRecursionRemover.cpp +++ b/alib2algo/src/grammar/simplify/LeftRecursionRemover.cpp @@ -93,7 +93,7 @@ grammar::EpsilonFreeCFG assignAsOrder(const grammar::EpsilonFreeCFG& origGrammar continue; } if(origGrammar.getRules().find(secondLHS) == origGrammar.getRules().end()) { //is there any right hand side to substitue with? - res.addRule(lhs, singleRHS); + //if not well this rule does not generate anything anyway continue; } @@ -109,6 +109,9 @@ grammar::EpsilonFreeCFG assignAsOrder(const grammar::EpsilonFreeCFG& origGrammar grammar::EpsilonFreeCFG LeftRecursionRemover::remove(const grammar::EpsilonFreeCFG& origGrammar) { grammar::EpsilonFreeCFG step = origGrammar; + for(const alphabet::Symbol& nonterminal : step.getNonterminalAlphabet()) { // remove identities + step.removeRule(nonterminal, std::vector<alphabet::Symbol>{nonterminal}); + } unsigned i = 0; while(i < origGrammar.getNonterminalAlphabet().size()) { grammar::EpsilonFreeCFG nextStep = assignAsOrder(directLeftRecursionRemoveAsOrder(step), i, origGrammar.getNonterminalAlphabet()); -- GitLab