Sign in Join

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

Mailing lists / fpc-devel / 2014-10

Dumping the syntax tree

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Vsevolod Alekseyev

Hi all,

I wonder where in the FPC compilation flow would be a good spot to dump the parsed syntax tree of a source?

Here's why I'm asking. For a while now, I've been struggling to adapt a bunch of Pascal code to various mobile platforms. It's been painful. The code itself is pretty conservative feature-wise, almost K&R C-like (except sets and ansistrings). I wonder if I could slap together a quick and dirty Pascal-to-C converter just for this codebase to work, but I'd rather reuse the existing parsing logic.

So if anyone could point me at a spot in the FPC source where the source tree is more or less ready, that's be nice. Thanks in advance.

Reply by email

Nikolay Nikolov
to Vsevolod Alekseyev
Vsevolod Alekseyev wrote 14 lines
Hi all, I wonder where in the FPC compilation flow would be a good spot to dump the parsed syntax tree of a source? Here's why I'm asking. For a while now, I've been struggling to adapt a bunch of Pascal code to various mobile platforms. It's been painful. The code itself is pretty conservative feature-wise, almost K&R C-like (except sets and ansistrings). I wonder if I could slap together a quick and dirty Pascal-to-C converter just for this codebase to work, but I'd rather reuse the existing parsing logic. So if anyone could point me at a spot in the FPC source where the source tree is more or less ready, that's be nice. Thanks in advance.

The compiler already supports dumping the parse tree when you use the -vp option. But it's more intended for debugging the compiler - I don't know if it'll work for you.

Nikolay

Reply by email

Vsevolod Alekseyev
to Nikolay Nikolov

Good point, thanks. From a brief look, tree.log retains enough information to rebuild the source. I'll see if I can work with that...

Nikolay Nikolov wrote 9 lines
The compiler already supports dumping the parse tree when you use the -vp option. But it's more intended for debugging the compiler - I don't know if it'll work for you. Nikolay _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Vsevolod Alekseyev
to Nikolay Nikolov: The compiler already supports dumping the parse tree when you use the -vp option. But…

On second look, no, the -vp tree is not sufficient. It doesn't have datatype definitions, doesn't have interface definitions...

Nikolay Nikolov wrote 24 lines
On 10/22/2014 12:23 AM, Vsevolod Alekseyev wrote: > Hi all, > > I wonder where in the FPC compilation flow would be a good spot to > dump the parsed syntax tree of a source? > > Here's why I'm asking. For a while now, I've been struggling to adapt > a bunch of Pascal code to various mobile platforms. It's been > painful. The code itself is pretty conservative feature-wise, almost > K&R C-like (except sets and ansistrings). I wonder if I could slap > together a quick and dirty Pascal-to-C converter just for this > codebase to work, but I'd rather reuse the existing parsing logic. > > So if anyone could point me at a spot in the FPC source where the > source tree is more or less ready, that's be nice. Thanks in advance. The compiler already supports dumping the parse tree when you use the -vp option. But it's more intended for debugging the compiler - I don't know if it'll work for you. Nikolay _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Nikolay Nikolov
to Vsevolod Alekseyev
Vsevolod Alekseyev wrote
On second look, no, the -vp tree is not sufficient. It doesn't have datatype definitions, doesn't have interface definitions...

True. I guess, you can try to use ppudump in order to dump these definitions. It'll only work for units though, but I guess it shouldn't be too hard to make the compiler output ppu files for programs as well.

Nikolay

Show quoted text 30 lines
On 10/22/2014 4:44 AM, Nikolay Nikolov wrote: > On 10/22/2014 12:23 AM, Vsevolod Alekseyev wrote: >> Hi all, >> >> I wonder where in the FPC compilation flow would be a good spot to >> dump the parsed syntax tree of a source? >> >> Here's why I'm asking. For a while now, I've been struggling to >> adapt a bunch of Pascal code to various mobile platforms. It's been >> painful. The code itself is pretty conservative feature-wise, almost >> K&R C-like (except sets and ansistrings). I wonder if I could slap >> together a quick and dirty Pascal-to-C converter just for this >> codebase to work, but I'd rather reuse the existing parsing logic. >> >> So if anyone could point me at a spot in the FPC source where the >> source tree is more or less ready, that's be nice. Thanks in advance. > The compiler already supports dumping the parse tree when you use the > -vp option. But it's more intended for debugging the compiler - I > don't know if it'll work for you. > > Nikolay > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Vsevolod Alekseyev
to Nikolay Nikolov

I don't see local variable definitions there, either...

Nikolay Nikolov wrote 45 lines
On 23.10.2014 г. 18:59, Vsevolod Alekseyev wrote: > On second look, no, the -vp tree is not sufficient. It doesn't have > datatype definitions, doesn't have interface definitions... True. I guess, you can try to use ppudump in order to dump these definitions. It'll only work for units though, but I guess it shouldn't be too hard to make the compiler output ppu files for programs as well. Nikolay > > On 10/22/2014 4:44 AM, Nikolay Nikolov wrote: >> On 10/22/2014 12:23 AM, Vsevolod Alekseyev wrote: >>> Hi all, >>> >>> I wonder where in the FPC compilation flow would be a good spot to >>> dump the parsed syntax tree of a source? >>> >>> Here's why I'm asking. For a while now, I've been struggling to >>> adapt a bunch of Pascal code to various mobile platforms. It's been >>> painful. The code itself is pretty conservative feature-wise, >>> almost K&R C-like (except sets and ansistrings). I wonder if I >>> could slap together a quick and dirty Pascal-to-C converter just >>> for this codebase to work, but I'd rather reuse the existing >>> parsing logic. >>> >>> So if anyone could point me at a spot in the FPC source where the >>> source tree is more or less ready, that's be nice. Thanks in advance. >> The compiler already supports dumping the parse tree when you use >> the -vp option. But it's more intended for debugging the compiler - >> I don't know if it'll work for you. >> >> Nikolay >> _______________________________________________ >> fpc-devel maillist - >> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel >> > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Kostas Michalopoulos
to Vsevolod Alekseyev

Lazarus has a Pascal tokenizer unit under components\mpaslex\mpaslex.pp. It seems old and doesn't look like it supports the full FPC syntax, but it might be a starting point since most likely you can convert the code to C++ with GNU GCC extensions (nested functions, etc) straightforward.

Vsevolod Alekseyev wrote 60 lines
I don't see local variable definitions there, either... On 10/23/2014 12:15 PM, Nikolay Nikolov wrote: > On 23.10.2014 г. 18:59, Vsevolod Alekseyev wrote: > >> On second look, no, the -vp tree is not sufficient. It doesn't have >> datatype definitions, doesn't have interface definitions... >> > True. I guess, you can try to use ppudump in order to dump these > definitions. It'll only work for units though, but I guess it shouldn't be > too hard to make the compiler output ppu files for programs as well. > > Nikolay > > >> On 10/22/2014 4:44 AM, Nikolay Nikolov wrote: >> >>> On 10/22/2014 12:23 AM, Vsevolod Alekseyev wrote: >>> >>>> Hi all, >>>> >>>> I wonder where in the FPC compilation flow would be a good spot to >>>> dump the parsed syntax tree of a source? >>>> >>>> Here's why I'm asking. For a while now, I've been struggling to adapt >>>> a bunch of Pascal code to various mobile platforms. It's been painful. The >>>> code itself is pretty conservative feature-wise, almost K&R C-like (except >>>> sets and ansistrings). I wonder if I could slap together a quick and dirty >>>> Pascal-to-C converter just for this codebase to work, but I'd rather reuse >>>> the existing parsing logic. >>>> >>>> So if anyone could point me at a spot in the FPC source where the >>>> source tree is more or less ready, that's be nice. Thanks in advance. >>>> >>> The compiler already supports dumping the parse tree when you use the >>> -vp option. But it's more intended for debugging the compiler - I don't >>> know if it'll work for you. >>> >>> Nikolay >>> _______________________________________________ >>> fpc-devel maillist - >>> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel >>> >>> >> _______________________________________________ >> fpc-devel maillist - >> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel >> > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Van Canneyt
to Kostas Michalopoulos

You had better use the fcl-passrc units. They dump a complete syntax tree. It is used to generate (a currently limited version of) javascript, and used to create documentation.

so it should be usable to generate C code...

The test program re-dumps a pascal program.
Presumably you can adapt that to generate C.

Michael.

Kostas Michalopoulos wrote
Lazarus has a Pascal tokenizer unit under components\mpaslex\mpaslex.pp. It seems old and doesn't look like it supports the full FPC syntax, but it might be a starting point since most likely you can convert the code to C++ with GNU GCC extensions (nested functions, etc) straightforward.

Reply by email

Vsevolod Alekseyev
to Michael Van Canneyt

What test program, please? Where?

Michael Van Canneyt wrote 25 lines
You had better use the fcl-passrc units. They dump a complete syntax tree. It is used to generate (a currently limited version of) javascript, and used to create documentation. so it should be usable to generate C code... The test program re-dumps a pascal program. Presumably you can adapt that to generate C. Michael. On Thu, 23 Oct 2014, Kostas Michalopoulos wrote: > Lazarus has a Pascal tokenizer unit under > components\mpaslex\mpaslex.pp. It seems old and doesn't look like it > supports the full FPC syntax, but it might be a starting point > since most likely you can convert the code to C++ with GNU GCC > extensions (nested functions, etc) straightforward. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Van Canneyt
to Vsevolod Alekseyev

See the FPC sources:

packages/fcl-passrc/examples/test_parser.pp

Michael.

Vsevolod Alekseyev wrote 32 lines
What test program, please? Where? On 10/23/2014 4:12 PM, Michael Van Canneyt wrote: > > > You had better use the fcl-passrc units. They dump a complete syntax tree. > It is used to generate (a currently limited version of) javascript, and > used to create documentation. > > so it should be usable to generate C code... > > The test program re-dumps a pascal program. Presumably you can adapt that > to generate C. > > Michael. > > On Thu, 23 Oct 2014, Kostas Michalopoulos wrote: > >> Lazarus has a Pascal tokenizer unit under components\mpaslex\mpaslex.pp. >> It seems old and doesn't look like it supports the full FPC syntax, but it >> might be a starting point >> since most likely you can convert the code to C++ with GNU GCC extensions >> (nested functions, etc) straightforward. > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Kostas Michalopoulos
to Michael Van Canneyt

I didn't knew about that! This can be very helpful for generating C compatible interfaces for DLLs.

On Thu, Oct 23, 2014 at 10:36 PM, Michael Van Canneyt <

Show quoted text 51 lines
wrote: See the FPC sources: packages/fcl-passrc/examples/test_parser.pp Michael. On Thu, 23 Oct 2014, Vsevolod Alekseyev wrote: What test program, please? Where? > > On 10/23/2014 4:12 PM, Michael Van Canneyt wrote: > >> >> >> You had better use the fcl-passrc units. They dump a complete syntax >> tree. >> It is used to generate (a currently limited version of) javascript, and >> used to create documentation. >> >> so it should be usable to generate C code... >> >> The test program re-dumps a pascal program. Presumably you can adapt >> that to generate C. >> >> Michael. >> >> On Thu, 23 Oct 2014, Kostas Michalopoulos wrote: >> >> Lazarus has a Pascal tokenizer unit under >>> components\mpaslex\mpaslex.pp. It seems old and doesn't look like it >>> supports the full FPC syntax, but it might be a starting point >>> since most likely you can convert the code to C++ with GNU GCC >>> extensions (nested functions, etc) straightforward. >>> >> _______________________________________________ >> fpc-devel maillist - >> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel >> >> > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > > _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email