简体   繁体   English

如何在数据库中存储“元”源代码

[英]How to store “meta” source code in a database

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. 在第二步中,我想将数据库中的此结构转换/导出为经典语言(C#,Java等)的源代码,或直接将其编译为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. 我在互联网上搜索,我认为所要查找的是“数据库中的源代码(SCID)”-不幸的是,我找不到该想法的实现。

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 -也可以是noSQL数据库
- I currently don't care how the program is imported/entered into the database -我目前不在乎程序如何导入/输入数据库

It sounds like you're looking for some kind of common markup language that adequately describes the common semantics of each target language - eg 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. 这与存储在数据库中无关,而与具有单个(我想像,类似XML)的结构有关,该结构随后可以由目标语言进行解析和评估以生成本机源代码/字节码。 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. 可能是您不需要完整的源代码,而只是对运行时数据的描述-XML和JSON等格式正是用于此目的的,并且提供了可解析并映射到本机对象的简化描述。等价物,并且源代码围绕该数据的动态解析构建。

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. 例如,如果您选择的语言首先转换为字节码,则从技术上讲,您也许可以将二进制字节码存储在BLOB中,然后直接运行它。 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). 当然,如果仅使用解释语言,则可以简单地存储完整的源代码并进行eval (以目标语言首选的任何方式)。

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. 如果您提供有关预期用例的更多信息,我相信您将获得一些体面的建议,以了解如何处理它而无需发明源代码Babelfish。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM