Convert Pascal to C#

Question

Wednesday, December 14, 2016 10:44 PM

How to convert this Pascal source code to C# ?

http://pastebin.com/AR390Am2

All replies (6)

Wednesday, December 14, 2016 11:11 PM

Have you tried any converters?

https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=pascel%20to%20c%23

More likely even if you find one you will need to do some tweaks after the conversion, especially with that much code. 

Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
VB Forums - moderator


Wednesday, December 14, 2016 11:25 PM | 1 vote

Does Pascal still exist? I haven't seen any Pascal code for more that 30 years.

Okay, I realise that doesn't help. Sorry.


Thursday, December 15, 2016 3:09 PM | 1 vote

"Does Pascal still exist? I haven't seen any Pascal code for more that 30 years."

Are you kidding?  It was one of the first 7 languages that targeted the CLR when .NET was first released along with Python and COBOL.

"How to convert this Pascal source code to C# ?"

You'll need to do this by hand probably. Pascal tended to rely on third-party modules that won't necessarily port. If the app was a console-based app then most of the code will convert almost directly. There are only a couple of language features in Pascal that won't directly convert (i.e. with statement and tagged records). But the rest of the code should convert pretty easily.

Michael Taylor
http://www.michaeltaylorp3.net


Thursday, December 15, 2016 10:08 PM

I wasn't kidding. I had to use it during first year in college, and haven't touched it since. The fact that it's in the same category as COBOL is unsurprising, because I haven't seen that since final year in college.


Thursday, December 15, 2016 11:24 PM

Inno Setup which is widely used Windows installer uses Pascal as its scripting language.  I've used it numerous times in the last few years.


Sunday, March 19, 2017 3:01 AM

I had the same question recently and checked out all the free converters.  Few are currently maintained.  I did find a for-cost [but economical] service at mpsinc.com .  But my problem may be simpler than warrenting a translation service.  Instead, I wrote a series of sed scripts and bundled in a single shell script file.  My "translator" runs on macOS, but could easily be adapted to any sed interpreter.  ( Free for the taking at: http://wonus.com/ox2cs/ ) .

My simple series of sed scripts outperformed every free offering that I could find.  But my Pascal sources were of the RemObjects Oxygene dialect [very similar to Delphi-Prism, not ordinary Embarcadero Delphi).  For instance, Oxygene replaces function & procedure keywords with method.  Since I only have about 4000 lines of Pascal code, I tailored my sed scripts for handle my coding conventions, and these are hard coded into the sed semantics.  Even still, some of the tedious operations can be handled: like method signatures, for loops, assignments, begin, end, and few other constructs.  My translator focuses on fixing the easy but tedious errors.  The remaining compile errors could easily be spotted and fixed.  A brief sample is below:

PASCAL:

type AVBook = public record

public

    writ: Array of AVWrittenEx;   // AVOPosition in C++

    name: String;

    abr: String;

    alt: String;

    abrMin:  UInt16;

    altMin:  UInt16;

    chapterCnt: UInt16;

    chapter: Array [1..] of AVChapter;

    bits: UInt64;

    hits: Array[0..SEARCHBIT_ARRAY_SIZE-1] of UInt16;

    matches: UInt16;

    wordCnt: UInt16;

    end;

CS:

public struct AVBook

{

//public//

    AVWrittenEx[] writ; // array of AVWrittenEx

    string name;

    string abr;

    string alt;

    UInt16  abrMin;

    UInt16  altMin;

    UInt16 chapterCnt;

    AVChapter[] chapter; // array [1..] of AVChapter

    UInt64 bits;

    UInt16[] hits; // array[0..SEARCHBIT_ARRAY_SIZE-1] of UInt16

    UInt16 matches;

    UInt16 wordCnt;

        }

For a large translation effort, you would be advised to tune the sed scripts for your own coding conventions, but I was pleasantly surprised that a few hours of sed scripting could dramatically simplify translating Pascal into CS.**
**