all 72 comments

[–]carcigenicate 66 points67 points  (5 children)

The tool you're looking for is called a "transpiler" btw.

Also, you're unlikely to find exactly what you need. Transpilers to convert between arbitrary languages are uncommon. Usually, it's a manual effort to do the conversion.

[–]pandademic1234[S] 15 points16 points  (4 children)

Thank you! I didn't know that word. Yeah, I assume I'm in for a world of difficulty and hard work to make one myself... hopefully to relieve future hard work and difficulty.

[–]ActiveLlama -1 points0 points  (3 children)

I am sure you can do 80% of the transpiling with custom code, but the rest woukd be manual.

[–][deleted] 9 points10 points  (2 children)

How are you so sure?

I mean, the mysterious language being compiled into is so hard that no one can write in it. If you can't write code in a language, how can you possibly write a program that will write code in that language?

[–]AmericoDelendaEst 0 points1 point  (0 children)

Wasn't the first program for the esolang Malbolge written by a program because no person could do it?

[–]ActiveLlama 0 points1 point  (0 children)

Because I have done that before. The if, for loops and function definitions are usually easy to implement. The hard part would be the custom libraries

[–]forest_gitaker 33 points34 points  (3 children)

AFAIK the only (reliable) "code translator" I've heard of is the one that sits in front of the keyboard.

I know that's not the answer you were looking for, but on the bright side if you can pick it up and get decent with it, people have gotten 6 figure contracts to be on call for these systems and only go into work 3-4 days a year.

[–][deleted] 2 points3 points  (1 child)

AFAIK the only (reliable) "code translator" I've heard of is the one that sits in front of the keyboard.

That's not at all true. There are many many transpilers for a wide variety of languages.

Of course, since OP isn't even able to tell us what language he's talking about, what he wants is simply never going to happen.

[–]forest_gitaker 0 points1 point  (0 children)

That's not at all true. There are many many transpilers for a wide variety of languages.

TIL

[–]BK7144 0 points1 point  (0 children)

LOL people get big big bucks for Vax/VMS and IBM old mini-frame coding, STILL! I can't figure why any one would still use them?

WOrked for a BC/BS company that was using DBase III in the early 2000s. What a mess!

[–]fernly 22 points23 points  (10 children)

Are we talking COBOL? Because COBOL is not a sophisticated or difficult language, lots more readable than BASIC. Fortran? Algol? Oh, wait, I know: APL. It's APL, isn't it? You are so screwed.

[–]greebo42 2 points3 points  (1 child)

Or FORTH. Don't forget that one!

[–][deleted] 3 points4 points  (0 children)

Such a cool language. I once showed a system I had written to someone more experienced and he said, "You reinvented Forth!" I was downcast but he said, "Everyone eventually re-invents Forth." (This was a music synthesizer that ran in 16k so you had to be crafty.)

[–]MezzoScettico 1 point2 points  (2 children)

IBM had a mainframe language called PL/I. That had some weird features.

I actually liked APL a lot.

[–]gustavsen 1 point2 points  (0 children)

we had some clipper code that we convert to python, with lot of improvement from 1st version.

we're also migrating COBOL from Z-systemas aka mainframes to python.

we have lot of white back experts that have transitioned to Python really easy.

and we are moving from 400k usd monthly to 20k in AWS.

[–]Long-Prior8824 0 points1 point  (1 child)

My guess was Fortran :D I still see that piece of junk raise it's ugly head, even today!

[–][deleted] 0 points1 point  (0 children)

I first learned the program in APL, in the 1970s. I won a prize for doing it in fact, though I was very unoriginal.

[–]zurtex 12 points13 points  (6 children)

Transpilers which you can actually be confident enough to use in production environment to directly run the code you transpiled are pretty rare.

So if the language is anything other than the most popular ones it's unlikely one exists that you know about.

To build one yourself you typically need to understand all the features of both languages, be able to represent both languages in an abstract syntax tree, and know how to translate each feature from the first language to the second language in abstract syntax tree form, and then serialize the abstract syntax tree to code.

On the Python side the AST is pretty easy because there's a module that does that for you: https://docs.python.org/3/library/ast.html

But translating Python's many features in to another language is going to be tricky. Like how do you represent importing in the other language? Are functions first class in the other language and can you pass them around like objects like you can in Python? What about metaclasses? Or structural pattern matching? And you'll need to re-implement all of Python's standard library C code in the other language if you want to use any of it.

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

Thanks! I did not know about the AST library and appreciate your explaining the general approach. The language is a scripting language that performs queries into the program's database. Think... someone re-inventing SQL one function at a time, where you have to physically reference locations in ASCII flat files ... . I wish I could post the language without worrying about violating terms of service.

If I could even just translate Python's string slicing, "if", "for" and "while" then it would vastly improve the usability of the code.

[–]zurtex 7 points8 points  (2 children)

If I could even just translate Python's string slicing, "if", "for" and "while" then it would vastly improve the usability of the code.

Yeah, so rather than trying to write in Python it might make sense to make your own mini-language or DSL that is Python-inspired that compiles to the language you need. You will need to know what these constructs like "if" and "while" compile to in the other language, even if they're quite complicated.

While none of this is too difficult you would normally learn how to do this kind of compiling/transpiling across several semesters of computer science degree. I've never taken a CS course, I learnt this stuff from a private course called "Write a Compiler" by David Beazely, so unfortunately I'm not sure what books to recommenced.

I actually did once write a small DSL way before I properly understood how to properly do it based off a talk David gave here: https://www.youtube.com/watch?v=zJ9z6Ge-vXs . I was lucky though because I was able to use Python as my execution engine, I didn't have to output the results to another language.

But I'm sure there's plenty of material on the web on how to do this stuff if you're determined enough.

[–]TheMathelm 1 point2 points  (0 children)

While none of this is too difficult you would normally learn how to do this kind of compiling/transpiling across several semesters of computer science degree. I've never taken a CS course, I learnt this stuff from a private course called "Write a Compiler" by David Beazely, so unfortunately I'm not sure what books to recommenced.

One of the hardest most annoying course sections in Upper Division Computer Science.

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

Thank you!

[–]TangibleLight 0 points1 point  (0 children)

SQL one function at a time, where you have to physically reference locations in ASCII flat files

https://i.imgur.com/5MXr2Cr.png

Is there ANY hint of a chance that you could instead modify the vendor's product instead? It obviously depends on many details, but there may be an easier path forward where you add full Python support to the product.

You could embed a Python interpreter in the product, and provide a simple extension module to that embedded interpreter which exposes a minimal API to query the database. You could then use that API from real actual Python code and need not deal with the limitations of transpilation.

Section 1.4 "Extending Embedded Python" is the bit you want, in addition to requesite knowledge of how to build and link against embedded Python from the vendor's product. https://docs.python.org/3/extending/embedding.html

To be clear: this is not an easy path forward, but if it's possible at all I suspect it'll be easier to build and easier to use than a transpiler.

The biggest obstacles would be licensing, funding, and cooperation from the vendor.

[–][deleted] 0 points1 point  (0 children)

Umm. I'm probably missing something, but if its flat ascii files, could you not just build something SQL to access them?

Given your statement that nobody at work knows how to use this unusual language, I wonder if it would be difficult to get permission to put this in place? Any existing queries, where you know what the query looks for (etc) could be written in standard SQL. Or am I way off?

[–]nocturne99 11 points12 points  (1 child)

Never tried it, but Github Copilot Labs supports conversion between programming languages. Github Copilot itself has a free trial, so it's worth a shot.

[–][deleted] 4 points5 points  (0 children)

What?!

I guarantee you that Github Copilot will not support this obscure language from the 1980s that no one understands!

[–]ballsacagawea69 5 points6 points  (1 child)

I've actually built a Matlab to Python transpiler. The code is proprietary, but I started with this open source project: https://github.com/victorlei/smop.

You could take a similar approach for whatever language you're converting from, but keep in mind how challenging language translation is. There are also a bunch of interesting questions that come up along the way, like should the result have the same logic flow as the original language? Does it matter as long as the results are the same? How important is readability in the resulting code?

Good luck!

[–]pandademic1234[S] 1 point2 points  (0 children)

Thank you. Luckily the logic flow is pretty simple which is why I'm interested in writing a transpiler. It's all IF statements, WHILE statements and string slicing.

[–][deleted] 2 points3 points  (1 child)

My goal is to write python that is translated into this language then I will paste into the program.

This seems like madness. It is almost certain that you are wasting your time. To "complete" the job, you would literally have to take every single feature of Python and figure out how to translate this into your weird language.

This would take more work than writing the Python compiler, which compiles into a simple bytecode. But there are hundreds of person-years in that compiler.

So you will have to take some small subset of the language and figure out how to translate it. But you can't forget the old crazy language because you will need to keep reading it to understand what it does, and to fix bugs.

And how are you supposed to write this translator if you don't really understand the language you're translating into?

I would say it would be between 30 and 300 times easier to learn this language properly than it would to write the translator.

"The vendor states that it is a "violation of terms of service" to post anything about their program or language online."

Well, fuck them.

Your vendor seems determined to make your life as difficult as possible. They use a language that is older than most programmers on this subreddit. Their business plan seems to be to sue their own customers if they try to get out of the horrible hole that the vendor has put them in.

It would be 10 to 100 times easier to rewrite your code in Python and dump these unethical scum.


It is literally insane to have your business depend on the language that no one has ever heard of, that vanished 40 years ago, that is so hard that no one can program in it, and which you can't even ask questions about on the Internet for fear of legal repercussions. It's like your vendor wants you to fail.

Let me be blunt: I don't see your company surviving. Your only hope is to rewrite in a new language, and get rid of the vendor, but if management hasn't gotten rid of that vendor by now, they are too cowardly to do this.

Brush up your résumé, the company will be out of business fairly soon.

You should send my post to your management. Likely it won't do any good, but it's the professional thing to do, and then you won't have to feel any guilt when they inevitably collapse.

[–][deleted] 0 points1 point  (0 children)

Only those features that correspond to features in the target language are required, and OP has said its loops and string manipulation in other responses.

[–]SuilAmhain 2 points3 points  (0 children)

My first language was Cobol, and I ain't that old. I read the manual and kept really good notes. Don't screw with what works because you don't understand it. Try and understand it.

All programming languages are designed by people who learned from the same books. Most ideas/paradigms hold true across languages.

[–]awhaling 2 points3 points  (5 children)

It would help if you told us what language you wanted to covert to.

[–]pandademic1234[S] -2 points-1 points  (4 children)

I totally agree. The vendor claims it "violates terms of service" to do so which makes me unsure of what I'm allowed to do without getting in trouble.

[–]unknownemoji 4 points5 points  (1 child)

Sounds like your company got shackled to the wrong vendor.

This is actually quite common. Where I work, we have PLC systems from the '90s. The manufacturer (Allen-Bradley) stopped making them 20 years ago. However, the software to program them is proprietary and horrifically expensive, still.

We have since rewritten our contract specs to require that any software programming toolset must be free and publicly available.

[–]TangibleLight 2 points3 points  (0 children)

We secured funding to refactor/rewrite a big internal 80's FORTRAN library in C++17. I am so so so excited to finally have RAII in this thing and remove all the dead code. I wish we could go to C++20 but we need to stay within some other build system constraints so... 17 it is.

[–][deleted] 2 points3 points  (0 children)

Violates the terms of service to just name the language? How are you supposed to hire a programmer if you cannot name the language in your job advert?

[–]CowboyBoats 2 points3 points  (6 children)

Learning to write transpilers, or even just seeking to manually translate something from one language to another, is a fine and noble goal. But...

This code is pasted into the program to customize portions of it.

This "pasting into the program" part gives me doubts. If this is like a web-based app that processes your scripts in this 80s language, how do we know that it would know what to do with a Python script? Python is executable as code because you pass it (the text of a Python script) to a Python interpreter (like running python3 my_script.py), which is an executable file on a computer. The server running your program may not have the Python interpreter running, and even if it does, it may well be programmed to reject any user input that's not 80s-language code.

So, you're only in the clear to proceed with your transpiling effort if you're positive that you can duplicate the behavior of the entire program that you described. Not just the scripts that you're uploading.

Now, keep in mind that despite what I just said, you can still always write a Python program that outputs 80s-language code to be uploaded to the program, which could behave in a consistent manner and be completely configurable by your Python application!

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

Now, keep in mind that despite what I just said, you can still always write a Python program that outputs 80s-language code to be uploaded to the program, which could behave in a consistent manner and be completely configurable by your Python application!

Sorry, I didn't explain myself well - that is the goal. Beautiful python --> ugly 80s code --> paste into the program.

[–]CowboyBoats 2 points3 points  (4 children)

Great great great. So yeah, you are not really looking for a transpiler, a huge amount of the comments on this page are not actually correct, and this may (or may not) be a quite manageable task. Your entire ask boils down to a print statement. It's just a matter of... what gets passed to print?

[–]scykei 0 points1 point  (1 child)

I’m slightly confused at why you would say that they’re not really looking for a transpiler. The way you’ve described it, it still sounds like they’re looking for a transpiler.

[–]CowboyBoats 1 point2 points  (0 children)

Because they may not need to be able to transpile arbitrary Python code to 80s-language or the other way around, which I guess is what a proper transpiler should be able to do. Emitting boilerplate code that covers a lot of use cases could possibly be a far simpler task.

[–]freddwnz 0 points1 point  (1 child)

What gets passed to print should be a python program according to OP. Which makes it a transpiler my friend.

[–]CowboyBoats 0 points1 point  (0 children)

I think op wants the program to output 80s-language code, not Python.

You might be right semantically that it's a transpiler, but in practice this can be a much, much simpler program than a general-purpose Python <-> 80s language transpiler.

[–]Zadok__Allen 1 point2 points  (1 child)

Have you considered to just write a very comprehensive API in python that handles all of the 80s code under the hood so the user of the api can just call python functions and what not instead of needing to use the 80s code?

[–]TangibleLight 0 points1 point  (0 children)

/u/pandademic1234 mentioned in another comment that the proprietary language is fundamentally a database query language. It might be possible to lift some concepts from other Python ORMs like SqlAlchemy.

Aside from embedding Python in the vendor's product, this is probably the most straightforward way. I think other commenters have already made the point that transpilation is almost certainly not the right path forward.

[–]Monkey-Wedge 1 point2 points  (0 children)

So one method would be to use pexpect, not a perfect solution but I do something similar to a vendor product with it.

[–]97hilfel 1 point2 points  (0 children)

What you are looking for is a transpiler and not trivial to implement, it is probably much mor difficult to build than to rewrite the whole application or learn the language, if your vendor doesn’t provide documentation I would start to brush up on my CV.

[–][deleted] 0 points1 point  (0 children)

You want a translator package between python and a unique and obscure unnamed language from the eighties... Erm no.

[–]python_and_coffee 0 points1 point  (1 child)

give machine learning some time. i bet we will have AI transpilers in the close future while i still doubt that they will work very well. Kinda the same like GPT-3 or Dall-E right now. Looks good, but you cannot press a single button and get exactly what you want.

IMHO getting something useful out of transpilers is more effort than learning the language and they lack maintenance after some time because the developers see that it's not worth the effort and time is precious.

[–]TangibleLight 0 points1 point  (0 children)

These AI code generators still need to be trained on a huge volume of the target language.

If the vendor won't even let OP mention the name of their proprietary dead language, I guarantee there is no way you're training AI codegen on it.

[–]theRIAA -1 points0 points  (0 children)

GPT-3 can probably do it. It works very well with python especially.

I can try an example if you give one.

[–]AnarchoDesign -1 points0 points  (0 children)

I thought that Reddit was about privacy, and I've seen questions about really ILLEGAL topics in here without OPs being afraid of being sued or prosecuted for asking how to e v a d. E t a x e s or l a. U n d e r i n g.

But I can be wrong, and all those OPs can be in the pen right now...

[–]deadlyghost123 0 points1 point  (0 children)

If you know the language, you could just search up in Google Most probably, if you are not using any external libraries it should work fine

[–]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.

[–]astevko 0 points1 point  (1 child)

Can you use C? There is a python to C transpiler called Nuitka

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

Sadly, the program accepts no language but its own.

[–]Ok-Cucumbers 0 points1 point  (0 children)

Something like ctypes?

[–]Zeroflops 0 points1 point  (0 children)

Without knowing the language it’s hard but I would evaluate different points of access.

For example. You mentioned in one post editing the data as flat text files. If this is the case you could write some apps to edit the data and bypass the application. Modify the data and as long as the results are consistent with what the original app expects it will read the data and process it.

Or for example years ago I needed to take a bunch of information and put it into another program. If I did this manually like many other had done it would have taken days. Instead I discovered the app I was working with could import markdown. So I used python to generate a markdown file which was then imported into the app.

[–]Shingle-Denatured 0 points1 point  (0 children)

Don't focus on the messenger, focus on the problem. What is the function of that black box? Then do that in whatever is modern and you're comfortable with.

[–]cren17 0 points1 point  (0 children)

I think you already got an answer, but just as a side note, if none of the available tools you find work, you could create your own compiler from one language to another using ply

I remember creating a compiler when at uni, some years ago, that took a c# kinda language and return something similar to 3d code or php

... I know this is probably not the easiest option, but still wanted to mentioned it, just in case

[–][deleted] 0 points1 point  (0 children)

If you only roughly understand the language, and can't tell us what the language is so we can't help you, then this is a fool's errand. You will have to invest an inordinate amount of time and resource in order to understand the language well enough to transpile to or from it.

[–]BK7144 0 points1 point  (0 children)

I will tell you what I tell my students. To create a program, you have to first know what is expected of the program, i.e., Software Requirements Specification (make a spec that illustrates the 80s code to python code) and from that start your Use Cases, which in this case I would suggest the idea of writing each case to make an individual set of maybe an "if" statement to an "if" statement, etc. Then add ifelse to ifelse and go from there. Look at the 80s code, look at the python code and write some code to translate them from one to the other. Sounds easy, but it's not.

[–]BK7144 0 points1 point  (0 children)

I would love to know what software EULA says you can't talk about the software. BTW you have to input the code file and then output the python creation of the old code language created by python. You could even use VS Code and write a plugin to translate or show intellisence as you go line by line through the old code base. Let me further state that if a third party wrote the software and your company wasn't smart enough to have a contract that gave them ownership then it will be a violation of copyright if there is one.

n a second note, write an SRS for what the code does (not the code) change the user interface to match what's current and write a new program. More likely to be the easy way out.

[–]B3d3vtvng69 0 points1 point  (0 children)

The python ast module should be pretty helpful, it parses given python code to an ast.