Author Topic: BaCon  (Read 10292 times)

Pjot

  • Guest
BaCon
« on: September 08, 2010, 11:47:36 AM »
All,

There is also the BaCon project, which implements a 2nd generation BASIC for Unix environments and converts this to C code, which then is compilable by GCC, TCC or the Compaq C compiler (and maybe even more compilers). The translation is based on the idea of passing expressions as-they-are to the resulting C code, allowing the design of high-performance calculations. This concept also leads to speedy translations. The resulting binaries are extremely small, even for large programs using GTK (around 50 to 60 kByte). Also several interfaces to other libraries exist, like SQlite, nCurses, GMP, Glade and more!

Greetings
Peter
« Last Edit: September 08, 2010, 01:02:28 PM by Pjot »

E.K.Virtanen

  • Guest
Re: BaCon
« Reply #1 on: September 08, 2010, 11:49:17 AM »
Hi Pjot, and nice to see you onboard as well.

I am planning to build my next interpreter with your dialect. Would you like to check out my problem at http://www.allbasic.info/forum/index.php?topic=11.0 incase you could give me some ideas how to do it with BaCon directly  ::)

JRS

  • Guest
Re: BaCon
« Reply #2 on: September 08, 2010, 12:05:04 PM »
Thanks Peter for joining the AllBasic forum and giving us an update where things stand with your Basic translator. I moved your thread to the translator board as it was an intro and not GP.


Pjot

  • Guest
Re: BaCon
« Reply #3 on: September 08, 2010, 12:17:48 PM »
Hi John, I just saw your list of BASIC languages and BaCon was missing, so I thought I'ld mention it there... anyway nice to see it is the first post in this Translators forum  :)

Regards
Peter

JRS

  • Guest
Re: BaCon
« Reply #4 on: September 08, 2010, 12:28:29 PM »
I guess The Basics' Page missed it. I'll add it to the list. Can you send me a graphic to use and I'll point it to your project site.

Welcome aboard!

Pjot

  • Guest
Re: BaCon
« Reply #5 on: September 08, 2010, 12:45:03 PM »
E.K.,

It's the good old problem of line parsing...? Multiple statements on one line are separated by the colon symbol... Hmm... so first you always must make sure the colon symbols occuring in a line are not part of a string themselves. It is unavoidable to write a miniparser to replace non-embedded ':' symbols to some other value, for example NL (0x0A). This is what I do myself too in the BaCon version of BaCon.

Then I would use the SPLIT statement to dynamically separate the string into elements, each of which can be parsed individually.

Hope the below helps!

Peter

Code: [Select]
' The variable with the line of BASIC
line$ = "PRINT \"MYBASIC: parser\": FOR x = 1 TO 10: PRINT x: NEXT x: END"

' Some declarations
token$ = ""
escaped = 0
in_string = 0

' Step 1: make sure colon is translated to newline symbol
FOR x = 1 TO LEN(line$)
    SELECT MID$(line$, x, 1)
' Separator
CASE ":"
    IF ISFALSE(in_string) THEN
token$ = CONCAT$(token$, CHR$(10))
escaped = FALSE
    ELSE
token$ = CONCAT$(token$, ":")
    END IF
' Escape symbol
CASE CHR$(92)
    token$ = CONCAT$(token$, CHR$(92))
    IF ISFALSE(escaped) THEN
escaped = TRUE
    ELSE
escaped = FALSE
    END IF
' Quote symbol
CASE CHR$(34)
    token$ = CONCAT$(token$, CHR$(34))
    IF ISFALSE(escaped) THEN in_string = NOT(in_string)
    escaped = FALSE
DEFAULT
    token$ = CONCAT$(token$, MID$(line$, x, 1))
    escaped = FALSE
    END SELECT
NEXT

' Step 2: split into separate elements
SPLIT token$ BY CHR$(10) TO element$ SIZE dim

' Print results
FOR x = 0 TO dim-1
    PRINT CHOP$(element$[x])
NEXT


Pjot

  • Guest
Re: BaCon
« Reply #6 on: September 08, 2010, 12:55:54 PM »
John, I have sent a picture by mail. Thanks for adding BaCon to the list!

Peter

Pjot

  • Guest
Re: BaCon
« Reply #7 on: September 09, 2010, 09:31:55 AM »
Hi Aurel,

Of course! As BaCon passes expressions as-they-are to the C compiler, arrays are basically C arrays. This means that the notation with square brackets is maintained. Of course you need to declare an array first (this never is done implicitly).

Example:

Code: [Select]
OPTION BASE 1

DECLARE array[10] TYPE NUMBER

FOR x = 1 TO 10
    array[x] = 5*x
NEXT

You can find more information on arrays in the BaCon Manual.

Hope this helps,
Peter

Pjot

  • Guest
Re: BaCon
« Reply #8 on: September 09, 2010, 11:11:03 AM »
Well, as mentioned, arrays in BaCon are not 'implemented', but passed as-they-are to the C compiler.  :) So in fact, the C compiler does all the work for me. That's why it is mentioned in the manual that BaCon is a lazy converter: the parsing of expressions and assignments is left to the C compiler.

Therefore you'ld better ask: how does a C compiler implement arrays? That's a whole different ballgame which leads to a long technical story. There's a lot to find on this on the net.

But what BaCon does implement is the associative array. An associative array is an array where the index is defined by a string, instead of a number. BaCon uses a C implementation where the information is stored in an array of structs. However we need an array then, and that is what we want to implement, right?  ;)

So, for BaCon, it is all done by the C compiler...

Regards
Peter
« Last Edit: September 09, 2010, 01:14:18 PM by Pjot »

codeguy

  • Guest
Re: BaCon
« Reply #9 on: September 18, 2010, 10:05:21 PM »
arrays in qb64 and its emitted c code ARE supported. i will be a strong proponent of qb64 as it is the best of 2 worlds: basic's simplicity and c's speed and power. every compilation results in a file of corresponding c code. if you navigate to the folder it's in, you've got the exact c code used by gcc to compile qb64 source. we are still in need of an interpreter, so if you want to help and know something about interpreter design, any help would be appreciated. this will be a standalone interpreter and may one day be integrated into qb64 itself.

Pjot

  • Guest
Re: BaCon
« Reply #10 on: September 21, 2010, 12:06:20 AM »
Hi Codeguy,

So I downloaded the v0.91 package from qb64.net but it seems to be all Windows? Is there a Unix version? (I do not have Win32/Win64 platform at all...)

Also there are a lot if .cpp files, so to compile qb64 it seems we need a C++ compiler...?

Regards,
Peter

JRS

  • Guest
Re: BaCon
« Reply #11 on: September 21, 2010, 02:55:19 AM »
I would like to see both BaCon and QB64 only generate the needed run-time for the application written.

BCX does this and it's MUCH easier to work with at the C(++) level.

Other than that, it's nice to see traditional Basic reincarnating itself with updated interfaces and OS support.

Pjot

  • Guest
Re: BaCon
« Reply #12 on: September 21, 2010, 11:50:32 AM »
Quote
I would like to see both BaCon and QB64 only generate the needed run-time for the application written.

John what do you mean...? For any BaCon binary there is only dependency to libc, libm and libdl. It generates only one binary. So no overhead to other stuff like GTK, GMP, GL or other stuff, not even in case BaCon progams actually use these libraries.

Or do you mean something else....?

Regards
Peter

JRS

  • Guest
Re: BaCon
« Reply #13 on: September 21, 2010, 11:57:49 AM »
Quote
John what do you mean...?

Hello World

I'm talking about how BCX only generates the needed runtime functions based on the user coded application. Both BaCon and QB64 includes a full runtime with every compiled program.
« Last Edit: September 21, 2010, 12:00:05 PM by JRS »

E.K.Virtanen

  • Guest
Re: BaCon
« Reply #14 on: September 21, 2010, 01:42:35 PM »
hmm...BCX is pretty old? I think it was something like 1999 or so when BCX project was launched. I might remember wrong though.
I dont see any reason to compare such a project for young ones, such as QB64 or BaCon.

Also it is good to remember what are the goals of the project. QB64 is updated QB and for sure, galleon does not currently ponder too much about optimizing yet. BaCon is .bash script which converts basic code to C and then uses gcc to compile it. I would not compare BCX for it at all.