BASIC to C Translator interest

Go To Last Post
35 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Being an avid fan of BCX (The BASIC to C translator by Kevin Diggins) I was wondering if there would be any interest in something like this for AVRs?
It can be useful to help teach C as well.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not even a nibble here :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Digging in my heals and staying with BASCOM...

Interestng product, however.

If I was to switch to C I'd probably just re-write my stuff, rather than trust another program to try and make sense of my code.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am sticking to Bascom too: tried to learn C, but I seem to be incompatible. Genetic or age .... or both :lol: And use Assembly for the speedy parts, mostly interruptroutines.
A translator from Bascom to C ? Brrrr .... nightmare visions

Nard

PS JC, if you ARE compatible with C, I'd recommend to learn it. I wish I had ..... sniff

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had a C book, once... I don't even SEE it on my bookcase now. IIRC it was a small paperback, blue cover, white title, in case that rings any bells.

My dusty shelf also has 8086 assembler, fortran, and a couple of Basic books. I took a Learn Java in 21 days type book on vacation once, I could never even get the IDE to work on my lap top, ending my investigation into Java.

Of course if a Super Freak can learn to use a PIC perhaps there is still hope I can learn C...

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I had a C book, once... I don't even SEE it on my bookcase now. IIRC it was a small paperback, blue cover, white title, in case that rings any bells.

The colours the other way around, blue title on white cover , and it's probably K&R. If so, then don't let it go..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
A translator from Bascom to C ? Brrrr .... nightmare visions

Do you have a small sample program? I could do a translation and see what we get :roll:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CirMicro wrote:
Not even a nibble here :)
Not from me, I was glad to leave BASIC behind after my TRS-80 Model I days.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When Voyager had to pass through The Void on their journey from the Delta quadrant to the Alpha quadrant ... that is where this planet resides .... I got that awkward feeling .... all that emptyness ... no stars .... no place to go to (pun intended!) ...

As attachment a Bascom-source: both as RTF (for readability ... it is as I see it in the IDE), and as plain text, for the translator. Let's see .....

Nard

Attachment(s): 

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nard wrote:

As attachment a Bascom-source: both as RTF (for readability ... it is as I see it in the IDE), and as plain text, for the translator. Let's see .....

I'll probably have to explain some of the BASCOM keywords to BCX. I'll let you know what I come up with tomorrow.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In BASCOM, show us how this equation is compiled

A = B + C + D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Picky, picky, picky...

To a Bascomer that would be a no-brainer, split it into two lines as Bascom doesn't parse and process multi-component math within a single line.

I suspect there are idiosyncrasies within most/any/all languages. There are certainly many Basic variants that would accept the above line, (ZBasic on the AVR, for example). One doesn't have to read many Freaks threads to know that there are also differences between the various C compilers. :wink:

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

To a Bascomer that would be a no-brainer, split it into two lines as Bascom doesn't parse and process multi-component math within a single line.

Of course if you were translating it to C you wouldn't have that limitation anyway.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I remember BASCOM having atrocious code generation for array access. As far as I can remember (several years ago now), most of BASCOM's commands were implemented as honking great big libraries which were compiled in and called by the main code, rather than the C compiler method of inlining small amounts of code. It also had huge FLASH consumption for things like string concatenation, because its so easy to do without thinking of the process that needs to be executed in order to acomplish it.

Nard: One day when I'm in the area while travelling the world I'll stop in and teach you C. It's really quite easy, as this fragment from my latest project shows:

static void SideShow_DeleteApplication(SideShow_PacketHeader_t* PacketHeader)
{
	GUID_t ApplicationGUID;
	SideShow_Application_t* AppToDelete;
	bool   FoundApp = false;
	
	Endpoint_Read_Stream_LE(&ApplicationGUID, sizeof(GUID_t));	
	Endpoint_ClearCurrentBank();

	do
	{
		AppToDelete = SideShow_GetApplicationFromGUID(&ApplicationGUID);

		if (AppToDelete != NULL)
		{
			AppToDelete->InUse = false;
			FoundApp = true;
		}
	} while (AppToDelete != NULL);

	for (int ContentItem = 0; ContentItem < MAX_CONTENT; ContentItem++)
	{
		if (memcmp(&Content[ContentItem].ApplicationID, &ApplicationGUID, sizeof(GUID_t)))
		  Content[ContentItem].InUse = false;
	}  

	if (!(FoundApp))
	  PacketHeader->Type.NAK = true;

	PacketHeader->Length = sizeof(SideShow_PacketHeader_t);

	Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM);
	Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t));
	Endpoint_ClearCurrentBank();
}

:lol:

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And then in the afternoon, you can drink beer! :mrgreen:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

:) I love you guys.

I think all that needed to be said has been said about Bascom. I don't feel the urge to switch to C, nor do I feel I have to prove something. If Bascom were a dog, some will consider it to be a garbage-breed, but to me it's a pedigree dog.

Nard

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it me but exactly what point is there in a BASIC->C converter anyway? If BASCOM does a fair job of BASIC->binary then what's gained by BASIC->C->binary ?

Cliff

(in fact that's actually BASIC->C->Asm->binary)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nard,

Just curious why "char" is defined as a 1 byte string instead of just a byte. I'm also curious as to how well BASCOM optimizes that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Personally, I always thought that 'unsigned char' was the weirdest thing about C.

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Char is in Bascom not a reserved name: it's the name I gave that variable. Could have called it "sel_char" or "Char_of_interest" or so ...

Nard

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Plons wrote:
Char is in Bascom not a reserved name: it's the name I gave that variable. Could have called it "sel_char" or "Char_of_interest" or so ...

Nard

I realize that, I was just curious why you wouldn't have declared it as byte instead of a string since it is only a 1 character string?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, some sort of BASIC > C translation is definitely possible. The "Native Mode" ZBasic compiler does it. I do not know the details of how that is done because it occurs in the background and the GCC C intermediate code is not saved. You go from BASIC source code to a downloadable (ZBasic hardware specific) code. But there IS a C intermediate and you can write your own C modules to include in the project.

If you are looking for a nice multitasking system that allows a composite of Basic and C source code, then this might be for you.

-Tony

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Cirmicro: Ah, I see. The use of a function like A$=Mid$(The_input$,4,5) requires that A is a string variable. Destinationtype must be the same as sourcetype.

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Plons wrote:
@Cirmicro: Ah, I see. The use of a function like A$=Mid$(The_input$,4,5) requires that A is a string variable. Destination type must be the same as sourcetype.

I See. Will BASCOM accept it in the form of A = ASC(Mid$(The_input$,4,1)) ?

Just wondering because one of the optimizations that the translator can make is with constructs such as:

 A = ASC(Mid$(The_input$,4,1)) 

 A = The_input[4-1];
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd have to try that .... never used it that way in Bascom. But I did things like that in other (MS) Basic. I'm talking 6502 Ohio Scientific Challlenger P2, 30 years ago.

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
'Plons, September 17, 2008

'Some string-thingies,

'CirMicro https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=68929&start=20


$regfile = Attiny2313.dat
$baud = 9600
$crystal = 13500000                                         ' 13.5 MHz Xtal

$hwstack = 32
$swstack = 32
$framesize = 16



Dim The_input_str As String * 10
Dim A_str As String * 1
Dim A As Byte


Do

   Input The_input_str Noecho
   A_str = Mid(the_input_str , 5 , 1)
   Print "A_str = " ; A_str

'   This line generates a compile error: A = Asc(mid(the_input_str , 5 , 1))
'   ... and has to be split
   A_str = Mid(the_input_str , 5 , 1)
   A = Asc(a_str)

   Print "A = " ; A

Loop

'Result on terminal:
' A_str = E
' A = 69

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've thought about dabbling with this some more. One thing that had me wondering though is if we make to allow BASCOM syntax is there any copyright stuff we need to be concerned about? I was wondering because I know the developer of FASTAVR mentioned something of being accused of mimicking the syntax at one time. As always, I'd like to keep it as free good clean fun.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Personally, I always thought that 'void (*fp)(int);' was the weirdest thing about C.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is "set" and "reset" in BASCOM suppose to be the same as:

variable.bit = 1
variable.bit = 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a small sample. If anyone sees something that doesn't look right let me know.

Name$ = "Mike"

   PORTB.2 = 1
   PORTA.5 = 0

   IF PINC.3 = 1 THEN PRINT "Hello " + Name$

   IF PINC.3 = 0 THEN PRINT "GoodBye"

Translates to:

      strcpy(Name,"Mike");
      PORTB |= (1 << 2);
      PORTA &= ~(1 << 5);
      if(PINC & (1 << 3))
        {
          printf("#s#s\n","Hello ",Name);
        }
      if(!( PINC & (1 << 3)))
        {
          printf("#s\n","GoodBye");
        }
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mike, I don't know how you're going about this, but if I were doing it I'd start out by writing a BASIC parser without too much regard to how I was going to use it. When it was all working and could recognize the complete syntax of the version of BASIC I was interested in, then I'd start working on the code generator, whether that be to assembly language, C, FORTH, or whatever.

The same front end (parser) can drive an interpreter, a true compiler, or whatever else you might come up with.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Chuck, The parser is actually already written for Quickbasic/VisualBasic like syntax. It's just a matter of molding it more for an embedded environment. I would consider ASM, but C is the primary objective here to act more as an application wizard and educational tool. I know it leans on a lot of egos but you can't please everyone :)

Thanks,
Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It took TWO crashes of OpenOffice writer to answer ....
(FYI, I reported to flaw)

'July 4, 2010

'For CirMicro's experiment; comes from Theremin1


'Buttons
Button0 Alias Pinc.5
Button1 Alias etc

'Signals
High_pitch Alias Portb.1



'CirMicro, this is how I use Set and Reset
If Button0 = 0 Then
   Reset High_pitch
Else
   Set High_pitch
End If

'but this would work fine too
If Button0 = 0 Then
   High_pitch = 0
Else
   High_pitch = 1
End If

You can download Bascom Trial version at mcselec.com and use the Help-file that comes with it.

Nard

Attachment(s): 

A GIF is worth a thousend words   They are called Rosa, Sylvia, Tricia, and Ulyana. You can find them https://www.linuxmint.com/

Dragon broken ? http://aplomb.nl/TechStuff/Dragon/Dragon.html for how-to-fix tips

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Nard