Пример #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)
Пример #2
0
 def test_simpleTestShouldChange(self):
     g = Grammar(terminals=[0, 1],
                 nonterminals=[S, A, B],
                 rules=[RuleSto0, RuleStoA, RuleAtoAB, RuleBto1],
                 start_symbol=S)
     ContextFree.remove_useless_symbols(g, inplace=True)
     self.assertIn(0, g.terminals)
     self.assertNotIn(1, g.terminals)
     self.assertIn(S, g.nonterminals)
     self.assertNotIn(A, g.nonterminals)
     self.assertNotIn(B, g.nonterminals)
Пример #3
0
 def test_simpleTest(self):
     g = Grammar(terminals=[0, 1],
                 nonterminals=[S, A, B],
                 rules=[RuleSto0, RuleStoA, RuleAtoAB, RuleBto1],
                 start_symbol=S)
     com = ContextFree.remove_useless_symbols(g)
     self.assertIn(0, com.terminals)
     self.assertNotIn(1, com.terminals)
     self.assertIn(S, com.nonterminals)
     self.assertNotIn(A, com.nonterminals)
     self.assertNotIn(B, com.nonterminals)