Reusing the internals
lazarus / 64-FPC development
----------------------------------------------------------------------
int-index · 2015-02-01 21:44
I am developing a translator from Pascal to Haskell (source here:
https://github.com/int-index/sodium) and instead of reimplementing a
parser and a typechecker for Pascal, I would really like to reuse the
ones in FPC. So I need to modify FPC somehow to make it emit parsed
type-annotated version of source code in some easy to parse format
(such as XML).
Basically the idea is to get from this:
Code: [Select]var x: Integer; begin x := ...; WriteLn(x); end;to
something like this:
Code: [Select]...
Note the added type-conversion (reusing FPC typechecker and semantic
analysis).
My questions are: is this possible? Is it difficult? Where do I start
if I want to implement it?
----------------------------------------------------------------------
Blaazen · 2015-02-01 22:23
Maybe you should ask on FPC-Pascal or FPC-Devel mailing list, you have
better chance to meet freepascal developers there.
----------------------------------------------------------------------
engkin · 2015-02-02 00:28
Take a look here. It advices using fcl-passrc and the example
test_parser in packages\fcl-passrc\examples.
One more thing: WriteLn is not a real procedure call. The compiler
generates suitable set of calls based on the number and types of
parameters passed to WriteLn.
----------------------------------------------------------------------
JuhaManninen · 2015-02-02 06:19
Quote from: int-index on February 01, 2015, 10:44:45 pmI am developing
a translator from Pascal to Haskell
Heh, what will you do with Pascal variables and loops?
Anyway, good luck!
----------------------------------------------------------------------
Leledumbo · 2015-02-02 06:44
Quote from: int-index on February 01, 2015, 10:44:45 pmis this
possible?
certainly
Quote from: int-index on February 01, 2015, 10:44:45 pmIs it
difficult?
depending on your knowledge and skill
Quote from: int-index on February 01, 2015, 10:44:45 pmWhere do I
start if I want to implement it?
fpc -vp produces tree.log in a LISP-like
notation, though I'm afraid not enough for your approach for the
purpose. Using fcl-passrc classes and extending them with appropriate
backend for XML/Haskell (whatever you want) as engkin said will be a
better one.