KwikBASIC BASIC Interpreter (Updated Link)
KwikBASIC BASIC Interpreter (Updated Link)
I am currently working on a pet project to build an interpreted version of BASIC. It is coming along nicely, and I am adding features almost daily.
Currently the commands recognized by the interpreter are...
Command Line Switches
KwikBAS.exe sourcefile [-s]ilent [-t]imed [-n]o pause [-d]ebug trace
----------------------------------------------------------------------------
-s | Hides interpreter start/end messsages
-n | No pause when program is finished
-t | Displays execution time
-d | Displays number of line being executed
Supported Commands
Supported Commands v 0.2.10
#! -Shebang directive (Linux Only)
Arrays (x [, y])
Most mathematical operations
Hexadecimal notation (ie: &hAE10)
Const var = [numeric expression]
Dim [Shared] var[(idx1[,idx2])]AS datatype
Dim AS datatype var[(idx1[,idx2])]
var[(idx1[,idx2])] = value
Scope/End Scope
Cls
Colorfore,back
Printexpr
Cons [expr] <- Works like PRINT but always goes to console window
If expr Then / Else | EndIf
Mid / Left / Right
Len(string)
Spc(count)
Space(count)
String(count,char)
Instr(start,string,sub-string)
Chr(ascii_code)
Asc(char_string)
Do {Until|While} / Loop {Until|While} / Exit Do
For/Next | STEP | Exit For
While [expr]/Wend / Exit While
Mid / Left / Right
Len(string)
Spc(count)
Space(count)
String(count,char)
Instr(start,string,sub-string)
Csrlin()
Pos()
Locate row,col,cursorstate
Now()
Date()
Time()
DateSerial(yyyy,mm,dd)
TimeSerial(hh,mm,ss)
Year(date_serial)
Month(date_serial)
Day(date_serial)
Hour(time_serial)
Minute(time_serial)
Second(time_serial)
SetDate date_string
SetTime time_string
Input [prompt][;][,] var
Inkey
Timer
Sleep [ms]
End
Gosub
Return
Cons [expr] <- Works like PRINT but always goes to console window
ScreenRes width,height[,depth][,num_pages][,flags][,refresh]
ScreenSet [work_page][,visible_page]
Pset [dst,](x,y)[,color]
Line [dst,][STEP](x1,y1)-[STEP](x1,y2)[,color][,BF][,style]
Open filename For {INPUT|OUTPUT|APPEND|RANDOM|BINARY} As #file_num [,Len = record_length]
Close #file_num
Print #file_num, var_list [,…]
Write #file_num, var_list [,…]
Input #file_num, var_list [,…]
If you would like to test out the interpreter you can download it here...
Download KwikBASIC
Last edited by vdecampo on Feb 04, 2016 15:25, edited 34 times in total.
-
- Posts: 104
- Joined: Apr 30, 2009 15:20
- Location: Dumbarton, Scotland
I created a heap object which lets me create named entries with either string or double values and a datatype. Internally all numeric values are double and will be coerced to their final datatype when read. I have not implemented scope yet but it shouldn't be too hard. I plan on just creating a local heap object to track local variables.wolfman775 wrote:Verry nice, I was just wondering how you implemented variables.
-Vince
It's a new one based on a lexer project I did a year ago.angros47 wrote:Haven't yet tested it, but it seems interesting.... have you used part of code of my or tblank's one? Or it's a new project? If so, can't wait to see the source code.
Good luck!
I used code from Microsoft Knowledge-Base Article KB86688 for the numeric expression parsing.
-Vince
I gave that some serious thought, and since this was a learning project for me, I decided to interpret as I go. The entire source is parsed into tokens first, then the tokens are run through the virtual machine.TheMG wrote:Is it parsing as it goes along, or does it convert it to some sort of bytecode which it then interprets?
Perhaps next time I will employ a bytecode scheme.
-Vince
?
vdecampo :
why not working together on the same project ?
I think you're just rewriting something I have already done...
I think it would be more constructive to work together. don't you think ?
why not working together on the same project ?
I think you're just rewriting something I have already done...
I think it would be more constructive to work together. don't you think ?
Re: ?
I have never seen your source code. This is a project I have wanted to do for a long time and the recent chatter about interpreters spurred me into action. I am not certain our projects have the same goals.tblanck wrote:vdecampo :
why not working together on the same project ?
I think you're just rewriting something I have already done...
I think it would be more constructive to work together. don't you think ?
My goals are...
1. To create a virtual machine that interprets a subset of the FreeBASIC syntax.
2. That includes GUI elements from my KwikGUI library
3. To further my understanding of Recursive Descent Parsing (not that this is one)
4. To become the object of womens desire.
...Well maybe not #4... :)
Once I release my source code, you are welcome to participate in KwikBASIC's development.
-Vince
Because I have zero C++ experience. The biggest C++ program I have ever written was a HELLO WORLD test. Another reason is I wanted to experiment which scripting. An interpreter could be used to run apps over the web or create batch files.jcfuller wrote:Vince,
Why an interpreter as opposed to a translator (bas -> c++).
This would give you experience to help on a full c++ back end for FreeBASIC.
James
Ultimately this is a learning project for me. If it turns out ok, I may work on something more elaborate.
-Vince
Last edited by vdecampo on Aug 14, 2009 2:25, edited 1 time in total.
Ahhh what to say...
Exellent and work without bugs.I just joking...
You get the point and like what i see...
Aurel
My small modification of your example (just for test..)
Exellent and work without bugs.I just joking...
You get the point and like what i see...
Aurel
My small modification of your example (just for test..)
Code: Select all
-----------------------------------------
' Interpreter Test Source Code
'-----------------------------------------
Dim As String testvar
Dim Value As Integer
testvar = "Hello"
Value = 2+4
Value = Value + 1
Print Value
Print testvar, Value+5
Print Int(value*25/7) & " How are you?"
Print "My string = " + value+10 & " Work Exellent,Vince!"
'Cls
'Print "Hello"
I have updated the download and it now includes the source code.
Here is some documentation.
Command Line Switches
KwikBASIC sourcefile [-s]ilent [-t]imed [-n]o pause
---------------------------------------------------
-s | Hides interpreter start/end messsages
-n | No pause when program is finished
-t | Displays execution time
Supported Commands
Most mathematical operations
Dim var AS datatype 'types not enforced other than string/numeric
Dim AS datatype var
var = value 'String or Numeric
Print expr
Cls
If numeric_expr Then…Else…EndIf
Timer
Chr(ascii_code)
Asc(char_string)
Issues
1. If/Then blocks currently only evaluate numeric expressions.
2. Some errors are not reporting properly.
3. The string expression evaluator is a little buggy.
Enjoy!
-Vince
Here is some documentation.
Command Line Switches
KwikBASIC sourcefile [-s]ilent [-t]imed [-n]o pause
---------------------------------------------------
-s | Hides interpreter start/end messsages
-n | No pause when program is finished
-t | Displays execution time
Supported Commands
Most mathematical operations
Dim var AS datatype 'types not enforced other than string/numeric
Dim AS datatype var
var = value 'String or Numeric
Print expr
Cls
If numeric_expr Then…Else…EndIf
Timer
Chr(ascii_code)
Asc(char_string)
Issues
1. If/Then blocks currently only evaluate numeric expressions.
2. Some errors are not reporting properly.
3. The string expression evaluator is a little buggy.
Enjoy!
-Vince