如何实现 idl-to-java 编译器

发布于 2024-11-29 18:23:33 字数 144 浏览 1 评论 0原文

我需要实现一个 idl-to-java 编译器。事实上,它不是idl-to-java。接口定义语言得到扩展。所以我需要实现一个可以生成java源文件的编译器。我对corba一无所知,感觉很难下手。你觉得我半年能完成这个工作吗?如果是这样,我该怎么办? ps:请原谅我的英语。

I need to implement an idl-to-java compiler. In fact, it's not idl-to-java. Interface definition language is extended. So I need to implement a compiler which can generates java source file. I know nothing about corba and I feel hard to start. Do you think it's possible for me to finish this work in half a year? and if so, what should I do. ps: please forgive my English.

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

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

发布评论

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

评论(3

愛放△進行李 2024-12-06 18:23:34

您可以使用 idl4emf:

http://code.google.com/p/idl4emf/

这个项目由 Xtext 中的 IDL 语法实现和 Ecore 中的 IDL 元模型实现组成。

该项目还包括来自 IDL 文件的代码生成器项目。您只需在 Eclipse EMF 中编写 Xpand 模板即可从 IDL 文件实现您自己的生成器。

我已成功地将这个项目用作多个生成器项目的一部分。

You can use idl4emf:

http://code.google.com/p/idl4emf/

This project is composed by an IDL grammar implementation in Xtext and an IDL metamodel implementation in Ecore.

This project also includes a code generator project from IDL files. You can implement your own generator from IDL files just writing Xpand templates in Eclipse EMF.

I've used this project as part of several generator projects successfully.

赠意 2024-12-06 18:23:33

如果你对解析器和解析器生成器一无所知,这将是一项艰巨的工作,但我认为如果你不从头开始,半年应该足够了。

我建议你使用 Antlr,它恰好有一个 IDL 解析器实现 在其贡献的示例中。这可能适用于旧版本的 Antlr,但这绝对是一个很好的起点。请务必获取Antlr 书,您将需要它!

对于代码生成部分,您可以使用 StringTemplate,这是一个由 Antlr 的作者 Terence Parr 编写的模板引擎,正是用于此目的目的。

如果您确实必须实现整个 ORB,您不妨看看其他人是如何做到的,例如此处

If you don't know anything about parsers and parser generators it's going to be a tough job, but I think that half a year should be plenty if you don't start from scratch.

I suggest that you use Antlr, which happens to have an IDL parser implementation among its contributed examples. This is probably for an older version of Antlr, but it's definitely a good starting point. Be sure to get hold of the Antlr book, you're going to need it!

For the code generation part you could use StringTemplate, a template engine written by Antlr's author, Terence Parr, exactly for this purpose.

If you really have to implement a whole ORB you might as well check out how others did it, e.g. here.

再见回来 2024-12-06 18:23:33

真正的 IDL-to-java 不仅会产生将这些内容映射回 IDL 定义的 Java 代码(严格遵守 OMG 标准)。它还生成允许您的定义与底层 CORBA 堆栈一起使用的 Java 代码(与为目标硬件体系结构生成指令的真正编译器不同)。

也就是说,IDL 编译器

1) 获取您的 IDL 定义并将它们转换为 CORBA 堆栈,特定于语言的独立定义(在您的情况下,在 Java 中)。

2) 除此之外,它还生成 CORBA 堆栈/供应商特定的代码。

如果您需要的只是执行 #1 的功能,那么它就不是 IDL 到 Java 编译器(不是真正意义上的编译器)。但为了简单起见,我们可以这样称呼它。

因此,这里有两种可能的途径:

1) 查看基于 Java 的现有 CORBA 堆栈(OpenOrb 或 JacOrb)的 IDL 编译器的源代码,或者

2) 查看 OMG 的规范,它告诉您如何从 IDL 映射到您的 IDL。选择的语言:http://www.omg.org/technology/documents/idl2x_spec_catalog.htm

这一切都假设您了解编译器理论和实现。否则,如果这是一个学习实验,那就太好了!但如果这是有截止日期的工作的一部分,这可能是一项不切实际的任务。

不管怎样,祝你好运。

A true IDL-to-java not only spews Java code that maps that stuff back to IDL definitions (strictly adhering to the OMG standards). It also generate Java code that allows your definitions to work with an underlying CORBA stack (not unlike a true compiler generating instructions for a target hardware architecture.)

That is, an IDL compiler

1) takes your IDL definitions and converts them into CORBA-stack, language-specific independent definitions (in your case, in Java).

2) In addition to that, it generates CORBA-stack/vendor specific code as well.

If all you need is something that does #1, then it's not an IDL-to-Java compiler (not in the true sense of the word). But we can call it that for the sake of simplicity.

So you have two possible routes here:

1) Look at the source code of IDL compilers from existing CORBA stacks that are Java based (OpenOrb or JacOrb), or

2) Look at the OMG's specs that tell you how to map from IDL to your language of choice: http://www.omg.org/technology/documents/idl2x_spec_catalog.htm

This is all assuming you know about compiler theory and implementation. Otherwise, if this is an experiment for learning, great! But if this is part of work with a deadline, this could be an unrealistic task.

Either way, good luck.

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