Python Forum
Multi-Language compiler/code Generator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi-Language compiler/code Generator
#1
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?
Reply
#2
I would use lex and yacc
tutorial: https://www2.cs.arizona.edu/classes/cs45...-large.pdf
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Online Compiler alexmaxwell1 2 1,521 Sep-03-2023, 05:54 PM
Last Post: Skaperen
  Is python an interpreted language or a compiled language? GouravDas 1 2,020 Jun-23-2020, 10:38 AM
Last Post: Gribouillis
  Best compiler for windows or mac linux Shadowdevelopment 0 1,614 Jan-21-2020, 02:25 AM
Last Post: Shadowdevelopment
  ChocoPy - A Subset of Python3 used for teaching compiler courses nilamo 0 2,146 Sep-13-2019, 06:49 PM
Last Post: nilamo
  Transcrypt 3.6.56 Python to Javascript compiler now supports embedded JSX. jacques_de_hooge 1 2,674 Dec-01-2017, 05:30 PM
Last Post: nilamo
  Transcrypt Python to JavaScript compiler now supports async/await jacques_de_hooge 4 4,631 Aug-24-2017, 04:21 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020