Python Forum

Full Version: Multi-Language compiler/code Generator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. I'm looking into the feasibility of using python to generate an interpreter/code generator for a custom language. The idea is that the custom language is used to generate different code outputs in multiple other languages.

I feel getting to the point where I can generate an AST from my custom language is very doable (albeit not easy considering my skill level). However, I am having difficultly understanding how to create a code generator which can interpret the AST and spit out code in a few target languages (Ultimately, I would like to generate both C and python code). If it makes things easier, the custom language would only need simple constructs such as loops, conditionals, assignment, print statements etc. The main reason for creating a custom language is to support some specific builtin functions (i.e. raw code insertion in target language among others).

I know there is existing code translators such as Haxe, but I think that is a bit overkill for what I am trying to achieve as I do not need the entire syntax of the target language only a subset of the rules based on the constructs I define in the custom language. The overall intention here is to provide a 'golden' source that will be equivalent in the target languages and avoid potential syntax or semantic errors involved in manually writing the target code.

Any idea if something like this would be feasible?