FreeBASIC version 0.0

For other topics related to the FreeBASIC project or its community.
Site Admin
Posts: 3799
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il

FreeBASIC version 0.0

Postby v1ctor » Jul 26, 2009 15:57

Hi, guys, long time since i posted something new (yeap, i still alive :).

Actually this won't be anything new. I got a email from Yahoo - Geocities (RIP) saying they are going to remove my personal site (that never had anything other than a "In construction!" sign) and that i had to copy any important file stored there.

For my surprise, i found a rar archive with the FB sources, stored for backup purposes (there was no version control or whatever being used at that time). This version needs VBDOS to be built, because FB couldn't even self-compile - nor with -lang qb it could now, unfortunately, ENUM is disallowed.

So, for entertaining, educational (right..) and nostalgic reasons, here is it:

FreeBASIC v0.0

Don't try to do anything complex with it (like writing a self-hosting compiler using it, heh).

Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA

Postby vdecampo » Jul 26, 2009 17:23

Hi v1ctor! Nice to hear from you whether it's something new or old. For me it is a moral booster for the FB community.

Anyways, thanks for posting this. I am desperately trying to wrap my mind around building lexer/parser/compiler stuff because I want to eventually take a shot at my own compiler. Your code provides some great insight. I wish we had a set of tutorials like Crenshaw (or better) to walk through creating a basic compiler, in FB of course! :)

Hope all is well with you.

Posts: 1554
Joined: Jun 21, 2005 19:04

Postby angros47 » Jul 26, 2009 19:16

Hi V1c! And thanks for your work.

Well, you are not the only one to remove your basic compiler from geocities...

Ultrabasic compiler (I tried to continue the abandoned work of Gabriel Fernandez) were on, now I made a backup on

I discontinued it when FB was born, because FB was much better.
Posts: 2391
Joined: May 27, 2005 4:59

Postby Dr_D » Jul 26, 2009 21:29

Site Admin
Posts: 6176
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Aug 08, 2009 9:57

Now you can compile it in recent versions of FB, without the makefile.

I wrote a program that makes various minor hackish changes to the code, and compiles the result directly using fbc -lang fblite.

I haven't really tested the resulting exe, but it at least shows the help screen when run without params.

Code: Select all

#include ""
const FBC0DIR = "./src/compiler"
const FBC = "fbc"

function replace( byref s as string, byref s1 as string, byref s2 as string ) as string
    dim as integer i = 1
    dim as string t = s
        i = instr(i, t, s1)
        if i = 0 then return t
        t = left(t, i-1) & s2 & mid(t, i + len(s1))
        i += len(s2)
end function

sub fixfile( byref fn as string )
    dim as string f, b
    dim as integer i, i2, i3, i4
    if fileexists(fn & ".bak") then kill fn else name fn as fn & ".bak"

    open fn & ".bak" for binary as #1
        f = space(lof(1))
        get #1, 1, f
    close #1

    '' remove periods from consts/enums
    i = 1
        i2 = instr(i, f, "FB.")
        i3 = instr(i, f, "IR.")
        i4 = instr(i, f, "EMIT.")
        i = i2
        if i = 0 or (i > i3 and i3 > 0) then i = i3
        if i = 0 or (i > i4 and i4 > 0) then i = i4
        if i = 0 then exit do
        i2 = instr(i, f, ".")
        i3 = i2+1
        while mid(f, i3, 1) <> "."
            b = mid(f, i3, 1)
            if ucase(b) = lcase(b) then if b <> "_" then i = i3: continue do
            i3 += 1
        i4 = i3+1
        while mid(f, i4, 1) <> "."
            b = mid(f, i4, 1)
            if ucase(b) = lcase(b) then if b <> "_" then i4 = 0: exit while
            i4 += 1
        mid(f, i2, 1) = "_"
        mid(f, i3, 1) = "_"
        i = i3+1
        if i4 >= 1 then mid(f, i4, 1) = "_": i = i4+1

    '' rename variable 'class'
    f = replace(f, "class", "class_")
    '' couple of duplicate '+'s in string concatenation
    f = replace(f, "+  +", "+")
    f = replace(f, "+ +", "+")
    '' peek problem...
    f = replace(f, "peek( varptr( ctx.tbuff ) + ctx.tbuffptr )", "ctx.tbuff[ ctx.tbuffptr ]")
    '' exit sub from function
    i = 1
        i = instr(i + 1, f, "exit function")
        if i = 0 then exit do
        if instrrev(lcase(f), !"\nsub ", i) > instrrev(lcase(f), !"\nfunction ", i) then
            f = left(f, i-1) & "exit sub" & mid(f, i + len("exit function"))
        end if

    '' exit function from sub
    i = 1
        i = instr(i + 1, f, "exit sub")
        if i = 0 then exit do
        if instrrev(lcase(f), !"\nfunction ", i) > instrrev(lcase(f), !"\nsub ", i) then
            f = left(f, i-1) & "exit function" & mid(f, i + len("exit sub"))
        end if

    open fn for binary as #2
        put #2, 1, f
    close #2
end sub

dim d as string

chdir FBC0DIR

d = dir( "*.bas" )
do while len(d)
    print d
    fixfile( d )
    d = dir()

chdir "inc"

d = dir( "*.bi" )
do while len(d)
    print d
    fixfile( d )
    d = dir()

chdir ".."

shell FBC & " -lang fblite -v -e -x ../../fbcv0.exe " _
    "fbc.bas ast.bas ir.bas parser2.bas parser5.bas rtl.bas " _
     "emit.bas hash.bas lex.bas parser3.bas parser6.bas strpool.bas " _
     "emitdbg.bas hlp.bas parser1.bas parser4.bas reg.bas symb.bas"
This code should work OK as-is, if you run it from the freebas_v0.0/ folder, with fbc in your PATH. Otherwise it should just be a matter of adjusting the consts at the start.

EDIT: Sorry, if anyone was having problems with this - I remembered I'd deleted dag.bas_ from the folder because it was getting caught in the *.bas in the compile command. I've hardcoded the module list now, so that shouldn't be necessary.
Site Admin
Posts: 3799
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il

Postby v1ctor » Aug 08, 2009 22:12

Cool, counting_pine, thanks for that. I made a change in the compiler to allow enums and periods in -lang qb but it was hackish and could start to break things later, so i gave up trying to get it to build.

Now only if it could self-compile.. heh, only version 0.1 could, never mind.

Anybody noticed that there are no pointers there? Only VBDOS could build it so arrays were used everywhere.
Posts: 82
Joined: Nov 20, 2007 9:08


Postby Leonheart » Aug 10, 2009 12:56

Oh, it's you XD.
I started make VFB.....
But everyone hates me a lot cuz we have same name... :P
V1c shake V1c.....

V1c runz!

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest