确定“编译顺序”

发布于 2024-10-23 15:11:16 字数 476 浏览 18 评论 0原文

我试图确定在文本文件中列出函数的编译顺序。你为什么问?我们在工作中使用业务规则管理语言 IDE,该语言在远程虚拟机上运行速度非常慢。我正在寻找一种从 Java 应用程序编译代码的方法。

我已经有一个 Java 应用程序,它将所有函数和其他所需文件(代码、函数名称等)读入内存。我希望能够在我的应用程序中包含一种方法来确定需要编译函数的顺序。

例如:

function B() {
 //Do Stuff
}

Integer globalVariable = 0;

function A() {
 globalVariable = 1337;
 B();
}

函数 B 必须在函数 A 之前声明。我希望能够扫描每个函数并看到“函数 A 调用 B”,因此 B 必须在 A 之前声明。全局变量也是如此(是的,语言我们正在使用 has Globals) 因此 globalVariable 必须在使用它的函数之前声明。

谢谢!

I'm trying to determine the compile order in which to list functions in a text file. Why you ask? We use a business rules management language IDE at work that runs very slow on out remote VM's. I'm looking for a way to compile the code from a Java Application.

I already have a Java Application that reads in all Functions and other needed files (Code, Function names etc..) into Memory. I would like to be able to include in my Application a way to determine the order in which Functions need to be compiled.

For Example:

function B() {
 //Do Stuff
}

Integer globalVariable = 0;

function A() {
 globalVariable = 1337;
 B();
}

Function B must be declared before Function A. I would like to just be able to scan through each function and see that 'Function A calls B' so B must be declared before A. Same thing for Global Variables (Yes the language we are using has Globals) so globalVariable must be declared before the function it is used in.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红颜悴 2024-10-30 15:11:16

解决此类问题的一种方法是将其表示为有向无环图,其中每个函数(或全局变量)是图的一个节点,图的边表示依赖关系。因此,您的示例将具有节点“A”、“B”和“globalVariable”,以及边“A->B”和“A->globalVariable”。

然后,可以通过在图表上执行拓扑排序来计算所需的顺序。

One way to solve this kind of problem is to represent it as a directed acyclic graph, where each function (or global variable) is a node of the graph, and the edges of the graph represent the dependencies. So, your example would have nodes "A", "B", and "globalVariable", and edges "A->B", and "A->globalVariable".

Then, your desired order can be computed by doing a Topological sort on the graph.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文