This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Anthony Sottile, benjamin.peterson, brett.cannon, rhettinger, serhiy.storchaka, xtreak, yselivanov
Date 2019-09-01.20:24:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1567369448.27.0.800784649305.issue37995@roundup.psfhosted.org>
In-reply-to
Content
FWIW, I wrote a generic AST pretty printer for a personal compiler project (see attached file).  Perhaps it can be adapted to the Python AST.

## Example input ###############################

Program(procs=[Procedure(name='FACTORIAL', params=['N'], is_test=False, body=Block(blocknum=0, stmts=[Assign(name=Output(is_bool=False), value=Number(x=1)), Assign(name=Cell(i=0), value=Number(x=1)), Loop(times=Id(name='N'), fixed=False, body=Block(blocknum=1, stmts=[Assign(name=Output(is_bool=False), value=BinOp(value1=Output(is_bool=False), op='x', value2=Cell(i=0))), Assign(name=Cell(i=0), value=BinOp(value1=Cell(i=0), op='+', value2=Number(x=1)))]))]))], calls=[])

## Example output ###############################

Program(
   procs = [
      Procedure(
         name = 'FACTORIAL',
         params = [
            'N'
         ],
         is_test = False,
         body = Block(
            blocknum = 0,
            stmts = [
               Assign(
                  name = Output(is_bool=False),
                  value = Number(x=1)
               ),
               Assign(
                  name = Cell(i=0),
                  value = Number(x=1)
               ),
               Loop(
                  times = Id(name='N'),
                  fixed = False,
                  body = Block(
                     blocknum = 1,
                     stmts = [
                        Assign(
                           name = Output(is_bool=False),
                           value = BinOp(
                              value1 = Output(is_bool=False),
                              op = 'x',
                              value2 = Cell(i=0)
                           )
                        ),
                        Assign(
                           name = Cell(i=0),
                           value = BinOp(
                              value1 = Cell(i=0),
                              op = '+',
                              value2 = Number(x=1)
                           )
                        )
                     ]
                  )
               )
            ]
         )
      )
   ],
   calls = []
)
History
Date User Action Args
2019-09-01 20:24:08rhettingersetrecipients: + rhettinger, brett.cannon, benjamin.peterson, serhiy.storchaka, yselivanov, Anthony Sottile, xtreak
2019-09-01 20:24:08rhettingersetmessageid: <1567369448.27.0.800784649305.issue37995@roundup.psfhosted.org>
2019-09-01 20:24:08rhettingerlinkissue37995 messages
2019-09-01 20:24:08rhettingercreate