I want to parse my contract written in solidity to AST, do some analysis on AST and editing,then generate that edited version back to source code so it is possible to execute it.

I know I can do colc --ast-json which gives AST for the contract.

I know there are solidity-parser, solparse for going from code to AST. However, solc and these two tools produce different ASTs.

I tried using soltar(for going from AST back to code) which is meant to be used with solidity-parser or solparse. However it only works with version 0.1.0 of the parsers which means I am missing out a lot of Solidity language. And soltar seems to be missing out contract names so I am sure along the way I would find more bugs like this.

Are there any other helpful tools that can help me do this? Do you think it is feasible to implement something like this with very good accuracy so the generated code from AST is executable and correct?

It would also be good if I could use solc on AST instead of just source code but I don't think it is possible.

  • Hi viknek, I also tried out the tool and I am facing the same problem with yours. Have you solved the problem? Looking forward your reply!
    – Bowen Xu
    Feb 8, 2018 at 2:50
  • Hi, I haven't however I am in progress of writing my own AST => source code. Will keep you updated.
    – viknek
    Feb 17, 2018 at 14:37

1 Answer 1


Try this tool:


SIF can help you query and instrument the AST and generate source code back from the modified AST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.