PycParser を使用して C 関数の抽象構文ツリーを生成しましたが、解析ツリーを文字列に変換する方法をまだ見つけようとしています。
from pycparser import c_parser
src = '''
int hello(a, b){
return a + b;
}
'''
ast = c_parser.CParser().parse(src)
aString = ast.show()
print(aString) #This prints "None" instead of printing the parse tree
生成された解析ツリーから文字列 (または文字列の配列) を生成することは可能でしょうか?
これは出力された抽象構文ツリーですが、文字列に変換する方法がわかりません。
FileAST:
FuncDef:
Decl: hello, [], [], []
FuncDecl:
ParamList:
ID: a
ID: b
TypeDecl: hello, []
IdentifierType: ['int']
Compound:
Return:
BinaryOp: +
ID: a
ID: b