[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Translation of C structs into IDL ones: can SableCC do the trick?


> Here comes the core question: could SableCC be used to write a converting
> parser between C(++) and IDL?

Yes, it can do it, but I don't think it will be very useful as you probably
don't need an AST for what you are doing.

> I know this is likely to be a hopeless task, but I would like to
> investigate some smarter approach than rewriting all structs from scratch.
> Of course not everything could be recycled, but at least I might give it a
> try.

Here is how I see your problem, if I understood it well.

Assume you have to convert structures like that:
struct {
	int a;
	struct B b ;
} foo;

So all you need to do is to find the structures, their names, their types and
their fields and fields types. You can distinguish them without even knowing
the C grammar, as long as it was not written in a fancy way.
You also need to get all the types info you can, such as typedefs...

You can do all of that with a simple script (a few lines of Perl or Python
will do) or you can use SableCC with a very simple grammar.

Once you collected this, you will probably need to resolve types if it is
possible ( I don't know IDL and what you can transpose to it ).

Then you print the structures you collected the IDL way. If there are types
you cannot resolve to IDL things, put a big "FIXME" instead so that you
resolve these problems yourself later.

> Therefore, I am looking for an IDL grammar,

You don't need that, as IDL is your output.

> it that I might customize to suit my needs) and some hints/clues/whatever
> to lead me into the right way, or just convince me I should give up right
> way :-))

It really depends of the size and the complexity of the programs you have to
It will help me of you can show an example and a pointer to an IDL

Hope this helps,

----        Fabien Deschodt                    Sable Research Group
------    fabien@deschodt.net               http://www.sable.mcgill.ca
----    http://www.deschodt.net