Пример #1
0
 def test_Less_Lookahead_ClosedTF(self):
     i0c = self.is_C_0(closed=True, la=Grammar.LookaheadSet({self.c}))
     i0d = self.is_C_0(closed=False, la=Grammar.LookaheadSet({self.d}))
     # We only compare on content, never by the index. So closure
     # doesn't matter here.
     self.assertLess(i0c, i0d)
     self.assertGreater(i0d, i0c)
Пример #2
0
 def test_Equal_Lookahead_ClosedTF(self):
     i0c = self.is_C_0(closed=True, la=Grammar.LookaheadSet({self.c}))
     i0d = self.is_C_0(closed=False, la=Grammar.LookaheadSet({self.d}))
     self.assertEqual(i0c, i0c)
     self.assertEqual(i0d, i0d)
     self.assertFalse(i0c == i0d)
     self.assertFalse(i0d == i0c)
Пример #3
0
 def test_Equal_Lookahead(self):
     i0c = self.is_C_0(la=Grammar.LookaheadSet({self.c}))
     i0d = self.is_C_0(la=Grammar.LookaheadSet({self.d}))
     self.assertEqual(i0c, i0c)
     self.assertEqual(i0d, i0d)
     self.assertFalse(i0c == i0d)
     self.assertFalse(i0d == i0c)
Пример #4
0
 def setUp(self):
     self.g = Grammar.Grammar.Load(DRAGON_BOOK_EXAMPLE_4_42,
                                   'translation_unit')
     self.L = self.g.rules[Grammar.LANGUAGE]
     self.C = self.g.rules["C"]
     self.c = self.g.rules["c"]
     self.d = self.g.rules["d"]
     self.l_empty = Grammar.LookaheadSet({})
     self.l_end = Grammar.LookaheadSet({self.g.MakeEndOfText()})
     self.l_end_and = Grammar.LookaheadSet(
         {self.g.MakeFixed('end'),
          self.g.MakeEndOfText()})
Пример #5
0
 def setUp(self):
     self.g = Grammar.Grammar.Load(DRAGON_BOOK_EXAMPLE_4_42,
                                   'translation_unit')
     self.C = self.g.rules["C"]
     self.c = self.g.rules["c"]
     self.d = self.g.rules["d"]
     self.el = Grammar.LookaheadSet({})
Пример #6
0
 def test_merge_overlap(self):
     x = Grammar.LookaheadSet({1, 2, 4})
     b = x.merge(Grammar.LookaheadSet({1, 2, 3}))
     self.assertEqual(str(x), "{1 2 3 4}")
     self.assertTrue(b)
Пример #7
0
 def test_merge_disjoint(self):
     x = Grammar.LookaheadSet({-1, 9, 4})
     b = x.merge(Grammar.LookaheadSet({1, 2, 3}))
     self.assertEqual(str(x), "{-1 1 2 3 4 9}")
     self.assertTrue(b)
Пример #8
0
 def test_merge_same(self):
     x = Grammar.LookaheadSet({1, 2, 3})
     b = x.merge(Grammar.LookaheadSet({1, 2, 3}))
     self.assertEqual(str(x), "{1 2 3}")
     self.assertFalse(b)
Пример #9
0
 def test_str_several_is_ordered(self):
     x = Grammar.LookaheadSet({9, 2, 1})
     self.assertEqual(str(x), "{1 2 9}")
Пример #10
0
 def test_str_empty(self):
     x = Grammar.LookaheadSet({})
     self.assertEqual(str(x), "{}")
Пример #11
0
 def test_init_several(self):
     x = Grammar.LookaheadSet({1, 2, 9})
     self.assertTrue(x == set({9, 2, 1}))
Пример #12
0
 def test_init_single(self):
     x = Grammar.LookaheadSet({1})
     self.assertTrue(x == set({1}))
Пример #13
0
 def test_init_empty(self):
     x = Grammar.LookaheadSet()
     self.assertTrue(x == set())
Пример #14
0
 def test_Less_Lookahead_ClosedFT(self):
     i0c = self.is_C_0(closed=False, la=Grammar.LookaheadSet({self.c}))
     i0d = self.is_C_0(closed=True, la=Grammar.LookaheadSet({self.d}))
     self.assertLess(i0c, i0d)
     self.assertGreater(i0d, i0c)
Пример #15
0
 def test_Less_Lookahead(self):
     i0c = self.is_C_0(la=Grammar.LookaheadSet({self.c}))
     i0d = self.is_C_0(la=Grammar.LookaheadSet({self.d}))
     self.assertLess(i0c, i0d)
     self.assertGreater(i0d, i0c)
Пример #16
0
 def is_C_1(self, closed=True, la=Grammar.LookaheadSet({})):
     result = Grammar.ItemSet(self.g, {self.iC(1): la})
     result = result.close(self.g) if closed else result
     return result