[Lazarus] Parser
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Thu Jul 1 13:35:35 CEST 2010
Marco van de Voort schrieb:
> On Thu, Jul 01, 2010 at 12:17:47AM +0200, Hans-Peter Diettrich wrote:
>> I've already translated a couple of available C libraries into Pascal,
>> using ToPas. There exist only a few constructs that do not translate
>> into Pascal directly (bitfields...), but their addition to the compiler
>> (code generators) should not be a problem - in the easiest case they can
>> be emulated in pure OPL, not affecting the code generators at all. At
>> statement and procedure level most languages don't differ much, and FPC
>> even has the C operators already implemented. Since the ToPas C parser
>> is written in OPL, its adaptation should be easy. This may become my
>> next project, after the parser...
>
> Since accessing header files is repeated as possible advantage files again
> and again, how much progress have you made in the opposite direction?
>
> Automated header translation
Sorry, I don't understand your point :-(
I found it inevitable to process existing C code at the source level, so
that every update can be reflected immediately and automatically by the
compiler. Any source code transformation, from C to Pascal, has to be
repeated after every such update, leading to much manual intervention,
and all modifications in the previously translated Pascal code are lost.
A maintenance nightmare :-(
About the opposite direction, Detlef Meyer-Eltz has made big progress in
providing translators from Delphi/OPL and Java into C++, see e.g.
<http://www.texttransformer.com/Delphi2Cpp_en.html>. While these tools
are not perfect, what IMO is impossible to achieve, they have been used
in the conversion of a couple of big commercial projects into C++.
This one-time transformation is *not* what I want to achieve, for the
beforementioned (maintenance) reasons. It may be a goodie for making
people move from C/C++ background to Pascal, when they can transform all
their legacy projects to the new language, but this can be achieved
independently from any concrete Pascal compiler.
As long as we live in a C dominated world (Linux...), every compiler
should be able to process C code, so that at least the existing C
libraries can be used immediately. Sometimes it's sufficient to only
have a header conversion tool, for external libraries, but sometimes
it's more desireable to incorporate such libraries more directly into an
application, like Delphi and Lazarus allow with their package system.
Such packages could be made usable more easily, when e.g. a more
"pascally" interface can be added to the original source code, by e.g.
patches, so that the use of such libraries is no more restricted to
their original C interface.
DoDi
More information about the Lazarus
mailing list