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

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



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

This depends.  Read further down.

> 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.
> 
> Therefore, I am looking for an IDL grammar, a C/C++ grammar (or a subset of
> 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 :-))

Parsing the complete C++ syntax is not feasible with the current SableCC
version.  C is much easier to parse, in general, but there are currently
no complete C grammar (with necessary related customized lexers/parsers)
for SableCC.

But you are only interested in the declarative part of C/C++, so that
might make it easier to build a grammar for this specific subset of the
two languages.  I really don't know about C++, but I suspect this part
to still be a nightmare.  For C, on the other hand, I am pretty sure
that a reasonable grammar could be built easily, assuming you implement
the mechanics to handle typedefs.

There's possibly other difficulties, depending on your specific problem.
(1) Preprocessing [e.g. do your declarations use macros?]
(2) #include [e.g. do your declarations use "FILE" or other included
types?] 
...

So, baseline:
If you are processing a relatively simple set of struct declarations,
with no attempt to declare function pointers and other ugly things (from
a parsing point of view;-), with no preprocessing, then it is a feasible
task.

If, on the other hand, you are very new to compiler tools, and have
nobody to help you, OR you need to parse a bigger subset of C (or very
minimal C++), then you might be better off refreshing your "C skills",
and modify GCC's front-end to implement your transformation.

Others might have better suggestions;-)

Good luck!

Etienne
-- 
----------------------------------------------------------------------
Etienne M. Gagnon, M.Sc.                     e-mail: egagnon@j-meg.com
Author of SableCC:                             http://www.sablecc.org/
and SableVM:                                   http://www.sablevm.org/