I have worked on the static analysis on Python source code recently. There is already a static analyzer written in Ocaml for CIL(C Intermediate Language) in our group. We want to reuse this analyzer, so our ideal approach is to translate Python to CIL.
Currently, I use Python built-in ast module to parse Python to Python AST. And then I translate the Python AST that ast.dump printed to C AST. In consider of C AST to CIL API and the static analyzer all written in Ocaml. I choose Ocamllex&Ocamlyacc to parse Python AST to C AST. However, there are some big problems.
The AST representation which ast.dump printed is hard to identify. That make my parser not easy to implement. On the other hand, I can't use Ocaml to acess the Python ast internal structure. Even I could, the data structure is different from Ocaml.
I wonder whether I choose a wrong approach on the translation from Python code to C AST at first? Is there any other existing tools or approaches that may meet my requirements?
If there is anything I miss, please just point out that will be a lot of help for me. Thanks.