[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Translation of C structs [a rant]
Fabien DESCHODT wrote:
> > 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.
[...description of the quick hack method that should work in practise...]
Yes and no. One of the reasons for the sorry state of software tools right now is
that while C (and C++ even more so) is convenient for many tasks, it is almost
impossible to process automatically, and so everyone either just does it by hand
or produces half-way solutions such as the one you propose.
This observation doesn't do much for solving the current problem, it's true, but
with the current audience let's say this anyway: please folks, when you're
designing a new language, always remember the need for automatic processing! You
should design a language in one of three ways:
(a) with all the parsing tools for the language itself in the standard library,
so at least getting an AST is something users are guaranteed (the Common Lisp
approach would also count if the interface to code-walking were properly
specified, but it really isn't);
(b) with a totally trivial syntax straightforwardly mapped to the semantics, so
you can get it right more or less off the top of your head; or
(c) (a distant third) with good enough abstraction facilities and isolating
syntax built in so that it's possible to write totally stylised code, when
necessary, without losing access to the full power of the language.
The fact is that about once a year throughout my professional life I've needed to
solve this particular problem, that of rewriting C data structures to soem end or
another, and the fact that there *is not* a good solution was designed (or
perhaps not not designed) into C from the start!
stephen p spackman