[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?



Hello to everybody!
I surely didn't mean to stir everything up like this! :-)))



At 22.59 21/02/2001 -0500, you wrote:
>Hi,
>
> > 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...

As far as those "C" structures are concerned, they are plain C, but they 
are quite complex because they make up a framework that consist of many 
user-defined types (plain "-la-C" typedefs), and some nested structures. 
No "C++-ish" flavors here, though...

>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 ).

IDL is a declarative-only language for describing what (i.e. methods and 
fields) distributed objects *can* export and share on the ORB (Object 
Request Broker), so as for other objects to use and process their output. 
You can't actually write a program in IDL, it's only a way of defining 
interfaces. Then an ad-hoc parser will translate this IDL declarations into 
both C++ and Java interfaced, using the correspondence relationships that 
are established between IDL- and C++/Java types.
All in all, I've a hunch that it's very simple to parse, perhaps simpler 
than Java; so, I'd expect SableCC to do a fine job with it. But the problem 
it's me, 'cause I'm not that familiar with writing grammars.


> > Therefore, I am looking for an IDL grammar,
>You don't need that, as IDL is your output.

Huh? I guess I don't have the grasp of what you mean here :-))

>It really depends of the size and the complexity of the programs you have to
>convert.

I don't care about complexity in the sense that if I knew how to make the 
conversion automatic, I wouldn't mind having my PC run even over a whole 
weekend.

>It will help me of you can show an example and a pointer to an IDL
>description.

Sure, I will dig the net for some pointers and I will post it on the list ASAP

Thanks in advance to everybody for your help.
Emmanuele

P.S. Kudos to anybody cursing bad software design practices. But I found 
myself faced with loads of code I didn't write myself. If you want to get 
things done quicly, then you're going to pay the price for not using a 
sound design approach from the very beginning...