6 ms·
I've been thinking of a pandoc-like tool to translate between languages, i.e. a transpiler. You would need to write down the most general abstract syntax tree
by cosmic_quanta 6y ago
I've been thinking of a pandoc-like tool to translate between languages, i.e. a transpiler.
You would need to write down the most general abstract syntax tree (AST) that encompasses all supported languages' features, as well as a way to read languages into this AST, and write the AST into languages.
The cool thing about pandoc is the ability to transform the AST between the read and write. In the context of a transpiler, that might mean that you transform the AST to be safer (e.g. adding type-checks in Python) before writing out.
That would be a very tedious tool to write, given that every language has its strange behaviors. But it might be a fun project if you limit the number of languages you support.
- xaedes 6y agoSomething like LLVM and decompiling
- brutt 6y agoYou will need to create common library for all these languages, then write all your programs using your own libraries only.
- cosmic_quanta 6y agoI don't get why? The AST can be parsed by any single language. Haskell is particularly well-suited for writing parsers.
- tsimionescu 6y agoI believe the point is that you can have perfect syntactic compatibility, but that means nothing when your program calls boost::asio or a Common Lisp defmethod and you want to interpret it as Haskell. The only way this could work is if you write the whole stdlib in your AST system. Of course, this still won't mean your lazy Haskell program works as an eager C program. Language semantics are too different, even between similar languages, you'll ALWAYS hit corner cases on anything more than a toy program. Even if you translate C# to Java. Well, maybe C to C++ will work decently, as few programs use the diverging features.
- cosmic_quanta 6y agoI see, thank you.
- karussell 6y agoFor the read part I think this something what GraalVM already does https://www.graalvm.org/docs/reference-manual/polyglot/ https://www.graalvm.org/docs/reference-manual/polyglot/