예제 #1
0
    def test_canonical_collection_lr_value(self):
        collection = canonical_collection(self.lrvalue, LR0(self.StartExtendedSymbol, 0, 0))
        self.assertTrue(len(collection) == 10)

        states = frozenset(
            [
                frozenset(
                    [
                        LR0(self.StartExtendedSymbol, 0, 0),
                        LR0("S", 0, 0),
                        LR0("S", 1, 0),
                        LR0("L", 0, 0),
                        LR0("L", 1, 0),
                        LR0("R", 0, 0),
                    ]
                ),
                frozenset([LR0(self.StartExtendedSymbol, 0, 1)]),
                frozenset([LR0("S", 0, 1), LR0("R", 0, 1)]),
                frozenset([LR0("S", 1, 1)]),
                frozenset([LR0("L", 0, 1), LR0("L", 0, 0), LR0("L", 1, 0), LR0("R", 0, 0)]),
                frozenset([LR0("L", 1, 1)]),
                frozenset([LR0("S", 0, 2), LR0("L", 0, 0), LR0("L", 1, 0), LR0("R", 0, 0)]),
                frozenset([LR0("L", 0, 2)]),
                frozenset([LR0("R", 0, 1)]),
                frozenset([LR0("S", 0, 3)]),
            ]
        )

        self.assertTrue(states == collection)
예제 #2
0
    def test_canonical_collection_arith(self):
        collection = canonical_collection(
            self.arith, LR1(self.StartExtendedSymbol, 0, 0, self.arith.EOF))
        self.assertTrue(len(collection) == 10)

        EOF = self.arith.EOF

        states = frozenset([
            frozenset([
                LR1(self.StartExtendedSymbol, 0, 0, EOF),
                LR1('S', 0, 0, EOF),
                LR1('C', 0, 0, 'c'),
                LR1('C', 0, 0, 'd'),
                LR1('C', 1, 0, 'c'),
                LR1('C', 1, 0, 'd'),
            ]),
            frozenset([
                LR1(self.StartExtendedSymbol, 0, 1, EOF),
            ]),
            frozenset([
                LR1('S', 0, 1, EOF),
                LR1('C', 0, 0, EOF),
                LR1('C', 1, 0, EOF)
            ]),
            frozenset([
                LR1('C', 0, 1, 'c'),
                LR1('C', 0, 1, 'd'),
                LR1('C', 0, 0, 'c'),
                LR1('C', 0, 0, 'd'),
                LR1('C', 1, 0, 'c'),
                LR1('C', 1, 0, 'd'),
            ]),
            frozenset([
                LR1('C', 1, 1, 'c'),
                LR1('C', 1, 1, 'd'),
            ]),
            frozenset([
                LR1('C', 0, 1, EOF),
                LR1('C', 0, 0, EOF),
                LR1('C', 1, 0, EOF),
            ]),
            frozenset([
                LR1('S', 0, 2, EOF),
            ]),
            frozenset([
                LR1('C', 1, 1, EOF),
            ]),
            frozenset([
                LR1('C', 0, 2, 'c'),
                LR1('C', 0, 2, 'd'),
            ]),
            frozenset([
                LR1('C', 0, 2, EOF),
            ]),
        ])

        assert len(states) == 10
        self.assertTrue(states == collection)
예제 #3
0
   def test_canonical_collection_arith(self):
      collection = canonical_collection(self.arith, LR1(self.StartExtendedSymbol, 0, 0, self.arith.EOF))
      self.assertTrue(len(collection) == 10)

      EOF = self.arith.EOF

      states = frozenset([
      frozenset([
         LR1(self.StartExtendedSymbol, 0, 0, EOF),
         LR1('S', 0, 0, EOF),
         LR1('C', 0, 0, 'c'), LR1('C', 0, 0, 'd'),
         LR1('C', 1, 0, 'c'), LR1('C', 1, 0, 'd'), ]),
      
      frozenset([
         LR1(self.StartExtendedSymbol, 0, 1, EOF),
         ]),

      frozenset([
         LR1('S', 0, 1, EOF),
         LR1('C', 0, 0, EOF),
         LR1('C', 1, 0, EOF)]),

      frozenset([
         LR1('C', 0, 1, 'c'), LR1('C', 0, 1, 'd'),
         LR1('C', 0, 0, 'c'), LR1('C', 0, 0, 'd'),
         LR1('C', 1, 0, 'c'), LR1('C', 1, 0, 'd'), ]),

      frozenset([
         LR1('C', 1, 1, 'c'), LR1('C', 1, 1, 'd'),]),
         
      frozenset([
         LR1('C', 0, 1, EOF),
         LR1('C', 0, 0, EOF), 
         LR1('C', 1, 0, EOF),  ]),

      frozenset([
         LR1('S', 0, 2, EOF),
         ]),

      frozenset([
         LR1('C', 1, 1, EOF), 
         ]),
      
      frozenset([
         LR1('C', 0, 2, 'c'), LR1('C', 0, 2, 'd'),]),

      frozenset([
         LR1('C', 0, 2, EOF), ]),

      ])

      assert len(states) == 10
      self.assertTrue(states == collection)
예제 #4
0
    def test_canonical_collection_lr_value(self):
        collection = canonical_collection(self.lrvalue,
                                          LR0(self.StartExtendedSymbol, 0, 0))
        self.assertTrue(len(collection) == 10)

        states = frozenset([
            frozenset([
                LR0(self.StartExtendedSymbol, 0, 0),
                LR0('S', 0, 0),
                LR0('S', 1, 0),
                LR0('L', 0, 0),
                LR0('L', 1, 0),
                LR0('R', 0, 0),
            ]),
            frozenset([
                LR0(self.StartExtendedSymbol, 0, 1),
            ]),
            frozenset([
                LR0('S', 0, 1),
                LR0('R', 0, 1),
            ]),
            frozenset([
                LR0('S', 1, 1),
            ]),
            frozenset([
                LR0('L', 0, 1),
                LR0('L', 0, 0),
                LR0('L', 1, 0),
                LR0('R', 0, 0),
            ]),
            frozenset([
                LR0('L', 1, 1),
            ]),
            frozenset([
                LR0('S', 0, 2),
                LR0('L', 0, 0),
                LR0('L', 1, 0),
                LR0('R', 0, 0),
            ]),
            frozenset([
                LR0('L', 0, 2),
            ]),
            frozenset([
                LR0('R', 0, 1),
            ]),
            frozenset([
                LR0('S', 0, 3),
            ]),
        ])

        self.assertTrue(states == collection)
예제 #5
0
    def test_cannonical_collection(self):
        collection = canonical_collection(self.arith,
                                          LR0(self.arith.START, 0, 0))

        states = frozenset([
            frozenset([
                LR0(self.arith.START, 0, 0),
                LR0('S', 0, 0),
                LR0('E', 0, 0),
                LR0('E', 1, 0),
            ]),
            frozenset([
                LR0(self.arith.START, 0, 1),
            ]),
            frozenset([
                LR0('E', 0, 1),
            ]),
            frozenset([
                LR0('S', 0, 1),
            ]),
            frozenset([
                LR0('E', 1, 1),
                LR0(self.arith.ACTION_INSIDE % (1, 'push'), 0, 0),
            ]),
            frozenset([
                LR0('E', 1, 2),
            ]),
            frozenset([
                LR0('E', 1, 4),
            ]),
            frozenset([
                LR0('E', 1, 6),
            ]),
            frozenset([
                LR0('E', 1, 5),
                LR0(self.arith.ACTION_INSIDE % (2, 'pop'), 0, 0),
            ]),
            frozenset([
                LR0('E', 1, 3),
                LR0('E', 0, 0),
                LR0('E', 1, 0),
            ]),
        ])

        self.assertTrue(states == collection)
예제 #6
0
    def test_canonical_collection_arith(self):
        collection = canonical_collection(self.arith, LR0(self.StartExtendedSymbol, 0, 0))
        self.assertTrue(len(collection) == 12)

        states = frozenset(
            [
                frozenset(
                    [
                        LR0(self.StartExtendedSymbol, 0, 0),
                        LR0("E", 0, 0),
                        LR0("E", 1, 0),
                        LR0("T", 0, 0),
                        LR0("T", 1, 0),
                        LR0("F", 0, 0),
                        LR0("F", 1, 0),
                    ]
                ),
                frozenset([LR0(self.StartExtendedSymbol, 0, 1), LR0("E", 0, 1)]),
                frozenset([LR0("E", 1, 1), LR0("T", 0, 1)]),
                frozenset([LR0("F", 1, 1)]),
                frozenset(
                    [
                        LR0("F", 0, 1),
                        LR0("E", 0, 0),
                        LR0("E", 1, 0),
                        LR0("T", 0, 0),
                        LR0("T", 1, 0),
                        LR0("F", 0, 0),
                        LR0("F", 1, 0),
                    ]
                ),
                frozenset([LR0("T", 1, 1)]),
                frozenset([LR0("E", 0, 2), LR0("T", 0, 0), LR0("T", 1, 0), LR0("F", 0, 0), LR0("F", 1, 0)]),
                frozenset([LR0("T", 0, 2), LR0("F", 0, 0), LR0("F", 1, 0)]),
                frozenset([LR0("E", 0, 1), LR0("F", 0, 2)]),
                frozenset([LR0("E", 0, 3), LR0("T", 0, 1)]),
                frozenset([LR0("T", 0, 3)]),
                frozenset([LR0("F", 0, 3)]),
            ]
        )

        self.assertTrue(states == collection)
예제 #7
0
   def test_cannonical_collection(self):
      collection = canonical_collection(self.arith, LR0(self.arith.START, 0, 0))
      
      states = frozenset([
      frozenset([
         LR0(self.arith.START, 0, 0),
         LR0('S', 0, 0), 
         LR0('E', 0, 0), LR0('E', 1, 0),]),
      
      frozenset([
         LR0(self.arith.START, 0, 1),]),
      
      frozenset([
         LR0('E', 0, 1),]),

      frozenset([
         LR0('S', 0, 1),]),
      
      frozenset([
         LR0('E', 1, 1), 
         LR0(self.arith.ACTION_INSIDE % (1, 'push'), 0, 0),]),
      
      frozenset([
         LR0('E', 1, 2),]),
      
      frozenset([
         LR0('E', 1, 4),]),
      
      frozenset([
         LR0('E', 1, 6),]),
      
      frozenset([
         LR0('E', 1, 5), 
         LR0(self.arith.ACTION_INSIDE % (2, 'pop'), 0, 0),]),

      frozenset([
         LR0('E', 1, 3), 
         LR0('E', 0, 0), LR0('E', 1, 0),]),
      ])
      
      self.assertTrue(states == collection)
예제 #8
0
    def test_canonical_collection_arith(self):
        collection = canonical_collection(self.arith,
                                          LR0(self.StartExtendedSymbol, 0, 0))
        self.assertTrue(len(collection) == 12)

        states = frozenset([
            frozenset([
                LR0(self.StartExtendedSymbol, 0, 0),
                LR0('E', 0, 0),
                LR0('E', 1, 0),
                LR0('T', 0, 0),
                LR0('T', 1, 0),
                LR0('F', 0, 0),
                LR0('F', 1, 0),
            ]),
            frozenset([
                LR0(self.StartExtendedSymbol, 0, 1),
                LR0('E', 0, 1),
            ]),
            frozenset([
                LR0('E', 1, 1),
                LR0('T', 0, 1),
            ]),
            frozenset([
                LR0('F', 1, 1),
            ]),
            frozenset([
                LR0('F', 0, 1),
                LR0('E', 0, 0),
                LR0('E', 1, 0),
                LR0('T', 0, 0),
                LR0('T', 1, 0),
                LR0('F', 0, 0),
                LR0('F', 1, 0),
            ]),
            frozenset([
                LR0('T', 1, 1),
            ]),
            frozenset([
                LR0('E', 0, 2),
                LR0('T', 0, 0),
                LR0('T', 1, 0),
                LR0('F', 0, 0),
                LR0('F', 1, 0),
            ]),
            frozenset([
                LR0('T', 0, 2),
                LR0('F', 0, 0),
                LR0('F', 1, 0),
            ]),
            frozenset([
                LR0('E', 0, 1),
                LR0('F', 0, 2),
            ]),
            frozenset([
                LR0('E', 0, 3),
                LR0('T', 0, 1),
            ]),
            frozenset([
                LR0('T', 0, 3),
            ]),
            frozenset([
                LR0('F', 0, 3),
            ]),
        ])

        self.assertTrue(states == collection)