def test_shift_reduce_hard_023(self): entry = ('C C A A C D E B E D E B C A C C A C A C E C A C B').split() exepted_output = [ 'C', 'C', 'A', 'C', 'C', 'A', 'C', 'D', 'A', 'C', 'A', 'C', 'C', 'A', 'C', 'A', 'C', 'D', 'C', 'A', 'C', 'A' ] self.assertListEqual(sr.shift_reduce(entry, GRAMMAR), exepted_output)
def test_shift_reduce_hard_020(self): entry = ('B D B E B B C C C E B D E E A A B A' + ' A B D E C E E B D C D D B B E D D C').split() exepted_output = [ 'A', 'D', 'A', 'D', 'A', 'D', 'A', 'C', 'D', 'A', 'C', 'C', 'A', 'D', 'C', 'C', 'A', 'C', 'D', 'C' ] self.assertListEqual(sr.shift_reduce(entry, GRAMMAR), exepted_output)
def test_shift_reduce_018(self): entry = 'B C E C'.split() exepted_output = ['A', 'C', 'D', 'C'] self.assertListEqual(sr.shift_reduce(entry, GRAMMAR), exepted_output)
def test_shift_reduce_001(self): entry = ''.split() exepted_output = [] self.assertListEqual(sr.shift_reduce(entry, GRAMMAR), exepted_output)
def test_shift_reduce_016(self): entry = 'C C E E C C E E C C'.split() exepted_output = ['A'] self.assertListEqual(sr.shift_reduce(entry, GRAMMAR), exepted_output)
def test_shift_reduce_hard_021(self): entry = ( 'SPACES D SPACES E SPACES SPACES SPACES E SPACES D SPACES A D' + ' SPACES E SPACES SPACES SPACES').split() exepted_output = ['C', 'C', 'A', 'C'] self.assertListEqual(sr.shift_reduce(entry, GRAMMAR), exepted_output)
def test_shift_reduce_hard_019(self): entry = 'E E E D A A E E A B A A'.split() exepted_output = ['FORBIDDEN', 'C', 'D', 'A', 'C', 'A'] self.assertListEqual(sr.shift_reduce(entry, GRAMMAR), exepted_output)
#!/usr/bin/env python3 import sys from pprint import pprint import utils.shiftreduce as sr from utils.grammar import Grammar GRAMMAR = Grammar("grammar/grammar_test.txt") if __name__ == '__main__': if len(sys.argv) == 1: ENTRY = 'E E' else: ENTRY = " ".join(sys.argv[1:]).upper() pprint(GRAMMAR.grammar) print(sr.shift_reduce(ENTRY.split(), GRAMMAR))