Author Topic: C to BASIC Converter?  (Read 132 times)

RChadwick

  • Newbie
  • *
  • Posts: 1
    • View Profile
C to BASIC Converter?
« on: April 04, 2021, 06:04:01 PM »
Ideally, I'd LOVE to see an exact opposite of BCX, where you could take C code, convert to BASIC, edit in BASIC, then convert back to C. I'm guessing that doesn't exist. Is there anything that can translate C to something like BASIC? I'm having problems understanding existing C code, and reading BASIC is a whole lot easier for me.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
Re: C to BASIC Converter?
« Reply #1 on: April 04, 2021, 07:13:17 PM »
Out of curiosity, how many "C" files do you need to convert to BASIC?

You will have the most luck finding VB <-> C# converters, like this one:

https://vbconversions.com/

Obviously, C# is not C/C++ and VB.Net is not standard BASIC but they are close
enough for translating small blocks of code that contain mostly standard keywords.

Alternatively, you could start with small blocks of BASIC, run them through BCX and
examine the resulting "C" file, in order that you might learn to recognize the similarities
between the two languages more easily.   For example:

Code: [Select]

FUNCTION Add_Two ( A AS INT, B AS INT ) AS INTEGER
  FUNCTION = A + B
END FUNCTION

PRINT Add_Two ( 4, 5 )      ' Display the number "9"

PAUSE



Code: [Select]
// *************************************************
//            User's Subs and Functions
// *************************************************

int Add_Two (int A,int B)
{
  return A+B;
}

// *************************************************
//                  Main Program
// *************************************************

  int main(int argc, char *argv[])
{
  printf("% d\n",(int)Add_Two(4,5));
  Pause();

  return EXIT_SUCCESS;   // End of main program
}


« Last Edit: April 04, 2021, 07:35:05 PM by MrBcx »

psbrsneiman

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: C to BASIC Converter?
« Reply #2 on: April 09, 2021, 11:14:06 AM »
Another option

Just add
$CCODE
to the beginning and end of the file, and in the middle you could write pure c, and its still a valid BCX application.

When you want to add some logic in the middle using basic, just escape out with $CCODE, and write your few lines, then $CCODE agin to continue C mode.
You can use all existing c variables and functions from BASIC

As well you could call from c function you make in BASIC, but you must study first the BCX output to understand when you will need to free memory yourself.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
Re: C to BASIC Converter?
« Reply #3 on: April 09, 2021, 12:45:18 PM »
Another option

Just add
$CCODE
to the beginning and end of the file, and in the middle you could write pure c, and its still a valid BCX application.

When you want to add some logic in the middle using basic, just escape out with $CCODE, and write your few lines, then $CCODE agin to continue C mode.
You can use all existing c variables and functions from BASIC

As well you could call from c function you make in BASIC, but you must study first the BCX output to understand when you will need to free memory yourself.

That's a very good suggestion.  The following link will take you to a download that
clearly demonstrates the power of the $CCODE wrap.

https://bcxbasiccoders.com/smf/index.php?topic=30.0

Custctrl.Inc contains the original hyperlink custom control, coded in plain "C".

Hyperlink_Demo.Bas
will $INCLUDE CustCtrl.inc, as if it were a BASIC file.

GSAC3

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: C to BASIC Converter?
« Reply #4 on: April 09, 2021, 04:33:29 PM »
From my experience, one of the best ways to learn basic C (i.e. basic spelled with a lower case b) is to examine the C code produced by BCX from BCX-coded programs.  Doing so will help a lot to be able to incorporate pure  C code into BCX programs using the in-line and block coding facilities of BCX.  The trick is usually making sure the interfaces between the BCX syntax and the C-coded syntax are consistent and compatible. Another common problem encountered when inserting C code from an external source is the possibility of duplicate and or conflicting variable or constant names or definitions which can be caught by a good text editor.

jbk

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: C to BASIC Converter?
« Reply #5 on: April 11, 2021, 06:21:24 AM »
thank you MrBcx for the interesting link  :)

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 786
    • View Profile
Re: C to BASIC Converter?
« Reply #6 on: April 11, 2021, 08:44:49 AM »
thank you MrBcx for the interesting link  :)

Glad to help ... if ever you have questions or get stuck, just ask.