0

I would like to store a computer program in a database instead of a number of text files. It should contain the structure and all objects, methods, dependencies etc. of the program. I do not want to store a specific language in the database but some kind of "meta" programming language. In a second step I would like to transform/export this structure in the database into either source code of a classic language (C#, Java, etc.) or compile it directly for CLR/JVM.

I think I am not the first person with this idea. I searched the internet and I think what I am looking for is called "source code in a database (SCID)" - unfortunately I could not find an implementation of this idea.

So my questions is:

Is there any program that stores "meta" program code inside of a database and let's you generate traditional text source code from it that can be compiled/executed?

Short remarks:
- It can also be a noSQL database
- I currently don't care how the program is imported/entered into the database

  • Neo4j jumps to mind, which might be a way to model the abstract syntax tree in a Graph Database. – ldz Feb 12 '17 at 13:32

1 Answers1

0

It sounds like you're looking for some kind of common markup language that adequately describes the common semantics of each target language - e.g. objects, functions, inputs, return values, etc.

This is less about storing in a database, and more about having a single (I imagine, XML-like) structure that can subsequently be parsed and eval'd by the target language to produce native source/bytecode. If there was such a thing, storing it in a database would be trivial -- that's not the hard part. Even a key/value database could handle that.

The hard part will be finding something that can abstract away the nuances of multiple languages and attempt to describe them in a common format.

Similar questions have already been asked, without satisfying solutions.

It may be that you don't need the full source, but instead just a description of the runtime data-- formats like XML and JSON are intended exactly for this purpose and provide a simplified description of Objects that can be parsed and mapped to native equivalents, with your source code built around the dynamic parsing of that data.

It may be possible to go further in certain languages. For example, if your language of choice converts to bytecode first, you might technically be able to store the binary bytecode in a BLOB and then run it directly. Languages that offer reflection and dynamic evaluation can probably handle this -- then your DB is simply a wrapper for storing that data on compilation, and retrieving it prior to running it. That'd depend on your target language and how compilation is handled.

Of course, if you're only working with interpreted languages, you can simply store the full source and eval it (in whatever manner is preferred by the target language).

If you give more info on your intended use case, I'm sure you'll get some decent suggestions on how to handle it without having to invent a sourcecode Babelfish.

Community
  • 1
  • 1
Lee Benson
  • 11,185
  • 6
  • 43
  • 57
  • Thanks for your answer! I think you are right that storing in a database is not a problem if there is a way to store the structure in an xml or so format. I understand that every language has it's own special way to solve problem which might be difficule to match with a structure that is also valid for other languages. In the first place I would like to store commen concepts tat most languages have in common. My main idea is to create a visual language like LabView. But I just want to estimate how much work it is and which parts are already available. – Michael Gerbracht Feb 12 '17 at 21:06
  • A lot, I'd imagine. Even if you build an AST for one language, porting concepts to another would be difficult - how do you efficiently port imperative code to a functional language, for example? If you want to offer a GUI that lets users drag and drop code concepts and then run them, you might find you just need to choose ONE language and then create a JSON/agnostic data structure that uses labels and data to invoke ready-made routines. Or embed a runtime engine on top of a language and do some kind of code generation. Depends which market you're serving and how complex it needs to be. – Lee Benson Feb 12 '17 at 21:29