12

I'm trying to build a parser for Solidity, and it would help if I could build a working version off of the existing parser. I've tried looking at the source code on the official git, but I haven't worked on a project of this magnitude before and it's confusing. Could some one tell me how I could isolate the parsing and AST modules so I can read a script and build an AST from it?

(I understand the scope might be a little too broad for this question, but I'd really appreciate any pointers)

10

If you use solc --ast, the compiler will output a json-representation of the AST (this is also included in the npm version of the compiler). Is that enough for your purposes? If not, please come to gitter to discuss.

  • 1
    Is there a way to convert an AST back into Solidity code? i.e. for transpilation purposes – Raine Revere Apr 21 '16 at 3:24
3

In addition to chriseth's answer, there's also the solidity-parser project which is useful if you A) are developing in a Javascript context, or B) don't want the parser to error if there are unresolved imports (unfortunately solc --ast will error if there are imports it cannot find).

0

In addition to Tim's answer there's also a python-solidity-parser based on the ANTLR syntax and AST format used in solidity-parser-antlr that you can use if you want to avoid depending on the compiler. Note: compiler AST is the truth.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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