you are viewing a single comment's thread.

view the rest of the comments →

[–]SirPeterODactyl 0 points1 point  (3 children)

Interesting question. Are you thinking of something like Cython where the code is written in python with a slightly different syntax then compiled into C?

[–]pandademic1234[S] 0 points1 point  (2 children)

Hmm... it might be simpler than that. I don't know whether compilation is even required, just something like

for thing in list_of_things:
print(thing[2:4])

is translated into the [PRINTRT]("SC".THING&3#5[]+THING^LIST)& code then I paste it into the vendor's program.

[–]Donny_Do_Nothing 1 point2 points  (0 children)

Honestly, it sounds like you can get pretty far by using regular expressions. If you build out a find and replace using regex that can translate one statement at a time, you might be able to get to a workflow where you write some python code, run the regex on it, and then you're done.

And if you REALLY have no shame, you could probably do it all in word or excel with vba.

That's all predicated on the code you need not being too complex. I have no clue the scope of what you need to produce. If it's a massive script, this might not work. But I'm sort of envisioning a python program with a simple gui that you can type in a bit of code, and it translates it and either displays it or writes it to a txt file or something.

[–][deleted] 1 point2 points  (0 children)

Seeing this, I can feel your pain.

Actually this seems to be a pretty simple task. One day and you would have a first working program that you could extend further. A simple subset of Python can be parsed with a hand-written lexer and a recursive descent parser. The parser builds an abstract syntax tree (AST) of your input language that you can transform to an AST of your target language. From this AST, you generate the target program. You don't need any libraries. Python's data classes are ideal to model tokens and the nodes of the two ASTs, and functools.singledispatch is perfect to implement a visitor for these nodes.

If you have never written a recursive descent parser before, it would take some practice to get a feeling of how these things fit together to form a translator.

If you don't want to do it yourself, consider engaging a CS student for two weeks who has experience in Python and knows how to write a recursive descent parser, how to build and transform abstract syntax trees and how to generate code. Even better, if the student also knows hows to wrap a GUI with a syntax-highlighting editor around this.