Recent

Author Topic: translator, from BASIC to PASCAL (source code translator)  (Read 8072 times)

juanirias

  • Full Member
  • ***
  • Posts: 100
translator, from BASIC to PASCAL (source code translator)
« on: August 16, 2021, 06:17:14 pm »
Hi Please need to compile the code attached, is taken from :

https://www.exmortis.narod.ru/src_translate_eng.html

« Last Edit: April 18, 2022, 05:02:07 am by juanirias »

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: translator, from BAS to PAS
« Reply #1 on: August 16, 2021, 06:28:41 pm »
Add {$mode tp} at the top of the file to make it compile.

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: translator, from BAS to PAS
« Reply #2 on: August 16, 2021, 06:59:37 pm »
Thanks, can see the comments? I have a lot of stranger symbols...

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: translator, from BAS to PAS
« Reply #3 on: August 16, 2021, 07:40:26 pm »
Open the file in Notepad++, in the statusbar you see that it detects the encoding of the file as OEM866. In Notepad++, select "Encoding" > "Convert to UTF8 without BOM", save. When you now open the file in Lazarus, the comments should be correct.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: translator, from BAS to PAS
« Reply #4 on: August 16, 2021, 07:58:32 pm »
Hi!

wp was faster but I've got a simple Lazarus solution:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var st : TStringList;
  3. begin
  4.    st := TStringList.create;
  5.    st.LoadFromFile('./CROSS.PAS');
  6.    st.text := CP866ToUTF8(st.text);
  7.    showMessage (st.text);
  8.    st.saveToFile('./CROSSutf8.pas');
  9.    st.free;
  10. end;
  11.  

Winni

PS.:
Code: Pascal  [Select][+][-]
  1. uses ...,LConvencoding;
« Last Edit: August 16, 2021, 08:21:25 pm by winni »

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: translator, from BAS to PAS
« Reply #5 on: August 16, 2021, 11:47:06 pm »
Open the file in Notepad++, in the statusbar you see that it detects the encoding of the file as OEM866. In Notepad++, select "Encoding" > "Convert to UTF8 without BOM", save. When you now open the file in Lazarus, the comments should be correct.


Could share the file, I'm under Linux, I cannot see anything!



winni

  • Hero Member
  • *****
  • Posts: 3197
Re: translator, from BAS to PAS
« Reply #6 on: August 17, 2021, 12:10:18 am »

Could share the file, I'm under Linux, I cannot see anything!

Use my shown solution.
No problems with Linux.

Winni

wp

  • Hero Member
  • *****
  • Posts: 11912
Re: translator, from BAS to PAS
« Reply #7 on: August 17, 2021, 12:34:07 am »
Once you know that the encoding of the file is OEM866, you can also load the file into the Lazarus IDE.
  • Right-click on the editor and select "File Settings" > "Encoding" > "cp866" > "Reopen with another encoding". This tells the IDE the correct file encoding - the file should be displayed correctly now.
  • However, since Lazarus normally works with UTF8 files you should convert the file to UTF8. Repeat "File Settings" > "Encoding", but now select the top item "UTF8" and click on "Change File" rather than "Reopen with another encoding"
Make a backup copy of the original file - it is very easy to select the wrong steps here.

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: translator, from BAS to PAS
« Reply #8 on: August 17, 2021, 05:07:50 pm »
Thanks!

I want to translate some old GW-BASIC source code, but cant with this....

regards

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: translator, from BAS to PAS
« Reply #9 on: August 17, 2021, 06:52:01 pm »
Memory tells me that gw basic was tokenized .


Right!

There was the  strange syntax in gwbasic to save as ASCII:

Code: Text  [Select][+][-]
  1. save  mybasic.bas,a
  2.  


No "Basic" option in the Code Menu of the Forum software .....


Winni

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: translator, from BAS to PAS
« Reply #10 on: August 17, 2021, 07:04:55 pm »
Dear all

Could you try to compile the source code *.pas

I have this errors:

bp.pas :

Code: Pascal  [Select][+][-]
  1. fpc "bp.pas" (in directory: /home/developer/wip/MetOrbDet/BasPas)
  2. Free Pascal Compiler version 3.2.0+dfsg-12 [2021/01/25] for x86_64
  3. Copyright (c) 1993-2020 by Florian Klaempfl and others
  4. Target OS: Linux for x86-64
  5. Compiling bp.pas
  6. bp.pas(102,17) Warning: Local variable "a" of a managed type does not seem to be initialized
  7. bp.pas(185,33) Warning: Local variable "dummy3" of a managed type does not seem to be initialized
  8. bp.pas(358,55) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  9. bp.pas(385,31) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  10. bp.pas(405,37) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  11. bp.pas(733,47) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  12. bp.pas(738,47) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  13. bp.pas(784,55) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  14. bp.pas(1083,36) Error: String types have to match exactly in $V+ mode
  15. bp.pas(1433) Fatal: There were 7 errors compiling module, stopping
  16. Fatal: Compilation aborted
  17. Error: /usr/bin/ppcx64 returned an error exitcode
  18. Compilation failed.
  19.  

rbp.pas


Code: Pascal  [Select][+][-]
  1. fpc "rbp.pas" (in directory: /home/developer/wip/MetOrbDet/BasPas)
  2. Free Pascal Compiler version 3.2.0+dfsg-12 [2021/01/25] for x86_64
  3. Copyright (c) 1993-2020 by Florian Klaempfl and others
  4. Target OS: Linux for x86-64
  5. Compiling rbp.pas
  6. rbp.pas(93,40) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  7. rbp.pas(132) Fatal: There were 1 errors compiling module, stopping
  8. Fatal: Compilation aborted
  9. Error: /usr/bin/ppcx64 returned an error exitcode
  10. Compilation failed.
  11.  

thanks!

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: translator, from BAS to PAS
« Reply #11 on: August 17, 2021, 07:25:58 pm »
Hi!

Turbo mode is not sufficent.
You also have to activate  the shortstrings.

Insert:

Code: Pascal  [Select][+][-]
  1. Program cross;
  2.  
  3. {$mode tp}
  4. {$H-}  
  5. ...
  6. ...
  7.  

Then everything compiles fine.

Background:
The source is often looking for myString[0].
This is the length byte with ShortStrings (Turbo days )

But this is not allowed with AnsiStrings.

Winni



juanirias

  • Full Member
  • ***
  • Posts: 100
Re: translator, from BAS to PAS
« Reply #12 on: August 17, 2021, 07:30:50 pm »
Please review the new attachment

regards, Juan


Dear all

Could you try to compile the source code *.pas

I have this errors:

bp.pas :

Code: Pascal  [Select][+][-]
  1. fpc "bp.pas" (in directory: /home/developer/wip/MetOrbDet/BasPas)
  2. Free Pascal Compiler version 3.2.0+dfsg-12 [2021/01/25] for x86_64
  3. Copyright (c) 1993-2020 by Florian Klaempfl and others
  4. Target OS: Linux for x86-64
  5. Compiling bp.pas
  6. bp.pas(102,17) Warning: Local variable "a" of a managed type does not seem to be initialized
  7. bp.pas(185,33) Warning: Local variable "dummy3" of a managed type does not seem to be initialized
  8. bp.pas(358,55) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  9. bp.pas(385,31) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  10. bp.pas(405,37) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  11. bp.pas(733,47) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  12. bp.pas(738,47) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  13. bp.pas(784,55) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  14. bp.pas(1083,36) Error: String types have to match exactly in $V+ mode
  15. bp.pas(1433) Fatal: There were 7 errors compiling module, stopping
  16. Fatal: Compilation aborted
  17. Error: /usr/bin/ppcx64 returned an error exitcode
  18. Compilation failed.
  19.  

rbp.pas


Code: Pascal  [Select][+][-]
  1. fpc "rbp.pas" (in directory: /home/developer/wip/MetOrbDet/BasPas)
  2. Free Pascal Compiler version 3.2.0+dfsg-12 [2021/01/25] for x86_64
  3. Copyright (c) 1993-2020 by Florian Klaempfl and others
  4. Target OS: Linux for x86-64
  5. Compiling rbp.pas
  6. rbp.pas(93,40) Error: Call by var for arg no. 1 has to match exactly: Got "AnsiString" expected "ShortString"
  7. rbp.pas(132) Fatal: There were 1 errors compiling module, stopping
  8. Fatal: Compilation aborted
  9. Error: /usr/bin/ppcx64 returned an error exitcode
  10. Compilation failed.
  11.  

thanks!
« Last Edit: August 17, 2021, 07:38:56 pm by juanirias »

juanirias

  • Full Member
  • ***
  • Posts: 100
Re: translator, from BAS to PAS
« Reply #13 on: August 18, 2021, 06:24:11 pm »
I cant compile ...

Help please  ;)

« Last Edit: August 18, 2021, 07:16:21 pm by juanirias »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: translator, from BAS to PAS
« Reply #14 on: August 18, 2021, 06:37:32 pm »
I cant compile ...

I also cant compile. The compiler does it!!!

Show us the error message. And get used to it!

Winni

 

TinyPortal © 2005-2018