An idea for converting code - BASIC to C++/Arduino, with flowcharting

Hi,

I've been working on some ideas for helping developers switch from BASIC to target code - C/C++/Arduino (and others).

My demo application reverse engineers BASIC code and converts to the selected target code.

To make things simpler, the code is broken down into subroutines automatically and a flowchart is created for each routine.

This way users can either use the flowchart interface or the text editing interface in whichever language they like.

There are plenty of BASIC programmers out there who I reckon would find this a good way to switch to Arduino.

The application uses Gold Parser Builder to define the Source & Target languages http://goldparser.org/ so I don't need to re-code the whole application to include another language. It can currently process a couple of dialects of BASIC (my own which is similar to VB, and PBASIC e.g. Basic Stamp) and can handle a few dialects of C/C++/C#/Java/Arduino.

The IDE uses a database to track the list of available compilers, so users can compile an Arduino application, or they could create a simple C project and the IDE will fire up and link the correct set of files - it should be able to handle ChipKit, Maple - just update the local database.

Here are some videos I uploaded to demo this to a colleague in Singapore, in each case the source code is pasted into the editor and flowcharts/conversions are then done automatically there are more features than this but these are the ones that I think will interest Arduino users?

  1. Reverse engineering BASIC into 2 subroutines and generate flowchart(s)
    - YouTube

  2. Reverse Engineer PBASIC
    - YouTube

  3. Reverse Engineer BASIC and convert to C style
    - YouTube

  4. Reverse Engineer Arduino program, draw the flowcharts and convert to BASIC
    - YouTube

I'd be interested in hearing peoples views..

Thanks in advance
Michael

Looks really cool!

eried:
Looks really cool!

Thanks, would you like to try it? I could use some feedback from arduino users..

Sure :smiley:

You think with the parser you used for the code it is possible to update the old arduino libraries? http://blog.makezine.com/2011/12/01/arduino-1-0-is-out-heres-what-you-need-to-know/ looking at those rules? I am trying to add an automated installer (it is pretty complete now) but still missing the "old library" update procedures (for now I is just fairy simple regex replacements) but I think I need fancy stuff to understand if replacement is in comments, or anything the coder can do.

eried:
You think with the parser you used for the code it is possible to update the old arduino libraries? http://blog.makezine.com/2011/12/01/arduino-1-0-is-out-heres-what-you-need-to-know/ looking at those rules? I am trying to add an automated installer (it is pretty complete now) but still missing the "old library" update procedures (for now I is just fairy simple regex replacements) but I think I need fancy stuff to understand if replacement is in comments, or anything the coder can do.

I can parse for some of the rules for definate, I tried the 2 below and the parser could pick them up and at least give a report to the user that they need changing if some kind of tool was needed to do that.

The BYTE keyword
Serial.print(val, BYTE)
To:
Serial.write(val); //sends as char

Migrating Wire (I2C) statements
Wire.send()
To:
Wire.write()
And change:
Wire.receive()
To:
Wire.read()

I don't know about the problems caused by dervied classes, I would need to examine this e.g.

Return values from write() methods
Classes derived from Print must implement a write method to write data to the device that the class supports. The signature of the write method has changed from void to size_t to return the number of characters written. If you have a class derived from Print you need to modify the write method as follows and return the number of characters written (typically 1). Change:

  • void write*
  • To:*
  • size_t write*

Overall I think it's worth attempting something, the main problem is that I have not validated the Arduino/Wiring syntax completely, but then again doing something like this would go some way toward getting that validation completed.

Can you download Gold Parser Builder http://goldparser.org/builder/files/GOLD-Builder-5.2.0-Setup.zip
I can send a compiled grammer file for arduino etc that you can load into it and scan your library source file, from there you can see in a tree structure what is recognised and possible to trap in some kind of conversion tool?

and possible to trap in some kind of conversion tool?

You mean to compile the solution?
I want to build a dll with this routines so I can update them in the future. The basic structure I am using now (of course is extremelly primitive but it is just to split the Library Repair from the Manager in my Modded Arduino IDE):

I would suggest rather than homebrewing your own system, roll it into (or likely, fork off of) the QB64 project; it uses (IIRC) gcc as it's backend to compile to native.

The videos all seem to be private. I was interested in seeing them.