Recent

Author Topic: FPC Compiler source needed  (Read 4521 times)

Researching

  • Full Member
  • ***
  • Posts: 121
FPC Compiler source needed
« on: December 19, 2019, 03:55:46 am »
Hi, everyone!

Need to build an XML tree of code.
So want to use FPC source in the project. Actually the parcer and lexer (? if words are correct ).
How to find them in sourcecode?
Any suggestions of interfaces, entry / output points?

ANSWERS:
1. parcer and scanner are spread over whole compiler code
2. use CodeTools [for xml tree of code]
3. use fcl-passrc [used in Pascal-to-JavaScrip]


« Last Edit: December 19, 2019, 08:46:19 pm by Researching »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Re: FPC Compiler source needed
« Reply #1 on: December 19, 2019, 09:30:53 am »
FPC's parser and scanner are spread through the whole compiler source and are not separately usable in a library.

I suggest you to take a look at fcl-passrc instead which is part of Free Pascal and is also used by the pas2js Pascal-to-JavaScript transpiler as well as the documentation tool fpdoc.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: FPC Compiler source needed
« Reply #2 on: December 19, 2019, 10:17:33 am »
Need to build an XML tree of code.
So want to use FPC source in the project. Actually the parcer and lexer (? if words are correct ).
How to find them in sourcecode?
Any suggestions of interfaces, entry / output points?
FPC's parser and scanner are spread through the whole compiler source and are not separately usable in a library.
Never knew. I always thought all those processes were didactic separated.
Quote
I suggest you to take a look at fcl-passrc instead which is part of Free Pascal and is also used by the pas2js Pascal-to-JavaScript transpiler as well as the documentation tool fpdoc.

soerensen3

  • Full Member
  • ***
  • Posts: 213
Re: FPC Compiler source needed
« Reply #3 on: December 19, 2019, 04:48:03 pm »
Maybe you can use Code Tools from Lazarus. In the examples or components folder there are also basic examples.
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

sash

  • Sr. Member
  • ****
  • Posts: 366
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

Researching

  • Full Member
  • ***
  • Posts: 121
Re: FPC Compiler source needed
« Reply #5 on: December 19, 2019, 08:50:47 pm »
Very useful answers.
Will try to check.

FPC's parser and scanner are spread through the whole compiler source and are not separately usable in a library.
is it right, that to extract the parser and scanner is either difficult, or impossible??


PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Re: FPC Compiler source needed
« Reply #6 on: December 20, 2019, 09:27:22 am »
FPC's parser and scanner are spread through the whole compiler source and are not separately usable in a library.
Never knew. I always thought all those processes were didactic separated.
To be fair the scanner is rather self contained, but the parser is essentially in all units having a p prefix (12 units) and they directly generate the node tree, thus they depend on all the node units (prefix n, 18 units). Some other units are required as well. So yes, the parser is deeply integrated with other parts of the compiler.

FPC's parser and scanner are spread through the whole compiler source and are not separately usable in a library.
is it right, that to extract the parser and scanner is either difficult, or impossible??
Correct. The compiler's parser and scanner are geared towards compiling Pascal code not providing potential users with information about the source. I'd go with fcl-passrc if I were you.

Researching

  • Full Member
  • ***
  • Posts: 121
Re: FPC Compiler source needed
« Reply #7 on: December 21, 2019, 04:43:25 am »
Which of theese to use?
Code: Pascal  [Select][+][-]
  1. fcl-passrc       C : Lazarus 202\fpc\3.0.4\units \386-win 32\
  2. fcl-passrc       C : Lazarus 202\fpc\3.0.4\source \packages\
  3. passrcutil.ppu   C : Lazarus 202\fpc\3.0.4\units\386-win 32\fd -passrc\
  4. passrcutil.о     C : Lazarus 202\fpc\3.0.4\units \386-win 32\fd -passrc\
  5. testpassrc.lpr   C : Lazarus 202\fpc\3.0.4\source \packages\fd -passrc\tests \
  6. testpassrc.lpi   C : Lazarus 202\fpc\3.0.4\source \packages\fd -passrc\tests \
  7. tcpassrcutil.pas C : Lazarus 202\fpc\3.0.4\source \packages\fd -passrc\tests \
  8. passrcutil.pp    C : Lazarus 202\fpc\3.0.4\source \packages\fd -passrc\src\
  9. fd -passrc.fpm   C : Lazarus 202\fpc\3.0.4\fpmkinst\386-win 32\
  10.  
  11.  

PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Re: FPC Compiler source needed
« Reply #8 on: December 21, 2019, 11:19:46 am »
Here is an example. Alternatively you can look at the examples in $fpcdir/packages/fcl-passrc/examples.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: FPC Compiler source needed
« Reply #9 on: December 23, 2019, 01:42:16 am »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Tenaja

  • Newbie
  • Posts: 1
Re: FPC Compiler source needed
« Reply #10 on: March 01, 2020, 05:06:52 pm »
I found Crenshaw's "Let's build a compiler" article very helpful. With that as a guide, I wrote a compiler for a specific target, and also two simple parsers that are not too different from json.  It's even in Pascal...
https://www.compilers.iecc.com/crenshaw/

 

TinyPortal © 2005-2018