Convert Basic to C

BASIC TO C TRANSLATOR

BCX is a fast and highly efficient BASIC to C Code Translator. It has been around for more than
a decade and it can turn your Slow BASIC Code to fast and powerful C Language Code. The Code
produced by BCX works on multiple Compilers like: MS C++, LCC, MinGW and countless others.s
And, a noteworthy point for BASIC programmers using BCX is that BCX like C is case-sensetive
 which means 'A' and 'a' are different.

Our first simple BASIC FILE Conversion Callenge for BCX is a simple BASIC Command to print an
output to the Console Screen. The Code in our BASIC File (HELLO.BAS) is:

PRINT "Hello World!"
Calling BCX from Command Line
The Output File from BCX (HELLO.C) SourceFile looks something like this:

// *************************************************************
//   Created with BCX -- The BASIC To C Translator (ver 5.12-08.08.22)
//   BCX (c) 1999 - 2008 by Kevin Diggins
// *************************************************************
//     Translated for compiling with a C Compiler
// *************************************************************

// % REMOVED A LIST OF% Win32 Header File %s%
#include

// % REMOVED A LIST OF% COMPILER DEFINITIONS
int main(int argc, char *argv[])
{
printf("%s\n","Hello World!");
  return 0;   //  End of main program
}

Actually BCX translated a single Line Code to 146 Lines of C Code which at the first look, doesnot sound impressive.

The rest of the C Code (*removed* in this post) is for the Compiler Definitions, the headers for the declarations of the Win32 functions (not used here). They are written no matter what you write in the BAS SourceFile because they are the Code inserted  by default by the BCX Translator. They are in this translation useless (for our current need of printing 'Hello World!') because we havenot used any Win32 functions. They will be useful when we utitlize the system resources (the functions provided by the Microsoft System Libraries - APIs).

Lets analyze the power and simplicity of BCX with our new Conversion Challenge. This time, we are going to put a conditional statement (if-elseif-else-end if) along with a For-Loop. The Code is:

Dim i

For i = 1 to 5
   IF i = 1 THEN
        PRINT "I IS 1"
    ELSEIF i = 2 THEN
        PRINT "I IS 2"
    ELSEIF i = 3 THEN
        PRINT "I IS 3"
    ELSEIF i = 4 THEN
       PRINT "I IS 4"
    ELSE
        PRINT "I IS 5"
NEXT

The stripped down Code produced by BCX is :

#include

static int     i;

int main(int argc, char *argv[])
{
  for(i=1; i<=5; i+=1)
    {
      if(i==1)
        {
          printf("%s\n","I IS 1");
        }
      else if(i==2)
        {
          printf("%s\n","I IS 2");
        }
      else if(i==3)
        {
          printf("%s\n","I IS 3");
        }
      else if(i==4)
        {
          printf("%s\n","I IS 4");
        }
      else
        {
          printf("%s\n","I IS 5");
        }
    return 0;   //  End of main program
  }

Thus you can use BCX for converting your slow BASIC Code to fast and efficient C Code. You can then compile the C Sourcefile with any of your desired C Compiler.

Found this post useful ? If so, Click +1 and RECOMMEND THIS SITE on Google

No comments:

Post a Comment