Recent

Author Topic: REPL in free pascal - need info  (Read 2981 times)

Weiss

  • Full Member
  • ***
  • Posts: 232
REPL in free pascal - need info
« on: August 25, 2024, 07:16:38 am »
I am looking for information on how to implement repl in free pascal. I might need it, but even if I don’t I would like to play with it anyway. Google always gets confused and brings python and other interpreted languages. Someone somewhere must have done it in Pascal?

Thaddy

  • Hero Member
  • *****
  • Posts: 18915
  • Glad to be alive.
Re: REPL in free pascal - need info
« Reply #1 on: August 25, 2024, 10:48:54 am »
Well, It is actually a feature that is easier made available in interpreted languages, so Google is basically right.
It is all about the E in repl: that requires run-time evaluation. That does not mean it is impossible to implement it in Pascal, but then you need to use a Pascal interpreter. There are several of those, like Pascalscript in the standard distribution.
There are also some Eval() functions available for Pascal, but those are not full interpeters.
To summarize: REPL is an explicit feature for which interpreted languages are better suited. It is by its very nature also always very slow. So, yes, it can be done in Pascal, likely interpreted Pascal.
Pascalscript is used in the Lazarus ide and is readily available and capable to implement REPL.
It takes some work from your side to implement the interactive part of REPL, but not much and nothing fancy.
( meaning a beginner that knows about a button, memo's and edit's can implement it...)

[edit] pas2js may also be a good candidate if pascal syntax is required, as are the language bindings for Python, and the ECMA family of scripting languages, but these have different syntax.
I prefer Python bindings but that is a matter of taste.
« Last Edit: August 25, 2024, 11:12:26 am by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

Weiss

  • Full Member
  • ***
  • Posts: 232
Re: REPL in free pascal - need info
« Reply #2 on: August 26, 2024, 04:20:43 am »
... yes, it can be done in Pascal, likely interpreted Pascal.
Pascalscript is used in the Lazarus ide and is readily available and capable to implement REPL.
It takes some work from your side to implement the interactive part of REPL, but not much and nothing fancy.
( meaning a beginner that knows about a button, memo's and edit's can implement it...)

thanks Thaddy, this is what was looking for. I am that beginner, buttons and memos etc. PascalsScript might be just my playground for a while.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8562
Re: REPL in free pascal - need info
« Reply #3 on: August 26, 2024, 09:37:17 am »
There was, many years ago, something called Mystic Pascal which I believed offered a somewhat BASIC-like interactive "user experience". I believe it started off as a commercial product, but ended up being given away on magazine covers... DOS-only and even if one could find a binary I'd be surprised if the source has survived.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Weiss

  • Full Member
  • ***
  • Posts: 232
Re: REPL in free pascal - need info
« Reply #4 on: August 26, 2024, 07:44:06 pm »
I also found “writing interpreter in object pascal” by Herbert Sauro. He builds repl in Pascal for his computer language. Would be interesting to dig Mystic Pascal as well, I think it dates to early 80’s. There is a diskette for sale on ebay. Thank you for good pointers, fellas.

LV

  • Sr. Member
  • ****
  • Posts: 427
Re: REPL in free pascal - need info
« Reply #5 on: August 26, 2024, 08:21:33 pm »
Maybe a simple working example from MaXbox (Win or Linux) https://sourceforge.net/projects/maxbox/files/Lazarus/PASCALSCRIPT_LAZARUS.zip Download it and have a look!

LV

  • Sr. Member
  • ****
  • Posts: 427
Re: REPL in free pascal - need info
« Reply #6 on: August 26, 2024, 08:55:36 pm »
Maybe a simple working example from MaXbox

Sorry, I checked it out now and I had to tweak unit1pscript2.pas a bit.

Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. {$R *.lfm}
  4.  
  5.  //uses  uPSDisassembly;  
  6.  

Code: Pascal  [Select][+][-]
  1. procedure TpsForm1.btngetCompiledClick(Sender: TObject);
  2. var sdata: string;
  3. begin
  4.       {PSScript1.GetCompiled(sData);
  5.    // {if not} PSScript1.SetCompiled(sData);
  6.    if not IFPS3DataToText(sData,sData)
  7.      then memo1.lines.add('¡No puedo crear el desensamblado!')
  8.    else
  9.      synmemo1.Text:= sData; }
  10.   //aPSCE.SaveDissasembly(sData);
  11. end;
  12.  
  13.  

Now it compiles and runs. ;)
« Last Edit: August 26, 2024, 10:11:01 pm by LV »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8562
Re: REPL in free pascal - need info
« Reply #7 on: August 26, 2024, 09:25:37 pm »
I also found “writing interpreter in object pascal” by Herbert Sauro. He builds repl in Pascal for his computer language. Would be interesting to dig Mystic Pascal as well, I think it dates to early 80’s. There is a diskette for sale on ebay. Thank you for good pointers, fellas.

http://cd.textfiles.com/pcsig08/901_1000/DISK0965/

The readme is accessible, which implies that the others are as well. I think I've looked at those in the past, but couldn't really see what was special... but that might have been because I was used to the debugging which was largely pioneered by Logitech in the mid-80s and later refined by Delphi etc.

In any event, the Mystic Pascal facilities might be a good baseline to try to aim for.

Updated: xref to the thread containing this, which links to a Github project.

https://forum.lazarus.freepascal.org/index.php/topic,60239.msg450782.html#msg450782

MarkMLl
« Last Edit: August 26, 2024, 09:58:30 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018