For Diggsey, and others, here is the current source (note that this is not the alpha 2 source, it has some bug fixes):
`initialization
#constant COLON chr$(58)
sync on : sync rate 0 : sync : `sync sleep 1
`retrieve arguments and load source
arguments as string
arguments=cl$()
print "arguments: "+arguments
dim totalSource(0) as integer = 0
dim sourceName(0) as string
dim source(0,0) as string
if arguments="" : loadSource("oodbp.txt")
else
`load project file to array
file as dword
file=newFile()
dim projLine() as string
open to read file,arguments
x=-1 : repeat : inc x
array insert at bottom projLine()
read string file,projLine(x)
until file end(file)
close file file
`load source file
x=-1 : repeat : inc x
until 0<instr(projLine(x),"final source=")
projLine(x)=trim(projLine(x))
loadSource(right$(projLine(x),len(projLine(x))-13))
projLine(x)=projLine(x)+".oodbp"
endif
`--------------------------------------
`############ main parsing ############
`--------------------------------------
name as string
memSize as dword
incSize as dword
loadLocal as string
saveLocal as string
decLine as string
varName as string
varType as string
varDecs as string
arrName as string
arrDecs as string
arrUdec as string
`loop through all source files
for f=0 to totalSource(0)
print "parsing "+left$(sourceName(f),len(sourceName(f))-6)+" ..." : sync
`loop through all lines
for g=0 to getSourceLength()
`parse through classes and perform actions
if commandExist("class",source(f,g))
name=getCommandParam("class",source(f,g))
source(f,g)="`"+source(f,g)
`replace all class definitions with dword definitions
for y=0 to totalSource(0)
for z=0 to getSourceLength()
source(y,z)=rightCheckReplace(" as "+name," as dword",source(y,z))
source(y,z)=leftCheckReplace(name+".",name+"_",source(y,z))
if instr(source(y,z),"rem") then source(y,z)=left$(source(y,z),instr(source(y,z),"rem")-1)
if instr(source(y,z),"`") then source(y,z)=left$(source(y,z),instr(source(y,z),"`")-1)
next z
next y
`inner-class parsing loop
y=g : repeat : inc y
`declarations command - read variable declarations and allow access to methods
if commandExist("declarations",source(f,y))
source(f,y)="`"+source(f,y)
varDecs="" : arrDecs="" : arrUdec="" : memSize=0
loadLocal="memPos as dword "+COLON+" memPos=this"
saveLocal="memPos as dword "+COLON+" memPos=this"
`declaration parsing loop
z=y : repeat : inc z
decLine=lower$(trim(source(f,z)))
`if variable assigned on line
if 0<instr(decLine," as ")
`determine type and name of variable/array
varType=right$(decLine,len(decLine)-instr(decLine," as ")-3)
varName=left$(decLine,instr(decLine," as ")-1)
arrName=left$(right$(varName,len(varName)-4),instr(varName,"(")-5)
if left$(varName,4)<>"dim "
if varDecs="" : varDecs=decLine
else : varDecs=varDecs+" "+COLON+" "+decLine
endif
else
if arrDecs="" : arrDecs=decLine : arrUdec="undim "+arrName+"()"
else : arrDecs=arrDecs+" "+COLON+" "+decLine : arrUdec=arrUdec+"undim "+arrName+"()"
endif
endif
if instr(varType,"=") then throwError("Assignment in class declarations. "+sourceName(f)+" line "+str$(g))
`nonstring variable types
select varType
case "boolean" : incSize=1 : varType="byte" : endcase
case "byte" : incSize=1 : varType="byte" : endcase
case "word" : incSize=2 : varType="word" : endcase
case "dword" : incSize=4 : varType="float" : endcase
case "integer" : incSize=4 : varType="float" : endcase
case "float" : incSize=4 : varType="float" : endcase
case "double integer" : incSize=8 : varType="double" : endcase
case "double float" : incSize=8 : varType="double" : endcase
endselect
`string or nonstring variable/array
if varType="string"
`array or variable
if left$(varName,3)="dim"
memSize=memSize+4
loadLocal=loadLocal+" "+COLON+" address as dword "+COLON+" address=peek dword(memPos) "+COLON+" inc memPos,4 "+COLON+" dim "+arrName+"(peek dword(address)) "+COLON+" for x=0 to array count("+arrName+"()) "+COLON+" "+arrName+"(x)=peek string(peek dword(address+4+x*4)) "+COLON+" delete memory peek dword(address+4+x*4) "+COLON+" next x "+COLON+" delete memory address"
saveLocal=saveLocal+" "+COLON+" address as dword "+COLON+" address=make memory(4+(array count("+arrName+"())+1)*4) "+COLON+" poke dword memPos,address "+COLON+" inc memPos,4 "+COLON+" poke dword address,array count("+arrName+"()) "+COLON+" for x=0 to array count("+arrName+"()) "+COLON+" poke dword address+4+x*4,make memory(len("+arrName+"(x))) "+COLON+" poke string peek dword(address+4+x*4),"+arrName+"(x) "+COLON+" next x "+COLON+" undim "+arrName+"()"
else
memSize=memSize+4
loadLocal=loadLocal+" "+COLON+" "+varName+"=peek string(peek dword(memPos)) "+COLON+" inc memPos,4"
saveLocal=saveLocal+" "+COLON+" delete memory peek dword(memPos) "+COLON+" poke dword memPos,make memory(len("+varName+")) "+COLON+" poke string peek dword(memPos),"+varName+" "+COLON+" inc memPos,4"
endif
else
`array or variable
if left$(varName,3)="dim"
memSize=memSize+4
loadLocal=loadLocal+" "+COLON+" address as dword "+COLON+" address=peek dword(memPos) "+COLON+" inc memPos,4 "+COLON+" dim "+arrName+"(peek dword(address)) "+COLON+" for x=0 to array count("+arrName+"()) "+COLON+" "+arrName+"(x)=peek "+varType+"(address+4+x*"+str$(incSize)+") "+COLON+" next x"
saveLocal=saveLocal+" "+COLON+" delete memory peek dword(memPos) "+COLON+" address as dword "+COLON+" address=make memory(4+(array count("+arrName+"())+1)*"+str$(incSize)+") "+COLON+" poke dword memPos,address "+COLON+" inc memPos,4 "+COLON+" poke dword address,array count("+arrName+"()) "+COLON+" for x=0 to array count("+arrName+"()) "+COLON+" poke "+varType+" address+4+x*"+str$(incSize)+","+arrName+"(x) "+COLON+" next x "+COLON+" undim "+arrName+"()"
else
memSize=memSize+incSize
loadLocal=loadLocal+" "+COLON+" "+varName+"=peek "+varType+"(memPos) "+COLON+" inc memPos,"+str$(incSize)
saveLocal=saveLocal+" "+COLON+" poke "+varType+" memPos,"+varName+" "+COLON+" inc memPos,"+str$(incSize)
endif
endif
endif
`loop until end of declarations reached
until commandExist("enddeclarations",source(f,z))
source(f,z)="`"+source(f,z) : y=z
endif
`for constructor command
if commandExist("constructor",source(f,y))
source(f,y)="function "+name+"_"+getCommandParam("constructor",source(f,y))+" "+COLON+" this as dword "+COLON+" this=make memory("+str$(memSize)+") "+COLON+" "+varDecs+" "+COLON+" "+arrDecs
endif
`for endconstructor command
if commandExist("endconstructor",source(f,y))
source(f,y-1)=lower$(trim(source(f,y-1)))+" "+COLON+" "+saveLocal
source(f,y)="endfunction this"
endif
`for dectructor command
if commandExist("destructor",source(f,y))
source(f,y)="function "+name+"_"+getCommandParam("destructor",source(f,y))+" "+COLON+" "+varDecs+" "+COLON+" "+loadLocal
endif
`for enddestructor command
if commandExist("enddestructor",source(f,y))
source(f,y-1)=lower$(trim(source(f,y-1)))+" "+COLON+" delete memory this "+COLON+" "+arrUdec
source(f,y)="endfunction"
endif
`for method command
if commandExist("method",source(f,y))
source(f,y)="function "+name+"_"+getCommandParam("method",source(f,y))+" "+COLON+" "+varDecs+" "+COLON+" "+loadLocal
endif
`for exitmethod command
`source(f,y)=replace("exitmethod","exitfunction",source(f,y))
`for endmethod command
if commandExist("endmethod",source(f,y))
source(f,y-1)=lower$(trim(source(f,y-1)))+" "+COLON+" "+saveLocal
source(f,y)="endfunction "+getCommandParam("endmethod",source(f,y))
endif
`loop until end of class reached
until commandExist("endclass",source(f,y))
source(f,y)="`"+source(f,y) : g=y
endif
next g
print "done" : sync
next f
`save source and project file
saveSource()
if arguments<>""
`save project file
cd "..compiler"
file as dword
file=newFile()
if file exist(arguments) then delete file arguments
open to write file,arguments
for x=0 to array count(projLine())
write string file,projLine(x)
next x
close file file
print "compiling with DBP compiler..." : sync
execute file "compilerDBP.exe",arguments,"",1
endif
print "all tasks complete" : sync
end
`throws an error and stops compilation
function throwError(error as string)
null=msgBox("Error",error,0)
end
endfunction
`pops up a message box
function msgBox(caption as string, message as string, mtype as integer)
result as dword
if (dll exist(127)=0) then load dll "User32.dll",127
result = call dll(127,"MessageBoxA",0,message,caption,mtype)
endfunction result
`--------------------------------------
`########## command functions #########
`--------------------------------------
`returns whether command is found in phrase or not
function commandExist(com as string,phrase as string)
result as dword = 0
com=lower$(com)
if lower$(left$(trim(phrase),len(com)))=com then result=1
endfunction result
`returns parameters of command
function getCommandParam(com as string,phrase as string)
param as string
phrase=lower$(trim(phrase))
if commandExist(com,phrase)
param=right$(phrase,len(phrase)-(len(com)+1))
else
param=""
endif
endfunction param
`--------------------------------------
`########## string functions ##########
`--------------------------------------
`replaces all instances of one stinr with another, regardless of surroundings
function noCheckReplace(find as string,rep as string,str as string)
start as integer = 1
pos as integer
repeat
pos=instr(lower$(str),lower$(find),start)
if pos>0
str=left$(str,pos-1)+lower$(rep)+right$(str,len(str)-pos-len(find)+1)
start=pos+len(find)-1
endif
until pos=0
endfunction str
`replaces all instances of one string with another, but only in a purely variable context
function bothCheckReplace(find as string,rep as string,str as string)
start as integer = 1
pos as integer
lchar as string
rchar as string
repeat
pos=instr(lower$(str),lower$(find),start)
if pos>0
lchar=mid$(str,pos-1)
rchar=mid$(str,pos+len(find))
if ( (pos+len(find)-1)=len(str) or varEndChar(rchar) ) and ( pos=1 or varEndChar(lchar) )
str=left$(str,pos-1)+lower$(rep)+right$(str,len(str)-pos-len(find)+1)
endif
start=pos+len(find)-1
endif
until pos=0
endfunction str
`replaces all instances of one string with another, checking the right of the string for variable context
function rightCheckReplace(find as string,rep as string,str as string)
start as integer = 1
pos as integer
char as string
repeat
pos=instr(lower$(str),lower$(find),start)
if pos>0
char=mid$(str,pos+len(find))
if (pos+len(find)-1)=len(str) or varEndChar(char)
str=left$(str,pos-1)+lower$(rep)+right$(str,len(str)-pos-len(find)+1)
endif
start=pos+len(find)-1
endif
until pos=0
endfunction str
`replaces all instances of one string with another, checking the left of the string for variable context
function leftCheckReplace(find as string,rep as string,str as string)
start as integer = 1
pos as integer
char as string
repeat
pos=instr(lower$(str),lower$(find),start)
if pos>0
char=mid$(str,pos-1)
if pos=1 or varEndChar(char)
str=left$(str,pos-1)+lower$(rep)+right$(str,len(str)-pos-len(find)+1)
endif
start=pos+len(find)-1
endif
until pos=0
endfunction str
`returns whether the character is a variable ending character or not
function varEndChar(char as string)
result as boolean
result = (char=" " or char="=" or char="(" or char=")" or char=chr$(58))
endfunction result
`returns sub string from a string
function mid(phrase as string,start as integer,stop as integer)
result as string = ""
for x=start to stop
result=result+mid$(phrase,x)
next x
endfunction result
`trims spaces off either side of a string
function trim(phrase as string)
while mid$(phrase,1)=" "
phrase=right$(phrase,len(phrase)-1)
endwhile
while mid$(phrase,len(phrase))=" "
phrase=left$(phrase,len(phrase)-1)
endwhile
endfunction phrase
`--------------------------------------
`########### file functions ###########
`--------------------------------------
`reads a source file to the array
function loadSource(file as string)
if file=" " or file="" then exitfunction
`manage array stuff
length as integer : length=getSourceLength()
totalSource(0)=totalSource(0)+1
dim sourceName(totalSource(0)) as string
dim source(totalSource(0),length) as string
sourceName(totalSource(0))=file+".oodbp"
`load file and read to array
number as dword
number=newFile()
load as string = ""
open to read number,file : x as integer = -1
repeat : inc x
`read line to array
read string number,source(totalSource(0),x)
`keep track of #included files
if left$(lower$(trim(source(totalSource(0),x))),8)="#"+"include"
if load="" : load=getCommandParam("#"+"include",lower$(trim(source(totalSource(0),x))))
else : load=load+" "+getCommandParam("#"+"include",lower$(trim(source(totalSource(0),x))))
endif
source(totalSource(0),x)="#"+"include "+getCommandParam("#"+"include",lower$(trim(source(totalSource(0),x))))+".oodbp"
endif
`redim array
if x=getSourceLength() then dim source(totalSource(0),x+1)
until file end(number)
close file number
`load all #included files
repeat
number=instr(load," ")
if number=0 : loadSource(load)
else : loadSource(left$(load,number-1))
endif
load=right$(load,len(load)-number)
until number=0
endfunction
`saves all source files
function saveSource()
number as dword
for f=0 to totalSource(0)
number=newFile()
if file exist(sourceName(f)) then delete file sourceName(f)
open to write number,sourceName(f)
for x=0 to getSourceLength()
write string number,source(f,x)
next x
close file number
next f
endfunction
`gets the size of the second array dimension
function getSourceLength()
size as integer
size=((array count(source())+1)/(totalSource(0)+1))-1
endfunction size
`returns a new file number
function newFile()
number as dword = 1
repeat
inc number
until (file open(number)=0)
endfunction number
Major changes are coming in the way that class variables are loaded and stored, so this will be out of date soon.
[edit]
I won't be releasing the third alpha like i said i would, as I've decided to recode some of the file parsing and file loading/saving from scratch. I will release the alpha 4 in several days instead, and it will include many bug fixes as well as full comment support and support for codesurge. I will be adding more to the syntax explanation during this period.
Who needs a signature?