Recent

Author Topic: Porting a Delphi Project  (Read 20898 times)

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Porting a Delphi Project
« Reply #30 on: August 29, 2018, 07:17:45 pm »
Thanks for the info!  :P
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Porting a Delphi Project
« Reply #31 on: August 30, 2018, 12:30:35 pm »
@Avra
Here's the new refactored version of my cross-platform goldengine translation.
- some speed-ups
- safer code
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Porting a Delphi Project
« Reply #32 on: August 31, 2018, 12:23:33 pm »
Thank you so much!  :D

I will take a look.  ::)
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Porting a Delphi Project
« Reply #33 on: August 31, 2018, 03:06:58 pm »
Unfortunatelly the problem is the same as with previos Lazarus version.  :(

I do not have a Delphi at the moment to test the original version.

It is pretty discouraging that pascal engine can't cope with code that is parsed fine on Gold Builder 5.20.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

simone

  • Hero Member
  • *****
  • Posts: 573
Re: Porting a Delphi Project
« Reply #34 on: August 31, 2018, 03:51:30 pm »
I started this thread two years ago and currently my interest in this topic is still very high. Thanks Thaddy!
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Porting a Delphi Project
« Reply #35 on: August 31, 2018, 04:07:49 pm »
For pascal itself, there is fcl-passrc.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Porting a Delphi Project
« Reply #36 on: August 31, 2018, 04:23:39 pm »
Unfortunatelly the problem is the same as with previos Lazarus version.  :(

I do not have a Delphi at the moment to test the original version.

It is pretty discouraging that pascal engine can't cope with code that is parsed fine on Gold Builder 5.20.
My download complains about unreachable Functioncall. see attached picture.

PS
  I downloaded the zip file and the command line file not the setup and I had to do a bit of creative file copying between the two to make it work.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Porting a Delphi Project
« Reply #37 on: August 31, 2018, 09:34:59 pm »
My download complains about unreachable Functioncall.
I have ignored that warning, but you might be on something with it since function calls are the ones who could not be processed with compiled grammar loaded into Lazarus Gold Engine. It looks like engine is more rigorous then Gold Test Window, since you can see from the screenshot that Gold Tester successfully parsed the code with given grammar.

For pascal itself, there is fcl-passrc.
This time I am not that much interested in parsing Pascal it self. I am just investigating how much effort would be to parse Pascal like FCL - an IEC 61131-7 fuzzy logic extension to ST (Structured Text) used for example in PLCs (programmable logic controllers) for industrial automation, or even games AI (with FCL compiler which generates source code as it's output). Since FCL function blocks are small, I do not need speed of a hand crafted or plex/pyacc parser - so Gold sounded pretty attractive.
https://en.wikipedia.org/wiki/Fuzzy_Control_Language

Here are some simple FCL examples:
Code: Pascal  [Select][+][-]
  1. function_block Test
  2.    var_input
  3.       Light : Real [lux];
  4.    end_var
  5.  
  6.    var_output
  7.       Switch : Nominal (On, Off);
  8.    end_var
  9.  
  10.    fuzzify Light
  11.       term Dark     := (  100 lux, 1)( 1000 lux, 0);
  12.       term Twilight := (  500 lux, 0)( 1000 lux, 1)(15000 lux, 1)(20000 lux, 0);
  13.       term Bright   := (10000 lux, 0)(20000 lux, 1);
  14.    end_fuzzify
  15.  
  16.    ruleblock Rules
  17.      if Light is Dark then Switch is On;
  18.      if Light is Bright then Switch is Off;
  19.    end_ruleblock
  20.  
  21. end_function_block
  22.  

Code: Pascal  [Select][+][-]
  1. FUNCTION_BLOCK
  2.   VAR_INPUT
  3.     Our_Health      REAL; (* RANGE(0 .. 100) *)
  4.     Enemy_Health    REAL; (* RANGE(0 .. 100) *)
  5.   END_VAR
  6.  
  7.   VAR_OUTPUT
  8.     Aggressiveness  REAL; (* RANGE(0 .. 4) *)
  9.   END_VAR
  10.  
  11.   FUZZIFY Our_Health
  12.     TERM Near_Death := (0, 0) (0, 1) (50, 0) ;
  13.     TERM Good := (14, 0) (50, 1) (83, 0) ;
  14.     TERM Excellent := (50, 0) (100, 1) (100, 0) ;
  15.   END_FUZZIFY
  16.  
  17.   FUZZIFY Enemy_Health
  18.     TERM Near_Death := (0, 0) (0, 1) (50, 0) ;
  19.     TERM Good := (14, 0) (50, 1) (83, 0) ;
  20.     TERM Excellent := (50, 0) (100, 1) (100, 0) ;
  21.   END_FUZZIFY
  22.  
  23.   FUZZIFY Aggressiveness
  24.     TERM Run_Away := 1 ;
  25.     TERM Fight_Defensively := 2 ;
  26.     TERM All_Out_Attack := 3 ;
  27.   END_FUZZIFY
  28.  
  29.   DEFUZZIFY valve
  30.     METHOD: MoM;
  31.   END_DEFUZZIFY
  32.  
  33.   RULEBLOCK first
  34.     AND:MIN;
  35.     ACCU:MAX;
  36.     RULE 0: IF (Our_Health IS Near_Death) AND (Enemy_Health IS Near_Death) THEN (Aggressiveness IS Fight_Defensively);
  37.     RULE 1: IF (Our_Health IS Near_Death) AND (Enemy_Health IS Good) THEN (Aggressiveness IS Run_Away);
  38.     RULE 2: IF (Our_Health IS Near_Death) AND (Enemy_Health IS Excellent) THEN (Aggressiveness IS Run_Away);
  39.     RULE 3: IF (Our_Health IS Good) AND (Enemy_Health IS Near_Death) THEN (Aggressiveness IS All_Out_Attack);
  40.     RULE 4: IF (Our_Health IS Good) AND (Enemy_Health IS Good) THEN (Aggressiveness IS Fight_Defensively);
  41.     RULE 5: IF (Our_Health IS Good) AND (Enemy_Health IS Excellent) THEN (Aggressiveness IS Fight_Defensively);
  42.     RULE 6: IF (Our_Health IS Excellent) AND (Enemy_Health IS Near_Death) THEN (Aggressiveness IS All_Out_Attack);
  43.     RULE 7: IF (Our_Health IS Excellent) AND (Enemy_Health IS Good) THEN (Aggressiveness IS All_Out_Attack);
  44.     RULE 8: IF (Our_Health IS Excellent) AND (Enemy_Health IS Excellent) THEN (Aggressiveness IS Fight_Defensively);
  45.   END_RULEBLOCK
  46. END_FUNCTION_BLOCK

Btw. I apologize everyone, since for successful parsing of test code you have to add one 'do' at the end of a 'for' loop line. I will edit my original message to correct just that.
« Last Edit: August 31, 2018, 10:04:20 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018