开发者

how to implement an idl-to-java compiler

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 thin开发者_如何学Pythonk 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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜