Hey there,
merry Christmas to all of you. The last two weeks I tried to write a little
and very simple interpreter in PowerBASIC 3.5. Well so far, everything works
but there is a problem I don't know how to solve.
At first take a look at the source (and yeah I think I know there are better
ways to program but I am a just a beginner
)
' aBASIC - Interpreter Version 0.1
' Copyright (c) 2003 by Christian Damhus
'
filename$ = command$
' ™ffne die angegebene Datei
zeile% = 1
ON ERROR GOTO serror
if filename$ = "help" then goto helpsystem
anz_stringvariable = 0
open filename$ for input as #1
cls
do
input #1, sbcode$
lange% = len(sbcode$)
befehl$ = left$(sbcode$, 3)
if befehl$ = "pri" then goto printbefehl
if befehl$ = "cls" then cls : goto parsenextline
if befehl$ = "bee" then beep : goto parsenextline
if befehl$ = "key" then goto waitkeybefehl
if befehl$ = "del" then goto delaybefehl
if befehl$ = "rem" then goto parsenextline
If befehl$ = "kil" then goto killbefehl
if befehl$ = "bee" then beep : goto parsenextline
if befehl$ = "dir" then goto dirbefehl
if befehl$ = "chd" then goto chdirbefehl
if befehl$ = "inp" then goto inputbefehl
if befehl$ = "she" then goto shellbefehl
' ----------------------------------------------------------------
' Befehle
' ----------------------------------------------------------------
printbefehl:
' Beispiel : print Hallo World
ausgabe$ = mid$(sbcode$, 7)
variable$ = right$(sbcode$,1)
if variable$ = chr$(47) then goto gib_aus
print ausgabe$
goto parsenextline
gib_aus:
nausgabe$ = REMOVE$(ausgabe$, "/")
print nausgabe$ + stringvariable$
goto parsenextline
' ----------------------------------------------------------------
waitkeybefehl:
' key
print "Beliebige Taste drcken zum Fortfahren..."
while taste$="" : taste$ = inkey$ : wend
goto parsenextline
' ----------------------------------------------------------------
delaybefehl:
' delay 100
zeit$ = mid$(sbcode$, 7)
zeit = val(zeit$)
if zeit$ = chr$(47) then goto delayvariable
delay(zeit)
goto parsenextline
delayvariable:
zeita = val(stringvariable$)
delay(zeita)
goto parsenextline
' ----------------------------------------------------------------
killbefehl:
' kill filename
finame$ = mid$(sbcode$, 6)
if finame$ = chr$(47) then kill stringvariable$ : goto parsenextline
kill finame$
goto parsenextline
' ----------------------------------------------------------------
dirbefehl:
' dir extension
ext$ = mid$(sbcode$, 5)
if ext$ = chr$(47) then goto dirvariable
datei$ = dir$(ext$)
print datei$
do until datei$ = ""
datei$ = dir$
print datei$
loop
goto parsenextline
dirvariable:
datei$ = dir$(stringvariable$)
print datei$
do until datei$ = ""
datei$ = dir$
print datei$
loop
goto parsenextline
' ----------------------------------------------------------------
chdirbefehl:
' chdir c:\pb
verz$ = mid$(sbcode$, 7)
if verz$ = chr$(47) then goto chdirvariable
chdir verz$
goto parsenextline
chdirvariable:
chdir stringvariable$
goto parsenextline
' ----------------------------------------------------------------
inputbefehl:
' input was eingeben
inputtext$ = mid$(sbcode$, 7)
print inputtext$
line input stringvariable$
goto parsenextline
' ----------------------------------------------------------------
shellbefehl:
' shell befehl
shellbe$ = mid$(sbcode$, 7)
if shellbe$ = chr$(47) then goto shellvariable
shell shellbe$
goto parsenextline
shellvariable:
shell stringvariable$
goto parsenextline
' ----------------------------------------------------------------
parsenextline:
zeile% = zeile% + 1
LOOP UNTIL sbcode$ = "end"
close #1
color 1,0 : print "ABASIC Interpreter V0.1"
print "Copyright (c) 2003 by Christian Damhus."
end
fehler:
PRINT "Zeile "; zeile%;": Befehl unbekannt!"
end
helpsystem :
cls
color 1,0 : locate 1,29 : print "ABASIC Version 0.1"
locate 2,17 : print"Copyright (c) 2003 by Christian Damhus"
locate 3,17 : color 7,0 : print"--------------------------------------"
locate 5,17 : print "Syntax : sb <filename.bas> OR sb help"
locate 7,10 : print "ABASIC is a simple, primitive BASIC Interpret written"
locate 8,10 : print "PowerBASIC V3.5. It supports only a few real BASIC commands"
locate 9,10 : print "but it is growing."
locate 11,10: print "ABASIC is freeware. You can use it to learn how to"
locate 12,10: print "write your own interpreter but it comes without ANY guarranties"
locate 13,10: print "For further information see : www.christian-damhus.tk/sb
locate 15,10: print "Supported Commands :"
locate 16,10: print "===================="
locate 17,10: print "PRINT, INPUT, SHELL, CLS, KILL, DIR, CHDIR, REM, KEY, BEEP"
end
serror:
cls
color 1,0 : print "ABASIC Version 0.1"
color 1,0 : print "Copyright (c) 2003 by Christian Damhus"
print
print "Usage : sb <filename.bas> OR sb help"
print
color 7,0 : print "Error : Can't find file " + filename$
end
---------------------------------------------------------------
When you use input, the value you unter will be stored in stringvariable$ .
But it can only have one value. If you use the input command again, the
new value will overwrite the first value and so it gets lost.
So every abasic program can just save one variable. What I try to do now
is, that an abasic program can take more than just one variable, e.g.
input name1$
input name2$ and so on
...
print name1$
print name2$ and so on
I don't know how to realize this. I tried to create a type structure (like
type stringvariable_table
identifier AS STRING*4 'only 4 letters for the name of the variable
value AS STRING*255
end type
DIM Tstringvariable_table AS stringvariable_table
Every variable should be stored in this table. But well it did not really
work. As I said before, I am just a beginner and have to learn a lot about
PowerBASIC. So I'd like to ask for your help because you know way more than I do.
Greets
Christian
PS. You don't have to type the source code. The link is www.abasic.privat.t-online.de/abasic01.zip
------------------
merry Christmas to all of you. The last two weeks I tried to write a little
and very simple interpreter in PowerBASIC 3.5. Well so far, everything works
but there is a problem I don't know how to solve.
At first take a look at the source (and yeah I think I know there are better
ways to program but I am a just a beginner

' aBASIC - Interpreter Version 0.1
' Copyright (c) 2003 by Christian Damhus
'
filename$ = command$
' ™ffne die angegebene Datei
zeile% = 1
ON ERROR GOTO serror
if filename$ = "help" then goto helpsystem
anz_stringvariable = 0
open filename$ for input as #1
cls
do
input #1, sbcode$
lange% = len(sbcode$)
befehl$ = left$(sbcode$, 3)
if befehl$ = "pri" then goto printbefehl
if befehl$ = "cls" then cls : goto parsenextline
if befehl$ = "bee" then beep : goto parsenextline
if befehl$ = "key" then goto waitkeybefehl
if befehl$ = "del" then goto delaybefehl
if befehl$ = "rem" then goto parsenextline
If befehl$ = "kil" then goto killbefehl
if befehl$ = "bee" then beep : goto parsenextline
if befehl$ = "dir" then goto dirbefehl
if befehl$ = "chd" then goto chdirbefehl
if befehl$ = "inp" then goto inputbefehl
if befehl$ = "she" then goto shellbefehl
' ----------------------------------------------------------------
' Befehle
' ----------------------------------------------------------------
printbefehl:
' Beispiel : print Hallo World
ausgabe$ = mid$(sbcode$, 7)
variable$ = right$(sbcode$,1)
if variable$ = chr$(47) then goto gib_aus
print ausgabe$
goto parsenextline
gib_aus:
nausgabe$ = REMOVE$(ausgabe$, "/")
print nausgabe$ + stringvariable$
goto parsenextline
' ----------------------------------------------------------------
waitkeybefehl:
' key
print "Beliebige Taste drcken zum Fortfahren..."
while taste$="" : taste$ = inkey$ : wend
goto parsenextline
' ----------------------------------------------------------------
delaybefehl:
' delay 100
zeit$ = mid$(sbcode$, 7)
zeit = val(zeit$)
if zeit$ = chr$(47) then goto delayvariable
delay(zeit)
goto parsenextline
delayvariable:
zeita = val(stringvariable$)
delay(zeita)
goto parsenextline
' ----------------------------------------------------------------
killbefehl:
' kill filename
finame$ = mid$(sbcode$, 6)
if finame$ = chr$(47) then kill stringvariable$ : goto parsenextline
kill finame$
goto parsenextline
' ----------------------------------------------------------------
dirbefehl:
' dir extension
ext$ = mid$(sbcode$, 5)
if ext$ = chr$(47) then goto dirvariable
datei$ = dir$(ext$)
print datei$
do until datei$ = ""
datei$ = dir$
print datei$
loop
goto parsenextline
dirvariable:
datei$ = dir$(stringvariable$)
print datei$
do until datei$ = ""
datei$ = dir$
print datei$
loop
goto parsenextline
' ----------------------------------------------------------------
chdirbefehl:
' chdir c:\pb
verz$ = mid$(sbcode$, 7)
if verz$ = chr$(47) then goto chdirvariable
chdir verz$
goto parsenextline
chdirvariable:
chdir stringvariable$
goto parsenextline
' ----------------------------------------------------------------
inputbefehl:
' input was eingeben
inputtext$ = mid$(sbcode$, 7)
print inputtext$
line input stringvariable$
goto parsenextline
' ----------------------------------------------------------------
shellbefehl:
' shell befehl
shellbe$ = mid$(sbcode$, 7)
if shellbe$ = chr$(47) then goto shellvariable
shell shellbe$
goto parsenextline
shellvariable:
shell stringvariable$
goto parsenextline
' ----------------------------------------------------------------
parsenextline:
zeile% = zeile% + 1
LOOP UNTIL sbcode$ = "end"
close #1
color 1,0 : print "ABASIC Interpreter V0.1"
print "Copyright (c) 2003 by Christian Damhus."
end
fehler:
PRINT "Zeile "; zeile%;": Befehl unbekannt!"
end
helpsystem :
cls
color 1,0 : locate 1,29 : print "ABASIC Version 0.1"
locate 2,17 : print"Copyright (c) 2003 by Christian Damhus"
locate 3,17 : color 7,0 : print"--------------------------------------"
locate 5,17 : print "Syntax : sb <filename.bas> OR sb help"
locate 7,10 : print "ABASIC is a simple, primitive BASIC Interpret written"
locate 8,10 : print "PowerBASIC V3.5. It supports only a few real BASIC commands"
locate 9,10 : print "but it is growing."
locate 11,10: print "ABASIC is freeware. You can use it to learn how to"
locate 12,10: print "write your own interpreter but it comes without ANY guarranties"
locate 13,10: print "For further information see : www.christian-damhus.tk/sb
locate 15,10: print "Supported Commands :"
locate 16,10: print "===================="
locate 17,10: print "PRINT, INPUT, SHELL, CLS, KILL, DIR, CHDIR, REM, KEY, BEEP"
end
serror:
cls
color 1,0 : print "ABASIC Version 0.1"
color 1,0 : print "Copyright (c) 2003 by Christian Damhus"
print "Usage : sb <filename.bas> OR sb help"
color 7,0 : print "Error : Can't find file " + filename$
end
---------------------------------------------------------------
When you use input, the value you unter will be stored in stringvariable$ .
But it can only have one value. If you use the input command again, the
new value will overwrite the first value and so it gets lost.
So every abasic program can just save one variable. What I try to do now
is, that an abasic program can take more than just one variable, e.g.
input name1$
input name2$ and so on
...
print name1$
print name2$ and so on
I don't know how to realize this. I tried to create a type structure (like
type stringvariable_table
identifier AS STRING*4 'only 4 letters for the name of the variable
value AS STRING*255
end type
DIM Tstringvariable_table AS stringvariable_table
Every variable should be stored in this table. But well it did not really
work. As I said before, I am just a beginner and have to learn a lot about
PowerBASIC. So I'd like to ask for your help because you know way more than I do.
Greets
Christian
PS. You don't have to type the source code. The link is www.abasic.privat.t-online.de/abasic01.zip
------------------
Comment