Esempio n. 1
0
 def setUp(self):
     self.g = Grammar(terminals=[My],
                      nonterminals=[S],
                      rules=[R],
                      start_symbol=S)
     ContextFree.remove_useless_symbols(self.g, inplace=True)
     ContextFree.remove_rules_with_epsilon(self.g, True)
     ContextFree.remove_unit_rules(self.g, True)
     ContextFree.remove_useless_symbols(self.g, inplace=True)
     ContextFree.transform_to_chomsky_normal_form(self.g, True)
Esempio n. 2
0
    def test_simpleChainingTestShouldNotChange(self):
        g = Grammar(terminals=[0, 1],
                    nonterminals=[S, A, B, C],
                    rules=[Rules],
                    start_symbol=S)
        ContextFree.remove_rules_with_epsilon(g)
        self.assertEqual(len(g.rules), 7)

        class RuleNewStoBC(Rule):
            rule = ([S], [B, C])

        class RuleNewStoAC(Rule):
            rule = ([S], [A, C])

        class RuleNewStoAB(Rule):
            rule = ([S], [A, B])

        class RuleNewAto0(Rule):
            rule = ([A], [0])

        class RuleNewStoB(Rule):
            rule = ([S], [B])

        class RuleNewStoC(Rule):
            rule = ([S], [C])

        class RuleNewStoA(Rule):
            rule = ([S], [A])

        class RuleNewStoEPS(Rule):
            rule = ([S], [EPS])

        self.assertNotIn(RuleNewStoBC, g.rules)
        self.assertNotIn(RuleNewStoAC, g.rules)
        self.assertNotIn(RuleNewStoAB, g.rules)
        self.assertNotIn(RuleNewAto0, g.rules)
        self.assertNotIn(RuleNewStoB, g.rules)
        self.assertNotIn(RuleNewStoC, g.rules)
        self.assertNotIn(RuleNewStoA, g.rules)
        self.assertNotIn(RuleNewStoEPS, g.rules)

        class RuleOldAtoEps(Rule):
            rule = ([A], [EPS])

        class RuleOldBtoEps(Rule):
            rule = ([B], [EPS])

        class RuleOldCtoEps(Rule):
            rule = ([C], [EPS])

        self.assertIn(RuleOldAtoEps, g.rules)
        self.assertIn(RuleOldBtoEps, g.rules)
        self.assertIn(RuleOldCtoEps, g.rules)
Esempio n. 3
0
 def test_simpleTestOverUnitRule(self):
     g = Grammar(terminals=[0, 1],
                 nonterminals=[S, A, B, C, D],
                 rules=[RuleS1AB, RuleB0, RuleACD, RuleCD, RuleDEps],
                 start_symbol=S)
     gr = ContextFree.transform_to_chomsky_normal_form(
         ContextFree.remove_unit_rules(
             ContextFree.remove_rules_with_epsilon(g)))
     pars = cyk(gr, [1, 0])
     s = InverseContextFree.epsilon_rules_restore(
         InverseContextFree.unit_rules_restore(
             InverseContextFree.transform_from_chomsky_normal_form(pars)))
     self.assertIsInstance(s, S)
     self.assertIsInstance(s.to_rule, RuleS1AB)
     self.assertIsInstance(s.to_rule.to_symbols[0], Terminal)
     self.assertEqual(s.to_rule.to_symbols[0].s, 1)
     b = s.to_rule.to_symbols[2]
     self.assertIsInstance(b, B)
     self.assertIsInstance(b.to_rule, RuleB0)
     self.assertIsInstance(b.to_rule.to_symbols[0], Terminal)
     self.assertEqual(b.to_rule.to_symbols[0].s, 0)
     a = s.to_rule.to_symbols[1]
     self.assertIsInstance(a, A)
     self.assertIsInstance(a.to_rule, RuleACD)
     d = a.to_rule.to_symbols[1]
     self.assertIsInstance(d, D)
     self.assertIsInstance(d.to_rule, RuleDEps)
     self.assertIs(d.to_rule.to_symbols[0].s, EPS)
     c = a.to_rule.to_symbols[0]
     self.assertIsInstance(c, C)
     self.assertIsInstance(c.to_rule, RuleCD)
     d = c.to_rule.to_symbols[0]
     self.assertIsInstance(d, D)
     self.assertIsInstance(d.to_rule, RuleDEps)
     self.assertIs(d.to_rule.to_symbols[0].s, EPS)
Esempio n. 4
0
 def test_multipleUsageShouldNotChange(self):
     g = Grammar(terminals=[0, 1, 2, 3],
                 nonterminals=[S, A, B, C, D],
                 rules=[Rules],
                 start_symbol=S)
     ContextFree.remove_rules_with_epsilon(g)
     self.assertEqual(len(g.rules), 12)
     self.assertEqual(g.rules.size(), 12)
     class RuleNewAto0A(Rule): rule = ([A], [0, A])
     class RuleNewAtoA0(Rule): rule = ([A], [A, 0])
     class RuleNewAtoB(Rule): rule = ([A], [B])
     class RuleNewAtoC(Rule): rule = ([A], [C])
     class RuleNewAtoCC(Rule): rule = ([A], [C, C])
     class RuleNewAto1(Rule): rule = ([A], [1])
     class RuleNewBto3(Rule): rule = ([B], [3])
     class RuleNewCtoA3(Rule): rule = ([C], [A, 3])
     class RuleNewDtoAB(Rule): rule = ([D], [A, B])
     class RuleNewDtoAA(Rule): rule = ([D], [A, A])
     class RuleNewDtoA3(Rule): rule = ([D], [A, 3])
     class RuleNewCto3(Rule): rule = ([C], [3])
     class RuleNewDtoA(Rule): rule = ([D], [A])
     class RuleNewDtoB(Rule): rule = ([D], [B])
     class RuleNewDto3(Rule): rule = ([D], [3])
     self.assertNotIn(RuleNewAto0A, g.rules)
     self.assertNotIn(RuleNewAtoA0, g.rules)
     self.assertNotIn(RuleNewAtoB, g.rules)
     self.assertNotIn(RuleNewAtoC, g.rules)
     self.assertNotIn(RuleNewAtoCC, g.rules)
     self.assertNotIn(RuleNewAto1, g.rules)
     self.assertNotIn(RuleNewBto3, g.rules)
     self.assertNotIn(RuleNewCtoA3, g.rules)
     self.assertNotIn(RuleNewDtoAB, g.rules)
     self.assertNotIn(RuleNewDtoAA, g.rules)
     self.assertNotIn(RuleNewDtoA3, g.rules)
     self.assertNotIn(RuleNewCto3, g.rules)
     self.assertNotIn(RuleNewDtoA, g.rules)
     self.assertNotIn(RuleNewDtoB, g.rules)
     self.assertNotIn(RuleNewDto3, g.rules)
     class BtoEps(Rule): rule=([B], [EPS])
     class CtoEps(Rule): rule=([B], [EPS])
     self.assertIn(BtoEps, g.rules)
     self.assertIn(CtoEps, g.rules)
Esempio n. 5
0
    def test_simpleTestShouldNotChange(self):
        g = Grammar(terminals=[1], nonterminals=[S, A, B, C], rules=[Rules])
        ContextFree.remove_rules_with_epsilon(g)
        self.assertEqual(g.rules.size(), 6)

        class RuleNewS(Rule):
            rule = ([S], [1])

        class RuleNewA(Rule):
            rule = ([A], [1])

        self.assertNotIn(RuleNewS, g.rules)
        self.assertNotIn(RuleNewA, g.rules)

        class OldA(Rule):
            rule = ([A], [EPS])

        class OldB(Rule):
            rule = ([B], [EPS])

        self.assertIn(OldA, g.rules)
        self.assertIn(OldB, g.rules)
Esempio n. 6
0
    def test_simpleTestShouldChange(self):
        g = Grammar(terminals=[1],
                    nonterminals=[S, A, B, C],
                    rules=[Rules],
                    start_symbol=S)
        ContextFree.remove_rules_with_epsilon(g, True)
        self.assertEqual(g.rules.size(), 6)

        class RuleNewS(Rule):
            rule = ([S], [1])

        class RuleNewA(Rule):
            rule = ([A], [1])

        self.assertIn(RuleNewS, g.rules)
        self.assertIn(RuleNewA, g.rules)
        fromS = list(filter(lambda x: hash(x) == hash(RuleNewS), g.rules))[0]
        self.assertEqual(fromS.fromSymbol, S)
        self.assertEqual(fromS.toSymbol, 1)
        self.assertTrue(isclass(fromS))
        self.assertTrue(issubclass(fromS, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromS.from_rule.rule, ([S], [1, B]))
        self.assertEqual(fromS.replace_index, 1)
        fromA = list(filter(lambda x: hash(x) == hash(RuleNewA), g.rules))[0]
        self.assertEqual(fromA.fromSymbol, A)
        self.assertEqual(fromA.toSymbol, 1)
        self.assertTrue(isclass(fromA))
        self.assertTrue(issubclass(fromA, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromA.from_rule.rule, ([A], [1, B]))
        self.assertEqual(fromA.replace_index, 1)

        class OldA(Rule):
            rule = ([A], [EPS])

        class OldB(Rule):
            rule = ([B], [EPS])

        self.assertNotIn(OldA, g.rules)
        self.assertNotIn(OldB, g.rules)
Esempio n. 7
0
 def test_simpleChainingTestShouldChange(self):
     g = Grammar(terminals=[0, 1],
                 nonterminals=[S, A, B, C],
                 rules=[Rules],
                 start_symbol=S)
     ContextFree.remove_rules_with_epsilon(g, True)
     self.assertEqual(len(g.rules), 11)
     class RuleNewSto0(Rule): rule = ([S], [0])
     class RuleNewSto1(Rule): rule = ([S], [1])
     class RuleNewStoC(Rule): rule = ([S], [C])
     class RuleNewStoEPS(Rule): rule = ([S], [EPS])
     self.assertIn(RuleNewSto0, g.rules)
     self.assertIn(RuleNewSto1, g.rules)
     self.assertIn(RuleNewStoC, g.rules)
     self.assertIn(RuleNewStoEPS, g.rules)
     fromSto0 = list(filter(lambda x: hash(x) == hash(RuleNewSto0), g.rules))[0]
     self.assertTrue(isclass(fromSto0))
     self.assertTrue(issubclass(fromSto0, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromSto0.from_rule.rule, ([S], [0, A]))
     self.assertEqual(fromSto0.replace_index, 1)
     fromSto1 = list(filter(lambda x: hash(x) == hash(RuleNewSto1), g.rules))[0]
     self.assertTrue(isclass(fromSto1))
     self.assertTrue(issubclass(fromSto1, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromSto1.from_rule.rule, ([S], [1, C]))
     self.assertEqual(fromSto1.replace_index, 1)
     fromStoC = list(filter(lambda x: hash(x) == hash(RuleNewStoC), g.rules))[0]
     self.assertTrue(isclass(fromStoC))
     self.assertTrue(issubclass(fromStoC, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromStoC.from_rule.rule, ([S], [C, C]))
     self.assertEqual(fromStoC.replace_index, 0)
     fromStoEPS = list(filter(lambda x: hash(x) == hash(RuleNewStoEPS), g.rules))[0]
     self.assertTrue(isclass(fromStoEPS))
     self.assertTrue(issubclass(fromStoEPS, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromStoEPS.from_rule.rule, ([S], [C]))
     self.assertEqual(fromStoEPS.replace_index, 0)
     class RuleOldBtoEps(Rule): rule = ([B], [EPS])
     self.assertNotIn(RuleOldBtoEps, g.rules)
Esempio n. 8
0
 def test_simpleTestOverUnitRule(self):
     g = Grammar(
         terminals=[0, 1, 2, 3],
         nonterminals=[S, A, B, C],
         rules=[RuleS0A, RuleAB, RuleAEps, RuleBEps, RuleB1C, RuleC11],
         start_symbol=S)
     gr = ContextFree.transform_to_chomsky_normal_form(
         ContextFree.remove_unit_rules(
             ContextFree.remove_rules_with_epsilon(g)))
     pars = cyk(gr, [0])
     s = InverseContextFree.epsilon_rules_restore(
         InverseContextFree.unit_rules_restore(
             InverseContextFree.transform_from_chomsky_normal_form(pars)))
     self.assertIsInstance(s, S)
     self.assertIsInstance(s.to_rule, RuleS0A)
     self.assertIsInstance(s.to_rule.to_symbols[0], Terminal)
     self.assertEqual(s.to_rule.to_symbols[0].s, 0)
     a = s.to_rule.to_symbols[1]
     self.assertIsInstance(a, A)
     self.assertIsInstance(a.to_rule, RuleAEps)
     self.assertIs(a.to_rule.to_symbols[0].s, EPS)
Esempio n. 9
0
 def test_multipleUsage(self):
     g = Grammar(terminals=[0, 1, 2, 3],
                 nonterminals=[S, A, B, C, D],
                 rules=[Rules],
                 start_symbol=S)
     com = ContextFree.remove_rules_with_epsilon(g)
     self.assertEqual(len(com.rules), 25)
     self.assertEqual(com.rules.size(), 25)
     class RuleNewSto0A(Rule): rule = ([S], [0, A])
     self.assertIn(RuleNewSto0A, com.rules)
     fromSto0A = list(filter(lambda x: hash(x) == hash(RuleNewSto0A), com.rules))[0]
     self.assertTrue(isclass(fromSto0A))
     self.assertTrue(issubclass(fromSto0A, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromSto0A.from_rule.rule, ([S], [A, 0, A]))
     self.assertEqual(fromSto0A.replace_index, 0)
     class RuleNewStoA0(Rule): rule = ([S], [A, 0])
     self.assertIn(RuleNewStoA0, com.rules)
     fromStoA0 = list(filter(lambda x: hash(x) == hash(RuleNewStoA0), com.rules))[0]
     self.assertTrue(isclass(fromStoA0))
     self.assertTrue(issubclass(fromStoA0, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromStoA0.from_rule.rule, ([S], [A, 0, A]))
     self.assertEqual(fromStoA0.replace_index, 2)
     class RuleNewAtoB(Rule): rule = ([A], [B])
     self.assertIn(RuleNewAtoB, com.rules)
     fromAtoB = list(filter(lambda x: hash(x) == hash(RuleNewAtoB), com.rules))[0]
     self.assertTrue(isclass(fromAtoB))
     self.assertTrue(issubclass(fromAtoB, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromAtoB.from_rule.rule, ([A], [B, C]))
     self.assertEqual(fromAtoB.replace_index, 1)
     class RuleNewAtoC(Rule): rule = ([A], [C])
     self.assertIn(RuleNewAtoC, com.rules)
     fromAtoC = list(filter(lambda x: hash(x) == hash(RuleNewAtoC), com.rules))[0]
     self.assertTrue(isclass(fromAtoC))
     self.assertTrue(issubclass(fromAtoC, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromAtoC.from_rule.rule, ([A], [B, C]))
     self.assertEqual(fromAtoC.replace_index, 0)
     class RuleNewAtoCC(Rule): rule = ([A], [C, C])
     self.assertIn(RuleNewAtoCC, com.rules)
     fromAtoCC = list(filter(lambda x: hash(x) == hash(RuleNewAtoCC), com.rules))[0]
     self.assertTrue(isclass(fromAtoCC))
     self.assertTrue(issubclass(fromAtoCC, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromAtoCC.from_rule.rule, ([A], [C, C, C]))
     self.assertEqual(fromAtoCC.replace_index, 0)
     class RuleNewBto1(Rule): rule = ([B], [1])
     self.assertIn(RuleNewBto1, com.rules)
     fromBto1 = list(filter(lambda x: hash(x) == hash(RuleNewBto1), com.rules))[0]
     self.assertTrue(isclass(fromBto1))
     self.assertTrue(issubclass(fromBto1, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromBto1.from_rule.rule, ([B], [1, C]))
     self.assertEqual(fromBto1.replace_index, 1)
     class RuleNewBto3(Rule): rule = ([B], [3])
     self.assertIn(RuleNewBto3, com.rules)
     fromBto3 = list(filter(lambda x: hash(x) == hash(RuleNewBto3), com.rules))[0]
     self.assertTrue(isclass(fromBto3))
     self.assertTrue(issubclass(fromBto3, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromBto3.from_rule.rule, ([B], [3, D]))
     self.assertEqual(fromBto3.replace_index, 1)
     class RuleNewCtoA3(Rule): rule = ([C], [A, 3])
     self.assertIn(RuleNewCtoA3, com.rules)
     fromCtoA3 = list(filter(lambda x: hash(x) == hash(RuleNewCtoA3), com.rules))[0]
     self.assertTrue(isclass(fromCtoA3))
     self.assertTrue(issubclass(fromCtoA3, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromCtoA3.from_rule.rule, ([C], [A, A, 3]))
     self.assertEqual(fromCtoA3.replace_index, 0)
     class RuleNewDtoAB(Rule): rule = ([D], [A, B])
     self.assertIn(RuleNewDtoAB, com.rules)
     fromDtoAB = list(filter(lambda x: hash(x) == hash(RuleNewDtoAB), com.rules))[0]
     self.assertTrue(isclass(fromDtoAB))
     self.assertTrue(issubclass(fromDtoAB, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromDtoAB.from_rule.rule, ([D], [A, A, B]))
     self.assertEqual(fromDtoAB.replace_index, 0)
     class RuleNewDtoAA(Rule): rule = ([D], [A, A])
     self.assertIn(RuleNewDtoAA, com.rules)
     fromDtoAA = list(filter(lambda x: hash(x) == hash(RuleNewDtoAA), com.rules))[0]
     self.assertTrue(isclass(fromDtoAA))
     self.assertTrue(issubclass(fromDtoAA, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromDtoAA.from_rule.rule, ([D], [A, A, B]))
     self.assertEqual(fromDtoAA.replace_index, 2)
     class RuleNewDtoA3(Rule): rule = ([D], [A, 3])
     self.assertIn(RuleNewDtoA3, com.rules)
     fromDtoA3 = list(filter(lambda x: hash(x) == hash(RuleNewDtoA3), com.rules))[0]
     self.assertTrue(isclass(fromDtoA3))
     self.assertTrue(issubclass(fromDtoA3, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromDtoA3.from_rule.rule, ([D], [A, A, 3]))
     self.assertEqual(fromDtoA3.replace_index, 0)
     class RuleNewCto3(Rule): rule = ([C], [3])
     self.assertIn(RuleNewCto3, com.rules)
     fromCto3 = list(filter(lambda x: hash(x) == hash(RuleNewCto3), com.rules))[0]
     self.assertTrue(isclass(fromCto3))
     self.assertTrue(issubclass(fromCto3, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromCto3.from_rule.rule, ([C], [A, 3]))
     self.assertEqual(fromCto3.replace_index, 0)
     class RuleNewDtoA(Rule): rule = ([D], [A])
     self.assertIn(RuleNewDtoA, com.rules)
     fromDtoA = list(filter(lambda x: hash(x) == hash(RuleNewDtoA), com.rules))[0]
     self.assertTrue(isclass(fromDtoA))
     self.assertTrue(issubclass(fromDtoA, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromDtoA.from_rule.rule, ([D], [A, B]))
     self.assertEqual(fromDtoA.replace_index, 1)
     class RuleNewDtoB(Rule): rule = ([D], [B])
     self.assertIn(RuleNewDtoB, com.rules)
     fromDtoB = list(filter(lambda x: hash(x) == hash(RuleNewDtoB), com.rules))[0]
     self.assertTrue(isclass(fromDtoB))
     self.assertTrue(issubclass(fromDtoB, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromDtoB.from_rule.rule, ([D], [A, B]))
     self.assertEqual(fromDtoB.replace_index, 0)
     class RuleNewDto3(Rule): rule = ([D], [3])
     self.assertIn(RuleNewDto3, com.rules)
     fromDto3 = list(filter(lambda x: hash(x) == hash(RuleNewDto3), com.rules))[0]
     self.assertTrue(isclass(fromDto3))
     self.assertTrue(issubclass(fromDto3, ContextFree.EpsilonRemovedRule))
     self.assertEqual(fromDto3.from_rule.rule, ([D], [A, 3]))
     self.assertEqual(fromDto3.replace_index, 0)
     class BtoEps(Rule): rule=([B], [EPS])
     class CtoEps(Rule): rule=([B], [EPS])
     self.assertNotIn(BtoEps, com.rules)
     self.assertNotIn(CtoEps, com.rules)
Esempio n. 10
0
    def test_simpleChainingTest(self):
        g = Grammar(terminals=[0, 1],
                    nonterminals=[S, A, B, C],
                    rules=[Rules],
                    start_symbol=S)
        com = ContextFree.remove_rules_with_epsilon(g)
        self.assertEqual(len(com.rules), 12)

        class RuleNewStoBC(Rule):
            rule = ([S], [B, C])

        class RuleNewStoAC(Rule):
            rule = ([S], [A, C])

        class RuleNewStoAB(Rule):
            rule = ([S], [A, B])

        class RuleNewAto0(Rule):
            rule = ([A], [0])

        class RuleNewStoB(Rule):
            rule = ([S], [B])

        class RuleNewStoC(Rule):
            rule = ([S], [C])

        class RuleNewStoA(Rule):
            rule = ([S], [A])

        class RuleNewStoEPS(Rule):
            rule = ([S], [EPS])

        self.assertIn(RuleNewStoBC, com.rules)
        self.assertIn(RuleNewStoAC, com.rules)
        self.assertIn(RuleNewStoAB, com.rules)
        self.assertIn(RuleNewAto0, com.rules)
        self.assertIn(RuleNewStoB, com.rules)
        self.assertIn(RuleNewStoC, com.rules)
        self.assertIn(RuleNewStoA, com.rules)
        self.assertIn(RuleNewStoEPS, com.rules)
        fromStoBC = list(
            filter(lambda x: hash(x) == hash(RuleNewStoBC), com.rules))[0]
        self.assertTrue(isclass(fromStoBC))
        self.assertTrue(issubclass(fromStoBC, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromStoBC.from_rule.rule, ([S], [A, B, C]))
        self.assertEqual(fromStoBC.replace_index, 0)
        fromStoAC = list(
            filter(lambda x: hash(x) == hash(RuleNewStoAC), com.rules))[0]
        self.assertTrue(isclass(fromStoAC))
        self.assertTrue(issubclass(fromStoAC, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromStoAC.from_rule.rule, ([S], [A, B, C]))
        self.assertEqual(fromStoAC.replace_index, 1)
        fromStoAB = list(
            filter(lambda x: hash(x) == hash(RuleNewStoAB), com.rules))[0]
        self.assertTrue(isclass(fromStoAB))
        self.assertTrue(issubclass(fromStoAB, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromStoAB.from_rule.rule, ([S], [A, B, C]))
        self.assertEqual(fromStoAB.replace_index, 2)
        fromAto0 = list(
            filter(lambda x: hash(x) == hash(RuleNewAto0), com.rules))[0]
        self.assertTrue(isclass(fromAto0))
        self.assertTrue(issubclass(fromAto0, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromAto0.from_rule.rule, ([A], [0, A]))
        self.assertEqual(fromAto0.replace_index, 1)
        fromStoA = list(
            filter(lambda x: hash(x) == hash(RuleNewStoA), com.rules))[0]
        self.assertTrue(isclass(fromStoA))
        self.assertTrue(issubclass(fromStoA, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromStoA.from_rule.rule, ([S], [A, C]))
        self.assertEqual(fromStoA.replace_index, 1)
        fromStoB = list(
            filter(lambda x: hash(x) == hash(RuleNewStoB), com.rules))[0]
        self.assertTrue(isclass(fromStoB))
        self.assertTrue(issubclass(fromStoB, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromStoB.from_rule.rule, ([S], [B, C]))
        self.assertEqual(fromStoB.replace_index, 1)
        fromStoC = list(
            filter(lambda x: hash(x) == hash(RuleNewStoC), com.rules))[0]
        self.assertTrue(isclass(fromStoC))
        self.assertTrue(issubclass(fromStoC, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromStoC.from_rule.rule, ([S], [B, C]))
        self.assertEqual(fromStoC.replace_index, 0)
        fromStoEPS = list(
            filter(lambda x: hash(x) == hash(RuleNewStoEPS), com.rules))[0]
        self.assertTrue(isclass(fromStoEPS))
        self.assertTrue(issubclass(fromStoEPS, ContextFree.EpsilonRemovedRule))
        self.assertEqual(fromStoEPS.from_rule.rule, ([S], [C]))
        self.assertEqual(fromStoEPS.replace_index, 0)

        class RuleOldAtoEps(Rule):
            rule = ([A], [EPS])

        class RuleOldBtoEps(Rule):
            rule = ([B], [EPS])

        class RuleOldCtoEps(Rule):
            rule = ([C], [EPS])

        self.assertNotIn(RuleOldAtoEps, com.rules)
        self.assertNotIn(RuleOldBtoEps, com.rules)
        self.assertNotIn(RuleOldCtoEps, com.rules)