This is in a way a continuation from my 'programming language'
I was experimenting again, and I figured that obviously I wasn't going to make anything better than db (suprise suprise), but I have made this.
Basically, I hate the DBC/DBPro syntax (no offence), so I made a thing that makes it look how I like.
For example, this is some code that I would type in a text editor:
syncronise(60);
display(1024:
768:
32);
unsyncronise();
print("Hello, I'm Zotoaster"); wait(500);
input("Enter a message!": a$);
You will notice that the commands can be split up and stuff (though they don't have to be). The semicolons (
are needed for every command, because what it actually does, is get every line in the code (unless it's preceded be //, a remark), and put it into one big line. It then splits it up into each individual command, and the way it does that, is by obviously checking for semicolons. If you dont put one there, then the to commands will be merged into one.
What that above code would output, is something like this:
sync on : sync rate 60
set display mode 1024,768,32
sync off
print "Hello, I'm Zotoaster"
wait 500
input "Enter a message!",a$
Of course, the commands I made there are very similar to DBs, but one I get it to read text files for commands, rather than having to program each one individually into arrays, it will be easy to make substitutes for DBs commands. Right, now I program every single command in, hahaha!
Here's the code so far:
`Setup
sync on
`Commands!
type tCommand
comline as string
params as integer
endtype
dim command(100) as tCommand
`**Commands Here**
`Syncronise
command(1).comline="syncronise()" : command(1).params=1
`unSyncronise
command(2).comline="unsyncronise()" : command(2).params=1
`Display
command(3).comline="display()" : command(3).params=3
`Print
command(4).comline="print()" : command(4).params=1
`Input
command(5).comline="input()" : command(5).params=2
`Wait
command(6).comline="wait()" : command(6).params=1
`**Commands Here**
`Db Lines
dim dblines(100) as string
`Global Variables
global fileLines as integer
global comCount as integer
global fCom as string
global curCompCom as integer
global curdbline as integer
global splitter as string : splitter=":"
`Read File
filelines=getFileLines("code1.zcl")
`Get all commands to 1 line
fCom=getCommands("code1.zcl",filelines)
comCount=getTokens(fCom,";")
`Code Command Data
type tCodeCom
comline as string
params as integer
brackets as string
endtype
dim comLine(comCount) as tCodeCom
`Check commands
checkCommands(fCom,comCount)
`Main Loop
do
`Show darkbasic code
for l=1 to curdbline
text 10,(20*l)+(mousez()/3),dblines(l)
next l
`End Loop
sync
cls
loop
`Functions - String
function getTokens(st$,sp$)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until counter>len(nst$)
tokens=splits-1
endfunction tokens
function getToken(st$,sp$,num)
if left$(st$,1)<>sp$ then nst$=sp$+st$
if right$(st$,1)<>sp$ then nst$=nst$+sp$
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$=sp$ then inc splits
until splits=num or counter>len(st$)
repeat
inc counter
cur$=mid$(nst$,counter)
if cur$<>sp$ then token$=token$+cur$
until cur$=sp$ or counter>len(st$)
endfunction token$
function removeChar(st$,ch$)
for l=1 to len(st$)
cur$=mid$(st$,l)
if cur$<>ch$ then mes$=mes$+cur$
next l
endfunction mes$
`Functions - Compiling
function getCommands(file$,lns)
dim lines(lns) as string
open to read 1,file$
for l=1 to lns
read string 1,lines(l)
for t=1 to len(lines(l))
if left$(lines(l),2)<>"//" then com$=com$+mid$(lines(l),t)
next t
next l
close file 1
undim lines()
endfunction com$
function checkCommands(com$,ccount)
repeat
cur$=getToken(com$,";",curCompCom)
for l=1 to len(cur$)
curlet$=mid$(cur$,l)
if curlet$="(" then stcount=1
if curlet$=")" then stcount=0
if stcount=1 then inc nstcount else nstcount=0
if nstcount>1 then bcount=1 else bcount=0
if bcount=1 then inc count else count=0
if count=0
comLine(curCompCom).comLine=comLine(curCompCom).comLine+curlet$
else
comLine(curCompCom).brackets=comLine(curCompCom).brackets+curlet$
endif
next l
comLine(curCompCom).params=getTokens(comLine(curCompCom).brackets,splitter)
curcomline$=comline(curCompCom).comLine
curbrackets$=comLine(curCompCom).brackets
curparams=comLine(curCompCom).params
processCommands(curcomline$,curbrackets$,curparams)
inc curCompCom
until curCompCom>ccount
endfunction
`Functions - File
function getFileLines(file$)
local lines as integer
open to read 1,file$
repeat
read string 1,null$
inc lines
until file end(1)
close file 1
endfunction lines
`Functions - Commands
function processCommands(line$,brackets$,params)
nbracket$=removeChar(brackets$,chr$(34))
nline$=removeChar(line$," ")
for c=1 to 100
if nline$=command(c).comLine and params=command(c).params
executeCommand(c,nbracket$)
endif
next c
endfunction
`Execute commands
function executeCommand(com,mes$)
if com>0 then inc curdbline
if com=1
dblines(curdbline)="sync on : sync rate "+mes$
endif
if com=2
dblines(curdbline)="sync off"
endif
if com=3
dblines(curdbline)="set display mode "+removeChar(getToken(mes$,splitter,1)," ")+","+removeChar(getToken(mes$,splitter,2)," ")+","+removeChar(getToken(mes$,splitter,3)," ")
endif
if com=4
dblines(curdbline)="print "+chr$(34)+mes$+chr$(34)
endif
if com=5
dblines(curdbline)="input "+chr$(34)+getToken(mes$,splitter,1)+chr$(34)+", "+removeChar(getToken(mes$,splitter,2)," ")
endif
if com=6
dblines(curdbline)="wait "+mes$
endif
endfunction