コード例 #1
0
ファイル: lesson12.py プロジェクト: Bookaa/LiuD_Lesson_12
    def test7(self):
        sample_Python = open('GDL_common.py').read()
        import Ast_Py
        the = Ast_Py.PY_Parser(sample_Python)
        mod = the.handle_main()

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod.walkabout(the2)
        txt = outp.txt
        self.assertEqual(txt.splitlines()[-1].strip(), "print '  ' * len ( self . lst ) + s + '<-'")
コード例 #2
0
ファイル: lesson12.py プロジェクト: Bookaa/LiuD_Lesson_12
    def test8(self):
        sample_Python = open('Ast_LiuD.py').read()
        import Ast_Py
        the = Ast_Py.PY_Parser(sample_Python)
        mod = the.handle_main()

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod.walkabout(the2)
        txt = outp.txt
        self.assertEqual(txt.splitlines()[-1].strip(), "self . outp . puts ( '?' )")
コード例 #3
0
ファイル: lesson12.py プロジェクト: Bookaa/LiuD_Lesson_12
    def test6(self):
        sample_Python = open('LiuD_Main_Gen.py').read()
        import Ast_Py
        the = Ast_Py.PY_Parser(sample_Python)
        mod = the.handle_main()

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod.walkabout(the2)
        txt = outp.txt
        self.assertEqual(txt.splitlines()[-1].strip(), 'return s')
コード例 #4
0
ファイル: lesson12.py プロジェクト: Bookaa/LiuD_Lesson_12
    def test9(self):
        sample_Python = open('Ast_Py.py').read()
        import Ast_Py
        the = Ast_Py.PY_Parser(sample_Python)
        mod = the.handle_main()

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod.walkabout(the2)
        txt = outp.txt
        #print txt
        self.assertEqual(txt.splitlines()[-1].strip(), "return PY_litname ( n )")
コード例 #5
0
ファイル: lesson12.py プロジェクト: Bookaa/LiuD_Lesson_12
    def test4(self):
        sample_Python = open('lesson12.py').read()
        import Ast_Py
        the = Ast_Py.PY_Parser(sample_Python)
        mod = the.handle_main()
        #print mod

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod.walkabout(the2)
        txt = outp.txt
        print txt
        lines = txt.splitlines()
        self.assertEqual(lines[-1].strip(), "print 'good'")
コード例 #6
0
ファイル: lesson10.py プロジェクト: Bookaa/LiuD_Lesson_10
    def test5(self):
        s = Gen_All(syntax_Py)
        #open('Ast_Py2.py', 'w').write(s)
        s2 = open('Ast_Py.py').read()
        self.assertEqual(s, s2)

        import Ast_Py
        the = Ast_Py.PY_Parser(sample_Python)
        mod = the.handle_main()

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod.walkabout(the2)
        txt = outp.txt
        #print '<%s>' % txt
        txt2 = '''
def main ( ) :
     c = 2800
     f = [ 10000 / 5 ] * 2801
     f [ c ] = 0
     e = 0
     while c != 0 :
         d = 0
         b = c
         while True :
             d += f [ b ] * 10000
             f [ b ] = d % ( b * 2 - 1 )
             d /= ( b * 2 - 1 )
             b -= 1
             if b == 0 :
                 break
             d *= b
         c -= 14
         print '%04d' % ( e + d / 10000 ) ,
         e = d % 10000
     print
main ( )'''
        self.assertEqual(txt, txt2)
コード例 #7
0
    def test5(self):
        s = Gen_All(syntax_Py, True)
        #open('Ast_Py2.py', 'w').write(s)
        s2 = open('Ast_Py.py').read()
        self.assertEqual(s, s2)
        #return

        import Ast_Py
        the = Ast_Py.PY_Parser(sample_Python)
        the.deep()
        mod = the.handle_main()
        last = the.SerialOut()

        stand = [[['main', [], [[[['c', 1], [[[['2800', 0], 4], 2]]], 5], [[['f', 1], [[[[[[[[[['10000', 0], 4], 2]], '/', [[['5', 0], 4]]]], 0], 1]], '*', [[['2801', 0], 4]]]], 5], [[[['f', [[[['c', 1], 4], 2]]], 0], [[[['0', 0], 4], 2]]], 5], [[['e', 1], [[[['0', 0], 4], 2]]], 5], [[[[[[['c', 1], 4], 2]], '!=', [[['0', 0], 4]]], [[[['d', 1], [[[['0', 0], 4], 2]]], 5], [[['b', 1], [[[['c', 1], 4], 2]]], 5], [[[[[0, 3], 2]], [[[['d', 1], 0, [[[[['f', [[[['b', 1], 4], 2]]], 2], 2]], '*', [[['10000', 0], 4]]]], 6], [[[['f', [[[['b', 1], 4], 2]]], 0], [[[[['d', 1], 4], 2]], '%', [[[[[[[['b', 1], 4], 2]], '*', [[['2', 0], 4]]], '-', [[['1', 0], 4]]], 0]]]], 5], [[['d', 1], 2, [[[[[[[[['b', 1], 4], 2]], '*', [[['2', 0], 4]]], '-', [[['1', 0], 4]]], 0], 2]]], 6], [[['b', 1], 1, [[[['1', 0], 4], 2]]], 6], [[[[[[['b', 1], 4], 2]], '==', [[['0', 0], 4]]], [[[[[['break', 1], 4], 2]], 7]], []], 0], [[['d', 1], 3, [[[['b', 1], 4], 2]]], 6]], []], 1], [[['c', 1], 1, [[[['14', 0], 4], 2]]], 6], [[[[[[[["'%04d'", 2], 4], 2]], '%', [[[[[[['e', 1], 4], 2]], '+', [[[['d', 1], 4]], '/', [[['10000', 0], 4]]]], 0]]]], 1], 3], [[['e', 1], [[[[['d', 1], 4], 2]], '%', [[['10000', 0], 4]]]], 5]], []], 1], [[[], 0], 3]]], 4], [[[[['main', []], 1], 2]], 7]]
        if last != stand:
            print last
        self.assertEqual(last, stand)

        the2 = Ast_Py.PY_SerialIn()
        mod2 = the2.handle_main(stand)

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod.walkabout(the2)
        txt = outp.txt
        #print '<%s>' % txt
        print txt
        txt2 = '''
def main ( ) :
     c = 2800
     f = [ 10000 / 5 ] * 2801
     f [ c ] = 0
     e = 0
     while c != 0 :
         d = 0
         b = c
         while True :
             d += f [ b ] * 10000
             f [ b ] = d % ( b * 2 - 1 )
             d /= ( b * 2 - 1 )
             b -= 1
             if b == 0 :
                 break
             d *= b
         c -= 14
         print '%04d' % ( e + d / 10000 ) ,
         e = d % 10000
     print
main ( )'''
        self.assertEqual(txt, txt2)

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod2.walkabout(the2)
        txt = outp.txt
        self.assertEqual(txt, txt2)
コード例 #8
0
ファイル: lesson12.py プロジェクト: Bookaa/LiuD_Lesson_12
    def test5(self):
        s = Gen_All(syntax_Py, True)
        #open('Ast_Py2.py', 'w').write(s)
        s2 = open('Ast_Py.py').read()
        self.assertEqual(s, s2)
        #return

        import Ast_Py
        the = Ast_Py.PY_Parser(sample_Python)
        the.deep()
        mod = the.handle_main()
        last = the.SerialOut()

        stand = [[[[['LiuD_Main_Gen'], [[[['Gen_All'], []]], 1]], 0], 6], [['cls1', [], [[[[[['v3', 0], 2], [[[[[[[[[[[[[[[[[['a1', 1], 1], 7], 0], 'a2'], 3], [[[[[[[[[['3', 0], 1], 7], 0], 1]]]]], 2]], 1], 'a3'], 3], [[[], [[[[[[[[['a4', 1], 1], 7], 0], 1]]]]]], [[], [[[[[[[[['a5', 1], 1], 7], 0], 1]]]]]]]], 2], 1]]]]], 1]], 2], 9]]], 7], [['cls2', [[['cls1'], ['object']]], [[[[[['v', 0], 2], [[[[[[[[[[[['3', 0], 1], 7], 0], 1]], '+', [[[[['2', 0], 1], 7], 0]]]]], [[[[[0, 6], 0], 1]]], [[[[0, [[[['66', 0], 1], 7], 0]], 0]]]]], 1]], 2], 9]]], 7], [[[[['s', 0], 2], [[[[[[[[[['"""test\ntest\n    multiline\n        string"""', 0], 0], 7], 0], 1]]]]], 1]], 2], 9], [['main', [], [[[[[['c', 0], 2], [[[[[[[[[['2800', 0], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[['f', 0], 2], [[[[[[[[[[[[[[[[[[[[['10000', 0], 1], 7], 0], 1]], '/', [[[[['5', 0], 1], 7], 0]]]]]]], 0], 0], 0], 1]], '*', [[[[['2801', 0], 1], 7], 0]]]]]], 1]], 2], 9], [[[[[[['f', 0], [[[[[[[[[['c', 1], 1], 7], 0], 1]]]]], 2]], 1], 2], [[[[[[[[[['0', 0], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[['e', 0], 2], [[[[[[[[[['0', 0], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[[[[[[[[['c', 1], 1], 7], 0], 1]]], '!=', [[[[[[['0', 0], 1], 7], 0], 1]]]]]], [[[[[['d', 0], 2], [[[[[[[[[['0', 0], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[['b', 0], 2], [[[[[[[[[['c', 1], 1], 7], 0], 1]]]]], 1]], 2], 9], [[[[[[[[[0, 6], 0], 1]]]]], [[[[[['d', 0], 2], 0, [[[[[[[[[[[['f', 1], 1], 7], 0], [[[[[[[[[['b', 1], 1], 7], 0], 1]]]]], 2]], 1], 1]], '*', [[[[['10000', 0], 1], 7], 0]]]]]]], 3], 9], [[[[[[['f', 0], [[[[[[[[[['b', 1], 1], 7], 0], 1]]]]], 2]], 1], 2], [[[[[[[[[[['d', 1], 1], 7], 0], 1]]], '%', [[[[[[[[[[[[[[[['b', 1], 1], 7], 0], 1]], '*', [[[[['2', 0], 1], 7], 0]]], '-', [[[[['1', 0], 1], 7], 0]]]]]], 4], 0], 1]]]]]], 1]], 2], 9], [[[[['d', 0], 2], 2, [[[[[[[[[[[[[[[[[['b', 1], 1], 7], 0], 1]], '*', [[[[['2', 0], 1], 7], 0]]], '-', [[[[['1', 0], 1], 7], 0]]]]]], 4], 0], 1]]]]]], 3], 9], [[[[['b', 0], 2], 1, [[[[[[[[['1', 0], 1], 7], 0], 1]]]]]], 3], 9], [[[[[[[[[[[['b', 1], 1], 7], 0], 1]]], '==', [[[[[[['0', 0], 1], 7], 0], 1]]]]]], [[[1, 0], 9]], [], []], 0], [[[[['d', 0], 2], 3, [[[[[[[[['b', 1], 1], 7], 0], 1]]]]]], 3], 9]], []], 1], [[[[['c', 0], 2], 1, [[[[[[[[['14', 0], 1], 7], 0], 1]]]]]], 3], 9], [[[[[[[[[[[[["'%04d'", 6], 0], 7], 0], 1]]], '%', [[[[[[[[[[[[[[['e', 1], 1], 7], 0], 1]], '+', [[[[[['d', 1], 1], 7], 0]], '/', [[[[['10000', 0], 1], 7], 0]]]]]]], 4], 0], 1]]]]]]], 1], 4], [[[[['e', 0], 2], [[[[[[[[[[['d', 1], 1], 7], 0], 1]]], '%', [[[[[[['10000', 0], 1], 7], 0], 1]]]]]], 1]], 2], 9]], []], 1], [[[], 0], 4]]], 5], [[[[[[[[[['main', []], 5], 0], 1]]]]], 4], 9]]
        if last != stand:
            print last
        self.assertEqual(last, stand)

        the2 = Ast_Py.PY_SerialIn()
        mod2 = the2.handle_main(stand)

        outp = Ast_Py.OutP()
        the2 = Ast_Py.PY_output(outp)
        mod.walkabout(the2)
        txt = outp.txt
        #print '<%s>' % txt
        txt2 = '''from LiuD_Main_Gen import Gen_All
class cls1 :
     v3 = a1 . a2 [ 3 ] . a3 ( a4 , a5 )
class cls2 ( cls1 , object ) :
     v = 3 + 2 if True else - 66
s = """test
test
    multiline
        string"""
def main ( ) :
     c = 2800
     f = [ 10000 / 5 ] * 2801
     f [ c ] = 0
     e = 0
     while c != 0 :
         d = 0
         b = c
         while True :
             d += f [ b ] * 10000
             f [ b ] = d % ( b * 2 - 1 )
             d /= ( b * 2 - 1 )
             b -= 1
             if b == 0 :
                 break
             d *= b
         c -= 14
         print '%04d' % ( e + d / 10000 ) ,
         e = d % 10000
     print
main ( )'''
        self.assertEqual(txt, txt2)
        if True:
            outp = Ast_Py.OutP()
            the2 = Ast_Py.PY_output(outp)
            mod2.walkabout(the2)
            txt = outp.txt
            print '<%s>' % txt
            self.assertEqual(txt, txt2)