Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Conversion Utilities

by Yostsw (Novice)
on Apr 07, 2003 at 15:28 UTC ( [id://248638]=perlquestion: print w/replies, xml ) Need Help??

Yostsw has asked for the wisdom of the Perl Monks concerning the following question:

We have quite a bit of BASIC code(Basic2c specifically) currently in production. I need to convert this code to PERL. Unfortunately, there are about 25000 lines of Basic code(not counting the rermarks (-; ). I need to use some sort of utility to at least get 50-70% of the way there so this project can be cut down to a manageable size.

Are there any Basic->to->PERL conversion utilities out there - especially one that someone can recommend from experience?

Many thanks in advance,

Spencer

Replies are listed 'Best First'.
Re: Conversion Utilities
by krujos (Curate) on Apr 07, 2003 at 15:38 UTC
    You could try this which will run basic programs from the command line. The docs also advertise a basic2pl which will do what you need.
Re: Conversion Utilities
by ferrency (Deacon) on Apr 07, 2003 at 15:54 UTC
    You might want to check out the Inline::Basic module. It's probably no good long-term solution, but it might help ease the transition between old code and new with minimal downtime.

    A lot of the specifics of converting the actual code in question depend on the specific dialect of BASIC, the way the code is designed and implemented currently, and what language-specific or platform-dependant features it uses. In the end you're most likely going to have to do a lot of hand-tuning after any reasonable conversion script.

    Alan

Re: Conversion Utilities
by glwtta (Hermit) on Apr 07, 2003 at 16:19 UTC
    Yeah, but the functionality of 25,000 lines of BASIC can be done in what, about 7 lines of Perl? :)
      the functionality of 25,000 lines of BASIC can be done in what, about 7 lines of Perl?

      Depends on the dialect of BASIC and also on exactly what sort of stuff the code is doing. Some things (e.g., simple (non-regex) string manipulation) many dialects of BASIC are pretty good at, and you might find 25000 lines of BASIC coming to 20000 lines or so of Perl. On the other hand, arrays in BASIC are fairly primitive, to say nothing of more complex data structures, so if the problem that the code is solving maps well onto objects or hashes you'll see a much more substantial reduction. Some dialects of BASIC make good use of subroutines (e.g., QBasic); others (e.g., most line-number BASICs) don't. In the former case some stuff may translate fairly well. In the latter case, you're going to end up with some *really* messy Perl code if the translation isn't done by a human.


      for(unpack("C*",'GGGG?GGGG?O__\?WccW?{GCw?Wcc{?Wcc~?Wcc{?~cc' .'W?')){$j=$_-63;++$a;for$p(0..7){$h[$p][$a]=$j%2;$j/=2}}for$ p(0..7){for$a(1..45){$_=($h[$p-1][$a])?'#':' ';print}print$/}
Re: Conversion Utilities
by logan (Curate) on Apr 07, 2003 at 19:13 UTC
    While I suppose it's technically possible to translate Basic to perl, it's just not a good idea. Perl has optimizations that didn't exist back in the day, and data structures that probably weren't available for Basic. Finally, you probably have vastly more memory and CPU cycles available to you now than the original author did when the original code was written.

    In the Real World, it's rare to be able to re-write something from the ground up. What a great opportunity! When you finish, you'll be the company perl expert, with all the honor and respect that is your due.

    And yes, the Monastary will be here to answer the inevitable questions.

    -Logan
    "What do I want? I'm an American. I want more."

Re: Conversion Utilities
by zenn (Sexton) on Apr 08, 2003 at 19:15 UTC
    Perhaps the best way to do that is to build a pseudo compiler/decompiler. You would have to parse the Basic code building the tree. After that you would have to decompile that tree in Perl source. It is a hard project and perhaps will consume an man-time effort and surely a expertise in computer theory that will not payback. Besides it will probably generate a not optimized perl code, unless you spend another bucket of compiler optimization wizardry over it. The rewrite from scratch seems to be a better approach.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://248638]
Approved by broquaint
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found