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).
Bye...
FreeBASIC version 0.0
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.
-Vince
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.
-Vince
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 http://www.geocities.com/angros47, now I made a backup on http://ultrabasic.sourceforge.net/
I discontinued it when FB was born, because FB was much better.
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 http://www.geocities.com/angros47, now I made a backup on http://ultrabasic.sourceforge.net/
I discontinued it when FB was born, because FB was much better.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
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.
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.
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 "file.bi"
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
do
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)
loop
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
do
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
wend
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
wend
mid(f, i2, 1) = "_"
mid(f, i3, 1) = "_"
i = i3+1
if i4 >= 1 then mid(f, i4, 1) = "_": i = i4+1
loop
'' 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
do
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
loop
'' exit function from sub
i = 1
do
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
loop
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()
loop
chdir "inc"
d = dir( "*.bi" )
do while len(d)
print d
fixfile( d )
d = dir()
loop
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"
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.
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.
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.
Meh....
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!
I started make VFB.....
But everyone hates me a lot cuz we have same name... :P
V1c shake V1c.....
V1c runz!