Lazarus

Free Pascal => Beginners => Topic started by: Weiss on August 25, 2024, 07:16:38 am

Title: REPL in free pascal - need info
Post by: Weiss 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?
Title: Re: REPL in free pascal - need info
Post by: Thaddy 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.
Title: Re: REPL in free pascal - need info
Post by: Weiss 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.
Title: Re: REPL in free pascal - need info
Post by: MarkMLl 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
Title: Re: REPL in free pascal - need info
Post by: Weiss 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.
Title: Re: REPL in free pascal - need info
Post by: LV 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!
Title: Re: REPL in free pascal - need info
Post by: LV 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. ;)
Title: Re: REPL in free pascal - need info
Post by: MarkMLl 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
TinyPortal © 2005-2018