예제 #1
0
 def test_simpleTestShouldNotChange(self):
     g = Grammar(terminals=[0,1,2,3],
                 nonterminals=[S, A, B, C, D],
                 rules=[Rules],
                 start_symbol=S)
     ContextFree.remove_unit_rules(g)
     # Removed
     class RuleStoA(Rule): rule = ([S], [A])
     self.assertTrue(g.have_rule(RuleStoA))
     class RuleStoB(Rule): rule = ([S], [B])
     self.assertTrue(g.have_rule(RuleStoB))
     class RuleAtoC(Rule): rule = ([A], [C])
     self.assertTrue(g.have_rule(RuleAtoC))
     class RuleBtoD(Rule): rule = ([B], [D])
     self.assertTrue(g.have_rule(RuleBtoD))
     # Old rules
     class RuleNewAto0A(Rule): rule = ([A], [0, A])
     self.assertTrue(g.have_rule(RuleNewAto0A))
     class RuleNewAto1S(Rule): rule = ([A], [1, S])
     self.assertTrue(g.have_rule(RuleNewAto1S))
     class RuleNewBto2B(Rule): rule = ([B], [2, B])
     self.assertTrue(g.have_rule(RuleNewBto2B))
     class RuleNewBto3S(Rule): rule = ([B], [3, S])
     self.assertTrue(g.have_rule(RuleNewBto3S))
     class RuleNewCto1C(Rule): rule = ([C], [1, C])
     self.assertTrue(g.have_rule(RuleNewCto1C))
     class RuleNewCto0(Rule): rule = ([C], [0])
     self.assertTrue(g.have_rule(RuleNewCto0))
     class RuleNewDto3D(Rule): rule = ([D], [3, D])
     self.assertTrue(g.have_rule(RuleNewDto3D))
     class RuleNewDto2(Rule): rule = ([D], [2])
     self.assertTrue(g.have_rule(RuleNewDto2))
     # New rules
     class RuleNewSto0A(Rule): rule = ([S], [0, A])
     self.assertFalse(g.have_rule(RuleNewSto0A))
     class RuleNewSto1S(Rule): rule = ([S], [1, S])
     self.assertFalse(g.have_rule(RuleNewSto1S))
     class RuleNewSto1C(Rule): rule = ([S], [1, C])
     self.assertFalse(g.have_rule(RuleNewSto1C))
     class RuleNewSto0(Rule): rule = ([S], [0])
     self.assertFalse(g.have_rule(RuleNewSto0))
     class RuleNewSto2B(Rule): rule = ([S], [2, B])
     self.assertFalse(g.have_rule(RuleNewSto2B))
     class RuleNewSto3S(Rule): rule = ([S], [3, S])
     self.assertFalse(g.have_rule(RuleNewSto3S))
     class RuleNewSto3D(Rule): rule = ([S], [3, D])
     self.assertFalse(g.have_rule(RuleNewSto3D))
     class RuleNewSto2(Rule): rule = ([S], [2])
     self.assertFalse(g.have_rule(RuleNewSto2))
     class RuleNewAto1C(Rule): rule = ([A], [1, C])
     self.assertFalse(g.have_rule(RuleNewAto1C))
     class RuleNewAto0(Rule): rule = ([A], [0])
     self.assertFalse(g.have_rule(RuleNewAto0))
     class RuleNewBto3D(Rule): rule = ([B], [3, D])
     self.assertFalse(g.have_rule(RuleNewBto3D))
     class RuleNewBto2(Rule): rule = ([B], [2])
     self.assertFalse(g.have_rule(RuleNewBto2))
 def setUp(self):
     self.g = Grammar(terminals=[My],
                      nonterminals=[S],
                      rules=[R],
                      start_symbol=S)
     ContextFree.remove_useless_symbols(self.g, transform_grammar=True)
     ContextFree.remove_rules_with_epsilon(self.g, transform_grammar=True)
     ContextFree.remove_unit_rules(self.g, transform_grammar=True)
     ContextFree.remove_useless_symbols(self.g, transform_grammar=True)
     ContextFree.transform_to_chomsky_normal_form(self.g, transform_grammar=True)
 def test_simpleTestShouldNotChange(self):
     g = Grammar(terminals=[0, 1],
                 nonterminals=[S, A, B, C],
                 rules=[Rules],
                 start_symbol=S)
     ContextFree.remove_unit_rules(g)
     # Removed
     class RuleStoA(Rule): rule=([S], [A])
     self.assertTrue(g.have_rule(RuleStoA))
     class RuleAtoB(Rule): rule=([A], [B])
     self.assertTrue(g.have_rule(RuleAtoB))
     class RuleBtoC(Rule): rule=([B], [C])
     self.assertTrue(g.have_rule(RuleBtoC))
     # Old rules
     class RuleNewSto0B0(Rule): rule = ([S], [0, B, 0])
     self.assertTrue(g.have_rule(RuleNewSto0B0))
     class RuleNewAto0A(Rule): rule = ([A], [0, A])
     self.assertTrue(g.have_rule(RuleNewAto0A))
     class RuleNewBto1B(Rule): rule = ([B], [1, B])
     self.assertTrue(g.have_rule(RuleNewBto1B))
     class RuleNewBtoAB(Rule): rule = ([B], [A, B])
     self.assertTrue(g.have_rule(RuleNewBtoAB))
     class RuleNewBtoEPS(Rule): rule = ([B], [EPS])
     self.assertTrue(g.have_rule(RuleNewBtoEPS))
     class RuleNewCto1A(Rule): rule = ([C], [1, A])
     self.assertTrue(g.have_rule(RuleNewCto1A))
     class RuleNewCto1(Rule): rule = ([C], [1])
     self.assertTrue(g.have_rule(RuleNewCto1))
     # New rules
     class RuleNewSto0A(Rule): rule = ([S], [0, A])
     self.assertFalse(g.have_rule(RuleNewSto0A))
     class RuleNewSto1B(Rule): rule = ([S], [1, B])
     self.assertFalse(g.have_rule(RuleNewSto1B))
     class RuleNewStoAB(Rule): rule = ([S], [A, B])
     self.assertFalse(g.have_rule(RuleNewStoAB))
     class RuleNewStoEPS(Rule): rule = ([S], [EPS])
     self.assertFalse(g.have_rule(RuleNewStoEPS))
     class RuleNewSto1A(Rule): rule = ([S], [1, A])
     self.assertFalse(g.have_rule(RuleNewSto1A))
     class RuleNewSto1(Rule): rule = ([S], [1])
     self.assertFalse(g.have_rule(RuleNewSto1))
     class RuleNewAto1B(Rule): rule = ([A], [1, B])
     self.assertFalse(g.have_rule(RuleNewAto1B))
     class RuleNewAtoAB(Rule): rule = ([A], [A, B])
     self.assertFalse(g.have_rule(RuleNewAtoAB))
     class RuleNewAtoEPS(Rule): rule = ([A], [EPS])
     self.assertFalse(g.have_rule(RuleNewAtoEPS))
     class RuleNewAto1A(Rule): rule = ([A], [1, A])
     self.assertFalse(g.have_rule(RuleNewAto1A))
     class RuleNewAto1(Rule): rule = ([A], [1])
     self.assertFalse(g.have_rule(RuleNewAto1))
     class RuleNewBto1A(Rule): rule = ([B], [1, A])
     self.assertFalse(g.have_rule(RuleNewBto1A))
     class RuleNewBto1(Rule): rule = ([B], [1])
     self.assertFalse(g.have_rule(RuleNewBto1))
예제 #4
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)
 def test_repeatOfC(self):
     g = Grammar(terminals=[0, 1, 2, 3],
                 nonterminals=[S, A, B, C, D],
                 rules=[
                     RuleSA, RuleSB, RuleAC, RuleA0A, RuleBD, RuleB2B,
                     RuleB3S, RuleC1C, RuleC0, RuleD3D, RuleD2
                 ],
                 start_symbol=S)
     gr = ContextFree.transform_to_chomsky_normal_form(
         ContextFree.remove_unit_rules(g))
     pars = cyk(gr, [1, 1, 0])
     s = InverseContextFree.unit_rules_restore(
         InverseContextFree.transform_from_chomsky_normal_form(pars))
     self.assertIsInstance(s, S)
     self.assertIsInstance(s.to_rule, RuleSA)
     a = s.to_rule.to_symbols[0]
     self.assertIsInstance(a, A)
     self.assertIsInstance(a.to_rule, RuleAC)
     c = a.to_rule.to_symbols[0]
     self.assertIsInstance(c, C)
     self.assertIsInstance(c.to_rule, RuleC1C)
     self.assertIsInstance(c.to_rule.to_symbols[0], Terminal)
     self.assertEqual(c.to_rule.to_symbols[0].s, 1)
     c = c.to_rule.to_symbols[1]
     self.assertIsInstance(c, C)
     self.assertIsInstance(c.to_rule, RuleC1C)
     self.assertIsInstance(c.to_rule.to_symbols[0], Terminal)
     self.assertEqual(c.to_rule.to_symbols[0].s, 1)
     c = c.to_rule.to_symbols[1]
     self.assertIsInstance(c, C)
     self.assertIsInstance(c.to_rule, RuleC0)
     self.assertIsInstance(c.to_rule.to_symbols[0], Terminal)
     self.assertEqual(c.to_rule.to_symbols[0].s, 0)
예제 #6
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)
 def test_directTo2(self):
     g = Grammar(terminals=[0, 1, 2, 3],
                 nonterminals=[S, A, B, C, D],
                 rules=[
                     RuleSA, RuleSB, RuleAC, RuleA0A, RuleA1S, RuleBD,
                     RuleB2B, RuleB3S, RuleC1C, RuleC0, RuleD3D, RuleD2
                 ],
                 start_symbol=S)
     gr = ContextFree.transform_to_chomsky_normal_form(
         ContextFree.remove_unit_rules(g))
     pars = cyk(gr, [2])
     s = InverseContextFree.unit_rules_restore(
         InverseContextFree.transform_from_chomsky_normal_form(pars))
     self.assertIsInstance(s, S)
     self.assertIsInstance(s.to_rule, RuleSB)
     b = s.to_rule.to_symbols[0]
     self.assertIsInstance(b, B)
     self.assertIsInstance(b.to_rule, RuleBD)
     d = b.to_rule.to_symbols[0]
     self.assertIsInstance(d, D)
     self.assertIsInstance(d.to_rule, RuleD2)
     self.assertIsInstance(d.to_rule.to_symbols[0], Terminal)
     self.assertEqual(d.to_rule.to_symbols[0].s, 2)
 def test_simpleTest(self):
     g = Grammar(terminals=[0, 1],
                 nonterminals=[S, A, B, C],
                 rules=[Rules],
                 start_symbol=S)
     com = ContextFree.remove_unit_rules(g)
     # Removed
     class RuleStoA(Rule): rule=([S], [A])
     self.assertFalse(com.have_rule(RuleStoA))
     class RuleAtoB(Rule): rule=([A], [B])
     self.assertFalse(com.have_rule(RuleAtoB))
     class RuleBtoC(Rule): rule=([B], [C])
     self.assertFalse(com.have_rule(RuleBtoC))
     # Old rules
     class RuleNewSto0B0(Rule): rule = ([S], [0, B, 0])
     self.assertTrue(com.have_rule(RuleNewSto0B0))
     class RuleNewAto0A(Rule): rule = ([A], [0, A])
     self.assertTrue(com.have_rule(RuleNewAto0A))
     class RuleNewBto1B(Rule): rule = ([B], [1, B])
     self.assertTrue(com.have_rule(RuleNewBto1B))
     class RuleNewBtoAB(Rule): rule = ([B], [A, B])
     self.assertTrue(com.have_rule(RuleNewBtoAB))
     class RuleNewBtoEPS(Rule): rule = ([B], [EPS])
     self.assertTrue(com.have_rule(RuleNewBtoEPS))
     class RuleNewCto1A(Rule): rule = ([C], [1, A])
     self.assertTrue(com.have_rule(RuleNewCto1A))
     class RuleNewCto1(Rule): rule = ([C], [1])
     self.assertTrue(com.have_rule(RuleNewCto1))
     # New rules
     class RuleNewSto0A(Rule): rule = ([S], [0, A])
     self.assertTrue(com.have_rule(RuleNewSto0A))
     fromSto0A = com.get_rule(RuleNewSto0A)
     self.assertTrue(isclass(fromSto0A))
     self.assertTrue(issubclass(fromSto0A, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto0A.by_rules), 1)
     self.assertEqual(fromSto0A.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromSto0A.end_rule.rule, ([A], [0, A]))
     class RuleNewSto1B(Rule): rule = ([S], [1, B])
     self.assertTrue(com.have_rule(RuleNewSto1B))
     fromSto1B = com.get_rule(RuleNewSto1B)
     self.assertTrue(isclass(fromSto1B))
     self.assertTrue(issubclass(fromSto1B, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto1B.by_rules), 2)
     self.assertEqual(fromSto1B.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromSto1B.by_rules[1].rule, ([A], [B]))
     self.assertEqual(fromSto1B.end_rule.rule, ([B], [1, B]))
     class RuleNewStoAB(Rule): rule = ([S], [A, B])
     self.assertTrue(com.have_rule(RuleNewStoAB))
     fromStoAB = com.get_rule(RuleNewStoAB)
     self.assertTrue(isclass(fromStoAB))
     self.assertTrue(issubclass(fromStoAB, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromStoAB.by_rules), 2)
     self.assertEqual(fromStoAB.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromStoAB.by_rules[1].rule, ([A], [B]))
     self.assertEqual(fromStoAB.end_rule.rule, ([B], [A, B]))
     class RuleNewStoEPS(Rule): rule = ([S], [EPS])
     self.assertTrue(com.have_rule(RuleNewStoEPS))
     fromStoEPS = com.get_rule(RuleNewStoEPS)
     self.assertTrue(isclass(fromStoEPS))
     self.assertTrue(issubclass(fromStoEPS, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromStoEPS.by_rules), 2)
     self.assertEqual(fromStoEPS.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromStoEPS.by_rules[1].rule, ([A], [B]))
     self.assertEqual(fromStoEPS.end_rule.rule, ([B], [EPS]))
     class RuleNewSto1A(Rule): rule = ([S], [1, A])
     self.assertTrue(com.have_rule(RuleNewSto1A))
     fromSto1A = com.get_rule(RuleNewSto1A)
     self.assertTrue(isclass(fromSto1A))
     self.assertTrue(issubclass(fromSto1A, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto1A.by_rules), 3)
     self.assertEqual(fromSto1A.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromSto1A.by_rules[1].rule, ([A], [B]))
     self.assertEqual(fromSto1A.by_rules[2].rule, ([B], [C]))
     self.assertEqual(fromSto1A.end_rule.rule, ([C], [1, A]))
     class RuleNewSto1(Rule): rule = ([S], [1])
     self.assertTrue(com.have_rule(RuleNewSto1))
     fromSto1 = com.get_rule(RuleNewSto1)
     self.assertTrue(isclass(fromSto1))
     self.assertTrue(issubclass(fromSto1, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto1.by_rules), 3)
     self.assertEqual(fromSto1.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromSto1.by_rules[1].rule, ([A], [B]))
     self.assertEqual(fromSto1.by_rules[2].rule, ([B], [C]))
     self.assertEqual(fromSto1.end_rule.rule, ([C], [1]))
     class RuleNewAto1B(Rule): rule = ([A], [1, B])
     self.assertTrue(com.have_rule(RuleNewAto1B))
     fromAto1B = com.get_rule(RuleNewAto1B)
     self.assertTrue(isclass(fromAto1B))
     self.assertTrue(issubclass(fromAto1B, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromAto1B.by_rules), 1)
     self.assertEqual(fromAto1B.by_rules[0].rule, ([A], [B]))
     self.assertEqual(fromAto1B.end_rule.rule, ([B], [1, B]))
     class RuleNewAtoAB(Rule): rule = ([A], [A, B])
     self.assertTrue(com.have_rule(RuleNewAtoAB))
     fromAtoAB = com.get_rule(RuleNewAtoAB)
     self.assertTrue(isclass(fromAtoAB))
     self.assertTrue(issubclass(fromAtoAB, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromAtoAB.by_rules), 1)
     self.assertEqual(fromAtoAB.by_rules[0].rule, ([A], [B]))
     self.assertEqual(fromAtoAB.end_rule.rule, ([B], [A, B]))
     class RuleNewAtoEPS(Rule): rule = ([A], [EPS])
     self.assertTrue(com.have_rule(RuleNewAtoEPS))
     fromAtoEPS = com.get_rule(RuleNewAtoEPS)
     self.assertTrue(isclass(fromAtoEPS))
     self.assertTrue(issubclass(fromAtoEPS, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromAtoEPS.by_rules), 1)
     self.assertEqual(fromAtoEPS.by_rules[0].rule, ([A], [B]))
     self.assertEqual(fromAtoEPS.end_rule.rule, ([B], [EPS]))
     class RuleNewAto1A(Rule): rule = ([A], [1, A])
     self.assertTrue(com.have_rule(RuleNewAto1A))
     fromAto1A = com.get_rule(RuleNewAto1A)
     self.assertTrue(isclass(fromAto1A))
     self.assertTrue(issubclass(fromAto1A, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromAto1A.by_rules), 2)
     self.assertEqual(fromAto1A.by_rules[0].rule, ([A], [B]))
     self.assertEqual(fromAto1A.by_rules[1].rule, ([B], [C]))
     self.assertEqual(fromAto1A.end_rule.rule, ([C], [1, A]))
     class RuleNewAto1(Rule): rule = ([A], [1])
     self.assertTrue(com.have_rule(RuleNewAto1))
     fromAto1 = com.get_rule(RuleNewAto1)
     self.assertTrue(isclass(fromAto1))
     self.assertTrue(issubclass(fromAto1, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromAto1.by_rules), 2)
     self.assertEqual(fromAto1.by_rules[0].rule, ([A], [B]))
     self.assertEqual(fromAto1.by_rules[1].rule, ([B], [C]))
     self.assertEqual(fromAto1.end_rule.rule, ([C], [1]))
     class RuleNewBto1A(Rule): rule = ([B], [1, A])
     self.assertTrue(com.have_rule(RuleNewBto1A))
     fromBto1A = com.get_rule(RuleNewBto1A)
     self.assertTrue(isclass(fromBto1A))
     self.assertTrue(issubclass(fromBto1A, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromBto1A.by_rules), 1)
     self.assertEqual(fromBto1A.by_rules[0].rule, ([B], [C]))
     self.assertEqual(fromBto1A.end_rule.rule, ([C], [1, A]))
     class RuleNewBto1(Rule): rule = ([B], [1])
     self.assertTrue(com.have_rule(RuleNewBto1))
     fromBto1 = com.get_rule(RuleNewBto1)
     self.assertTrue(isclass(fromBto1))
     self.assertTrue(issubclass(fromBto1, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromBto1.by_rules), 1)
     self.assertEqual(fromBto1.by_rules[0].rule, ([B], [C]))
     self.assertEqual(fromBto1.end_rule.rule, ([C], [1]))
예제 #9
0
 def test_simpleTest(self):
     g = Grammar(terminals=[0,1,2,3],
                 nonterminals=[S, A, B, C, D],
                 rules=[Rules],
                 start_symbol=S)
     com = ContextFree.remove_unit_rules(g)
     # Removed
     class RuleStoA(Rule): rule=([S], [A])
     self.assertFalse(com.have_rule(RuleStoA))
     class RuleStoB(Rule): rule=([S], [B])
     self.assertFalse(com.have_rule(RuleStoB))
     class RuleAtoC(Rule): rule=([A], [C])
     self.assertFalse(com.have_rule(RuleAtoC))
     class RuleBtoD(Rule): rule=([B], [D])
     self.assertFalse(com.have_rule(RuleBtoD))
     # Old rules
     class RuleNewAto0A(Rule): rule = ([A], [0, A])
     self.assertTrue(com.have_rule(RuleNewAto0A))
     class RuleNewAto1S(Rule): rule = ([A], [1, S])
     self.assertTrue(com.have_rule(RuleNewAto1S))
     class RuleNewBto2B(Rule): rule = ([B], [2, B])
     self.assertTrue(com.have_rule(RuleNewBto2B))
     class RuleNewBto3S(Rule): rule = ([B], [3, S])
     self.assertTrue(com.have_rule(RuleNewBto3S))
     class RuleNewCto1C(Rule): rule = ([C], [1, C])
     self.assertTrue(com.have_rule(RuleNewCto1C))
     class RuleNewCto0(Rule): rule = ([C], [0])
     self.assertTrue(com.have_rule(RuleNewCto0))
     class RuleNewDto3D(Rule): rule = ([D], [3, D])
     self.assertTrue(com.have_rule(RuleNewDto3D))
     class RuleNewDto2(Rule): rule = ([D], [2])
     self.assertTrue(com.have_rule(RuleNewDto2))
     # New rules
     class RuleNewSto0A(Rule): rule = ([S], [0, A])
     self.assertTrue(com.have_rule(RuleNewSto0A))
     fromSto0A = com.get_rule(RuleNewSto0A)
     self.assertTrue(isclass(fromSto0A))
     self.assertTrue(issubclass(fromSto0A, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto0A.by_rules), 1)
     self.assertEqual(fromSto0A.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromSto0A.end_rule.rule, ([A], [0, A]))
     class RuleNewSto1S(Rule): rule = ([S], [1, S])
     self.assertTrue(com.have_rule(RuleNewSto1S))
     fromSto1S = com.get_rule(RuleNewSto1S)
     self.assertTrue(isclass(fromSto1S))
     self.assertTrue(issubclass(fromSto1S, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto1S.by_rules), 1)
     self.assertEqual(fromSto1S.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromSto1S.end_rule.rule, ([A], [1, S]))
     class RuleNewSto1C(Rule): rule = ([S], [1, C])
     self.assertTrue(com.have_rule(RuleNewSto1C))
     fromSto1C = com.get_rule(RuleNewSto1C)
     self.assertTrue(isclass(fromSto1C))
     self.assertTrue(issubclass(fromSto1C, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto1C.by_rules), 2)
     self.assertEqual(fromSto1C.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromSto1C.by_rules[1].rule, ([A], [C]))
     self.assertEqual(fromSto1C.end_rule.rule, ([C], [1, C]))
     class RuleNewSto0(Rule): rule = ([S], [0])
     self.assertTrue(com.have_rule(RuleNewSto0))
     fromSto0 = com.get_rule(RuleNewSto0)
     self.assertTrue(isclass(fromSto0))
     self.assertTrue(issubclass(fromSto0, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto0.by_rules), 2)
     self.assertEqual(fromSto0.by_rules[0].rule, ([S], [A]))
     self.assertEqual(fromSto0.by_rules[1].rule, ([A], [C]))
     self.assertEqual(fromSto0.end_rule.rule, ([C], [0]))
     class RuleNewSto2B(Rule): rule = ([S], [2, B])
     self.assertTrue(com.have_rule(RuleNewSto2B))
     fromSto2B = com.get_rule(RuleNewSto2B)
     self.assertTrue(isclass(fromSto2B))
     self.assertTrue(issubclass(fromSto2B, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto2B.by_rules), 1)
     self.assertEqual(fromSto2B.by_rules[0].rule, ([S], [B]))
     self.assertEqual(fromSto2B.end_rule.rule, ([B], [2, B]))
     class RuleNewSto3S(Rule): rule = ([S], [3, S])
     self.assertTrue(com.have_rule(RuleNewSto3S))
     fromSto3S = com.get_rule(RuleNewSto3S)
     self.assertTrue(isclass(fromSto3S))
     self.assertTrue(issubclass(fromSto3S, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto3S.by_rules), 1)
     self.assertEqual(fromSto3S.by_rules[0].rule, ([S], [B]))
     self.assertEqual(fromSto3S.end_rule.rule, ([B], [3, S]))
     class RuleNewSto3D(Rule): rule = ([S], [3, D])
     self.assertTrue(com.have_rule(RuleNewSto3D))
     fromSto3D = com.get_rule(RuleNewSto3D)
     self.assertTrue(isclass(fromSto3D))
     self.assertTrue(issubclass(fromSto3D, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto3D.by_rules), 2)
     self.assertEqual(fromSto3D.by_rules[0].rule, ([S], [B]))
     self.assertEqual(fromSto3D.by_rules[1].rule, ([B], [D]))
     self.assertEqual(fromSto3D.end_rule.rule, ([D], [3, D]))
     class RuleNewSto2(Rule): rule = ([S], [2])
     self.assertTrue(com.have_rule(RuleNewSto2))
     fromSto2 = com.get_rule(RuleNewSto2)
     self.assertTrue(isclass(fromSto2))
     self.assertTrue(issubclass(fromSto2, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromSto2.by_rules), 2)
     self.assertEqual(fromSto2.by_rules[0].rule, ([S], [B]))
     self.assertEqual(fromSto2.by_rules[1].rule, ([B], [D]))
     self.assertEqual(fromSto2.end_rule.rule, ([D], [2]))
     class RuleNewAto1C(Rule): rule = ([A], [1, C])
     self.assertTrue(com.have_rule(RuleNewAto1C))
     fromAto1C = com.get_rule(RuleNewAto1C)
     self.assertTrue(isclass(fromAto1C))
     self.assertTrue(issubclass(fromAto1C, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromAto1C.by_rules), 1)
     self.assertEqual(fromAto1C.by_rules[0].rule, ([A], [C]))
     self.assertEqual(fromAto1C.end_rule.rule, ([C], [1, C]))
     class RuleNewAto0(Rule): rule = ([A], [0])
     self.assertTrue(com.have_rule(RuleNewAto0))
     fromAto0 = com.get_rule(RuleNewAto0)
     self.assertTrue(isclass(fromAto0))
     self.assertTrue(issubclass(fromAto0, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromAto0.by_rules), 1)
     self.assertEqual(fromAto0.by_rules[0].rule, ([A], [C]))
     self.assertEqual(fromAto0.end_rule.rule, ([C], [0]))
     class RuleNewBto3D(Rule): rule = ([B], [3, D])
     self.assertTrue(com.have_rule(RuleNewBto3D))
     fromBto3D = com.get_rule(RuleNewBto3D)
     self.assertTrue(isclass(fromBto3D))
     self.assertTrue(issubclass(fromBto3D, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromBto3D.by_rules), 1)
     self.assertEqual(fromBto3D.by_rules[0].rule, ([B], [D]))
     self.assertEqual(fromBto3D.end_rule.rule, ([D], [3, D]))
     class RuleNewBto2(Rule): rule = ([B], [2])
     self.assertTrue(com.have_rule(RuleNewBto2))
     fromBto2 = com.get_rule(RuleNewBto2)
     self.assertTrue(isclass(fromBto2))
     self.assertTrue(issubclass(fromBto2, ContextFree.ReducedUnitRule))
     self.assertEqual(len(fromBto2.by_rules), 1)
     self.assertEqual(fromBto2.by_rules[0].rule, ([B], [D]))
     self.assertEqual(fromBto2.end_rule.rule, ([D], [2]))