Message350962
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 = []
) |
|
Date |
User |
Action |
Args |
2019-09-01 20:24:08 | rhettinger | set | recipients:
+ rhettinger, brett.cannon, benjamin.peterson, serhiy.storchaka, yselivanov, Anthony Sottile, xtreak |
2019-09-01 20:24:08 | rhettinger | set | messageid: <1567369448.27.0.800784649305.issue37995@roundup.psfhosted.org> |
2019-09-01 20:24:08 | rhettinger | link | issue37995 messages |
2019-09-01 20:24:08 | rhettinger | create | |
|