Recent

Author Topic: Is there the whole syntax tree information of free pascal at one place  (Read 868 times)

daniel_sap

  • Full Member
  • ***
  • Posts: 115
Do you know, if there is information with the whole syntax tree of free pascal at one place

Also, how many syntax trees there are.
I think for Windows, Linux, MacOS it is one,
but there is different for Motorola 68k, AVR

Event if it is not up to date information would be fine

Regards

jamie

  • Hero Member
  • *****
  • Posts: 7493
Re: Is there the whole syntax tree information of free pascal at one place
« Reply #1 on: September 18, 2025, 12:07:44 pm »
You mean the help file?
The only true wisdom is knowing you know nothing

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12594
  • FPC developer.
Re: Is there the whole syntax tree information of free pascal at one place
« Reply #2 on: September 18, 2025, 01:47:33 pm »
I think he means a grammar, but yeah, the railroad diagrams in the docs are also related.

There is no formal grammar for FPC or Delphi. In case of FPC is because it is a recursive descent parser.

For delphi, older version's manuals had a grammar for documentation purposes. (and most Delphi grammars on the web are derived from that non production one)

Thausand

  • Sr. Member
  • ****
  • Posts: 457
Re: Is there the whole syntax tree information of free pascal at one place
« Reply #3 on: September 18, 2025, 01:51:53 pm »
I think he means a grammar, but yeah, the railroad diagrams in the docs are also related.

Then I have question. Post write:

Quote
Also, how many syntax trees there are.
I think for Windows, Linux, MacOS it is one,
but there is different for Motorola 68k, AVR
Grammar (syntax tree) same for platform all, no ? Have result ASM differ ?

daniel_sap

  • Full Member
  • ***
  • Posts: 115
Re: Is there the whole syntax tree information of free pascal at one place
« Reply #4 on: September 18, 2025, 05:10:29 pm »
I want to build a tree from the source code of one unit.
After that from this tree to generate the code again.

I think for code formatters they use it.
I don't think that Lazarus developers for example, they check the compiler code and write the formatter.
Or in Lazaurs main menu Source|Refactoring there is Unused units, Rename identifier, Extract procedure, they should build such a parse tree structure.

For me they should use some document, or some other approach, or may be they check the compiler code, or ask compiler developers...

Thaddy

  • Hero Member
  • *****
  • Posts: 18695
  • To Europe: simply sell USA bonds: dollar collapses
Re: Is there the whole syntax tree information of free pascal at one place
« Reply #5 on: September 20, 2025, 02:05:15 pm »
https://github.com/rochus-keller/FreePascal
Been dabbling with that sometime ago and is the best yet. Do not use on trunk, though.
(And I wonder why he used C++, this could all be done in FreePascal. Seems he used some older project)

With fpc itself:
To get the parse tree, compile with -vp option. Generates a file called tree.log.
This is not enough to create a syntax tree for the whole language.
I have an adapted D7 grammar -for Gold -  that parses most, but not all constructs associated with {$mode delphi} if that helps, but that won't work for {$mode objfpc}
You may also want to look at the parser that Lazarus uses, which is a very modified version of mwparser.
You can also have a look at the Castalia parser wich also has roots in TmwParser. I have translated that to fpc, but also does not parse objfpc, only mode delphi.
I guess the Lazarus parser or fcl-passrc are your best options, besides the standard fpc-ebnf (with a grammar) and fcl-passrc packages.
fcl-passrc is used for pas2js and parses 99% or so.
« Last Edit: September 20, 2025, 02:52:55 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

PascalDragon

  • Hero Member
  • *****
  • Posts: 6272
  • Compiler Developer
Re: Is there the whole syntax tree information of free pascal at one place
« Reply #6 on: September 22, 2025, 10:35:27 pm »
Quote
Also, how many syntax trees there are.
I think for Windows, Linux, MacOS it is one,
but there is different for Motorola 68k, AVR
Grammar (syntax tree) same for platform all, no ? Have result ASM differ ?

The (Object) Pascal syntax is not different between platforms (with very few exceptions like external classes for the JVM platform or register locations for syscall functions on Amiga-likes).

Also documenting the assembly syntax is not part of Free Pascal as it uses the syntax of the underlying platform assemblers. For that please refer to the platform's documentation.

 

TinyPortal © 2005-2018