Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-03

C++ parser

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Juha Manninen

JoshyFun and DoDi,
I have read your C to pascal converter mails in the other (infamous) thread.

This is not important but just some ideas:
I understood ToPas converter is in good shape, except for #defines support. Now, C++ classes map almost directly to OP classes. If you decide to add them to ToPas, it would be interesting to try it for C++ Builder projects.

#defines are not used much in C++ because of templates, but that doesn't help pascal conversion much. And there are many other syntax additions, I know, so the task is not easy.
The conversion should just leave some parts intact and mark them with proper comments.

There is one C++ parser quite near. SynEdit has one, but I think it is very simple and not suitable for conversion.

Just ideas...

Juha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100310/6a69e4ee/attachment.html>

Reply by email

Hans-Peter Diettrich
to Juha Manninen
This is not important but just some ideas: I understood ToPas converter is in good shape, except for #defines support.

The technical support of #defines is okay, missing is only an easy to use classification of the #defines into constants, functions and macros. By default all #defines are expanded, so that e.g. the C equivalent of named constants is lost.

Now, C++ classes map almost directly to OP classes. If you decide to add them to ToPas, it would be interesting to try it for C++ Builder projects.

Classes only map *syntactically* to Class (or more directly to Object), but the lifetime (of local objects) and the initialization differs from the OPL model. This means that Free has to be added at the end of a block or subroutine, and eventually try-finally blocks must protect the resources.

#defines are not used much in C++ because of templates, but that doesn't help pascal conversion much.

In Windows applications a lot of #defines reside in the Windows headers.

And there are many other syntax additions, I know, so the task is not easy.

My primary goal was a reliable translation of header files, usable without knowledge of C/C++. This works fine for C header files, but can not be achieved for C++ headers - the result would be unusable.

The conversion should just leave some parts intact and mark them with proper comments.

That's quite a different goal. I already wrote some (simple) conversion tools, that e.g. reverse "int x" into "x: int", in declarations and parameter lists. The procedure differs from header (or C) translation in so far, as such a translator should work with incomplete information, what requires a very different parsing strategy - a bottom-up (LR) parser were more appropriate for this task than the top-down (LL) parser of ToPas. I noticed this already in an attempt to classify #defines automatically.

There is one C++ parser quite near. SynEdit has one, but I think it is very simple and not suitable for conversion.

I'd prefer a tool like TextTransformer <http://www.texttransformer.com> to process C++ source code. AFAIR it already comes with a C++ grammar, and allows to insert any translation code into the grammar - just like the name suggests.

TextTransformer is written in C++ (BCB6), and can produce parser source code in C++. It also includes an C++ interpreter for user supplied transformation code. This should make it easy to convert C++ projects, when the users are more familiar with C++ than with OPL. The integrated debugger comes with single step and breakpoint capabilities, and allows to inspect both the input and output text, what makes it easy to write and debug the added transformation code.

I also wrote Delphi components for TextTransformer <http://sourceforge.net/projects/tetrapack/>, that allow to e.g. build parse trees for later use in Delphi code. These components may be usable with Lazarus, too, but at that time I was not familiar enough with Lazarus to check or adopt my implementation.

DoDi

Reply by email

Leslie Kaye
to Juha Manninen: I have read your C to pascal converter mails in the other (infamous) thread. This is not…
Juha Manninen wrote 29 lines
JoshyFun and DoDi, I have read your C to pascal converter mails in the other (infamous) thread. This is not important but just some ideas: I understood ToPas converter is in good shape, except for #defines support. Now, C++ classes map almost directly to OP classes. If you decide to add them to ToPas, it would be interesting to try it for C++ Builder projects. #defines are not used much in C++ because of templates, but that doesn't help pascal conversion much. And there are many other syntax additions, I know, so the task is not easy. The conversion should just leave some parts intact and mark them with proper comments. There is one C++ parser quite near. SynEdit has one, but I think it is very simple and not suitable for conversion. Just ideas... Juha

A file | import menu item would be a nice feature for Lazarus. Even if it only changed the curly brackets to begin .. end; it would be a start! -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100310/31135ac2/attachment.html>

Reply by email